summaryrefslogtreecommitdiff
path: root/test/bigalg.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2008-12-19 17:11:54 -0800
committerRuss Cox <rsc@golang.org>2008-12-19 17:11:54 -0800
commit4e8d7172d13d1014eb5c40a8a141aea270269269 (patch)
treecb81af416ec881adddae83a041978d025019be1f /test/bigalg.go
parent30a25b187b5e403c232a385a77420824c40a35e2 (diff)
downloadgo-4e8d7172d13d1014eb5c40a8a141aea270269269.tar.gz
[] and struct in interfaces.
other [] cleanup. convert() is gone. R=r DELTA=352 (144 added, 68 deleted, 140 changed) OCL=21660 CL=21662
Diffstat (limited to 'test/bigalg.go')
-rw-r--r--test/bigalg.go54
1 files changed, 43 insertions, 11 deletions
diff --git a/test/bigalg.go b/test/bigalg.go
index 0f92f66ab..748ef858f 100644
--- a/test/bigalg.go
+++ b/test/bigalg.go
@@ -32,15 +32,16 @@ func arraycmptest() {
if a == nil || nil == a {
println("fail3:", a, "== nil");
}
- if a == NIL || NIL == a {
- println("fail4:", a, "==", NIL);
- }
- if a != a {
- println("fail5:", a, "!=", a);
+}
+
+func SameArray(a, b []int) bool {
+ if len(a) != len(b) || cap(a) != cap(b) {
+ return false;
}
- if a1 != a {
- println("fail6:", a1, "!=", a);
+ if len(a) > 0 && &a[0] != &b[0] {
+ return false;
}
+ return true;
}
var t = T{1.5, 123, "hello", 255}
@@ -56,7 +57,7 @@ func maptest() {
ma[1] = a;
a1 := ma[1];
- if a1 != a {
+ if !SameArray(a, a1) {
println("fail: map val array", a, a1);
}
}
@@ -93,18 +94,49 @@ func chantest() {
t1 := <-ct;
if t1.a != t.a || t1.b != t.b || t1.c != t.c || t1.d != t.d {
- println("fail: chan struct", t1.a, t1.b, t1.c, t1.d);
+ println("fail: map val struct", t1.a, t1.b, t1.c, t1.d);
}
a1 := <-ca;
- if a1 != a {
- println("fail: chan array", a, a1);
+ if !SameArray(a, a1) {
+ println("fail: map val array", a, a1);
}
}
+type E struct { }
+var e E
+
+func interfacetest() {
+ var i interface{};
+
+ i = a;
+ a1 := i.([]int);
+ if !SameArray(a, a1) {
+ println("interface <-> []int", a, a1);
+ }
+ pa := new(*[]int);
+ *pa = a;
+ i = pa;
+ a1 = *i.(*[]int);
+ if !SameArray(a, a1) {
+ println("interface <-> *[]int", a, a1);
+ }
+
+ i = t;
+ t1 := i.(T);
+ if t1.a != t.a || t1.b != t.b || t1.c != t.c || t1.d != t.d {
+ println("interface <-> struct", t1.a, t1.b, t1.c, t1.d);
+ }
+
+ i = e;
+ e1 := i.(E);
+ // nothing to check; just verify it doesn't crash
+}
+
func main() {
arraycmptest();
maptest();
maptest2();
chantest();
+ interfacetest();
}