Commit 9195c22e authored by Robert Griesemer's avatar Robert Griesemer

use new test framework in array test

R=r
DELTA=30  (2 added, 5 deleted, 23 changed)
OCL=19627
CL=19632
parent bef9b171
...@@ -5,21 +5,21 @@ ...@@ -5,21 +5,21 @@
package array package array
import "array" import "array"
import "testing"
import "sort"
export func TestInit() bool { export func TestInit(t *testing.T) {
var a array.Array; var a array.Array;
if a.Init(0).Len() != 0 { return false } if a.Init(0).Len() != 0 { t.FailNow() }
if a.Init(1).Len() != 1 { return false } if a.Init(1).Len() != 1 { t.FailNow() }
if a.Init(10).Len() != 10 { return false } if a.Init(10).Len() != 10 { t.FailNow() }
return true;
} }
export func TestNew() bool { export func TestNew(t *testing.T) {
if array.New(0).Len() != 0 { return false } if array.New(0).Len() != 0 { t.FailNow() }
if array.New(1).Len() != 1 { return false } if array.New(1).Len() != 1 { t.FailNow() }
if array.New(10).Len() != 10 { return false } if array.New(10).Len() != 10 { t.FailNow() }
return true;
} }
...@@ -28,7 +28,7 @@ export func Val(i int) int { ...@@ -28,7 +28,7 @@ export func Val(i int) int {
} }
export func TestAccess() bool { export func TestAccess(t *testing.T) {
const n = 100; const n = 100;
var a array.Array; var a array.Array;
a.Init(n); a.Init(n);
...@@ -36,35 +36,34 @@ export func TestAccess() bool { ...@@ -36,35 +36,34 @@ export func TestAccess() bool {
a.Set(i, Val(i)); a.Set(i, Val(i));
} }
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
if a.At(i).(int) != Val(i) { return false } if a.At(i).(int) != Val(i) { t.FailNow() }
} }
return true;
} }
export func TestInsertRemoveClear() bool { export func TestInsertRemoveClear(t *testing.T) {
const n = 100; const n = 100;
a := array.New(0); a := array.New(0);
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
if a.Len() != i { return false } if a.Len() != i { t.FailNow() }
a.Insert(0, Val(i)); a.Insert(0, Val(i));
if a.Last().(int) != Val(0) { return false } if a.Last().(int) != Val(0) { t.FailNow() }
} }
for i := n-1; i >= 0; i-- { for i := n-1; i >= 0; i-- {
if a.Last().(int) != Val(0) { return false } if a.Last().(int) != Val(0) { t.FailNow() }
if a.Remove(0).(int) != Val(i) { return false } if a.Remove(0).(int) != Val(i) { t.FailNow() }
if a.Len() != i { return false } if a.Len() != i { t.FailNow() }
} }
if a.Len() != 0 { return false } if a.Len() != 0 { t.FailNow() }
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
a.Push(Val(i)); a.Push(Val(i));
if a.Len() != i+1 { return false } if a.Len() != i+1 { t.FailNow() }
if a.Last().(int) != Val(i) { return false } if a.Last().(int) != Val(i) { t.FailNow() }
} }
a.Init(0); a.Init(0);
if a.Len() != 0 { return false } if a.Len() != 0 { t.FailNow() }
const m = 5; const m = 5;
for j := 0; j < m; j++ { for j := 0; j < m; j++ {
...@@ -72,11 +71,9 @@ export func TestInsertRemoveClear() bool { ...@@ -72,11 +71,9 @@ export func TestInsertRemoveClear() bool {
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
x := Val(i); x := Val(i);
a.Push(x); a.Push(x);
if a.Pop().(int) != x { return false } if a.Pop().(int) != x { t.FailNow() }
if a.Len() != j+1 { return false } if a.Len() != j+1 { t.FailNow() }
} }
} }
if a.Len() != m { return false } if a.Len() != m { t.FailNow() }
return true;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment