aboutsummaryrefslogtreecommitdiff
path: root/stack_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'stack_test.go')
-rw-r--r--stack_test.go36
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))
+ }
+}