aboutsummaryrefslogtreecommitdiff
path: root/test/map.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2009-01-06 15:19:02 -0800
committerRuss Cox <rsc@golang.org>2009-01-06 15:19:02 -0800
commit5564504507c9b307840a5d13d9700d46e2a8524d (patch)
treef3f98baba1fdd5e0138a4875884aa85111308b3f /test/map.go
parent9662e7b2db0fa8c2bb4d8cf28940116763eedbc9 (diff)
downloadgo-5564504507c9b307840a5d13d9700d46e2a8524d.tar.gz
go-5564504507c9b307840a5d13d9700d46e2a8524d.zip
new new & make
R=r OCL=22166 CL=22166
Diffstat (limited to 'test/map.go')
-rw-r--r--test/map.go41
1 files changed, 23 insertions, 18 deletions
diff --git a/test/map.go b/test/map.go
index bc31bf8300..caa764d2d8 100644
--- a/test/map.go
+++ b/test/map.go
@@ -35,27 +35,27 @@ func main() {
}
}
- mib := new(map[int] bool);
- mii := new(map[int] int);
- mfi := new(map[float] int);
- mif := new(map[int] float);
- msi := new(map[string] int);
- mis := new(map[int] string);
- mss := new(map[string] string);
- mspa := new(map[string] []string);
+ mib := make(map[int] bool);
+ mii := make(map[int] int);
+ mfi := make(map[float] int);
+ mif := make(map[int] float);
+ msi := make(map[string] int);
+ mis := make(map[int] string);
+ mss := make(map[string] string);
+ mspa := make(map[string] []string);
// BUG need an interface map both ways too
type T struct {
i int64; // can't use string here; struct values are only compared at the top level
f float;
};
- mipT := new(map[int] *T);
- mpTi := new(map[*T] int);
- mit := new(map[int] T);
- mti := new(map[T] int);
+ mipT := make(map[int] *T);
+ mpTi := make(map[*T] int);
+ mit := make(map[int] T);
+ mti := make(map[T] int);
type M map[int] int;
- mipM := new(map[int] M);
+ mipM := make(map[int] M);
const count = 1000;
var apT [2*count]*T;
@@ -65,14 +65,13 @@ func main() {
s10 := strconv.itoa(i*10);
f := float(i);
t := T{int64(i),f};
- apT[i] = new(*T);
+ apT[i] = new(T);
apT[i].i = int64(i);
apT[i].f = f;
- apT[2*i] = new(*T); // need twice as many entries as we use, for the nonexistence check
+ apT[2*i] = new(T); // need twice as many entries as we use, for the nonexistence check
apT[2*i].i = int64(i);
apT[2*i].f = f;
- // BUG m := M{i, i+1};
- m := new(M); m[i] = i+1;
+ m := M{i: i+1};
mib[i] = (i != 0);
mii[i] = 10*i;
mfi[float(i)] = 10*i;
@@ -81,7 +80,7 @@ func main() {
msi[s] = i;
mss[s] = s10;
mss[s] = s10;
- as := new([]string, arraylen);
+ as := make([]string, arraylen);
as[0] = s10;
as[1] = s10;
mspa[s] = as;
@@ -123,6 +122,9 @@ func main() {
if len(mpTi) != count {
fmt.printf("len(mpTi) = %d\n", len(mpTi));
}
+ if len(mti) != count {
+ fmt.printf("len(mti) = %d\n", len(mti));
+ }
if len(mipM) != count {
fmt.printf("len(mipM) = %d\n", len(mipM));
}
@@ -172,6 +174,9 @@ func main() {
if(mpTi[apT[i]] != i) {
fmt.printf("mpTi[apT[%d]] = %d\n", i, mpTi[apT[i]]);
}
+ if(mti[t] != i) {
+ fmt.printf("mti[%s] = %s\n", s, mti[t]);
+ }
if (mipM[i][i] != i + 1) {
fmt.printf("mipM[%d][%d] = %d\n", i, i, mipM[i][i]);
}