diff options
author | Alexander Kiryukhin <a.kiryukhin@mail.ru> | 2022-04-07 21:36:40 +0300 |
---|---|---|
committer | Alexander Kiryukhin <a.kiryukhin@mail.ru> | 2022-04-07 21:36:40 +0300 |
commit | 9cd6b0fca87679e570fbdd4942e3068feb3439fa (patch) | |
tree | 557bf877d71854480f4171e9dd324cebb5606056 /stack_test.go |
initial
Diffstat (limited to 'stack_test.go')
-rw-r--r-- | stack_test.go | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/stack_test.go b/stack_test.go new file mode 100644 index 0000000..b2c1760 --- /dev/null +++ b/stack_test.go @@ -0,0 +1,36 @@ +package collection + +import ( + "reflect" + "testing" +) + +func TestPushPop(t *testing.T) { + collection := []int{} + collection = Push(collection, 1) + collection = Push(collection, 2) + collection = Push(collection, 3) + want := []int{1, 2, 3} + if !reflect.DeepEqual(collection, want) { + t.Errorf("Want %+v, but got %+v", want, collection) + } + collection, e := Pop(collection) + if e != 3 { + t.Errorf("Want 3, but got %d", e) + } + collection, e = Pop(collection) + if e != 2 { + t.Errorf("Want 2, but got %d", e) + } + collection, e = Pop(collection) + if e != 1 { + t.Errorf("Want 1, but got %d", e) + } + collection, e = Pop(collection) + if e != 0 { + t.Errorf("Want 0, but got %d", e) + } + if len(collection) != 0 { + t.Errorf("Collection must be empty, but got %+v (len = %d)", collection, len(collection)) + } +} |