summaryrefslogtreecommitdiff
path: root/stack_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'stack_test.go')
-rw-r--r--stack_test.go53
1 files changed, 53 insertions, 0 deletions
diff --git a/stack_test.go b/stack_test.go
new file mode 100644
index 0000000..773f6cf
--- /dev/null
+++ b/stack_test.go
@@ -0,0 +1,53 @@
+package stack
+
+import "testing"
+
+func TestInt(t *testing.T) {
+ s := NewStack()
+ s.Push(1)
+ i, _ := s.Pop()
+ if i != 1 {
+ t.Error("Expected 1, got ", i)
+ }
+}
+
+func TestComplex(t *testing.T) {
+ s := NewStack()
+ s.Push(1+1i)
+ i, _ := s.Pop()
+ if i != 1+1i {
+ t.Error("Expected 1+1i, got ", i)
+ }
+}
+
+func TestMeny(t *testing.T) {
+ s := NewStack()
+ s.Push(1)
+ s.Push(2)
+ i, _ := s.Pop()
+ if i != 2 {
+ t.Error("Expected 2, got ", i)
+ }
+ i, _ = s.Pop()
+ if i != 1 {
+ t.Error("Expected 1, got ", i)
+ }
+}
+
+func BenchmarkPushPopSingle(b *testing.B) {
+ s := NewStack()
+ for i := 0; i < b.N; i++ {
+ s.Push(1)
+ s.Pop()
+ }
+}
+
+func BenchmarkPushPopAlot(b *testing.B) {
+ s := NewStack()
+ for i := 0; i < b.N; i++ {
+ s.Push(i)
+ }
+ for i := 0; i < b.N; i++ {
+ s.Pop()
+ }
+}