package stack import "testing" func TestInt(t *testing.T) { s := New() s.Push(1) i := s.Pop() if i != 1 { t.Error("Expected 1, got ", i) } } func TestComplex(t *testing.T) { s := New() s.Push(1 + 1i) i := s.Pop() if i != 1+1i { t.Error("Expected 1+1i, got ", i) } } func TestMany(t *testing.T) { s := New() 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 TestSwap(t *testing.T) { s := New() s.Push(1) s.Push(2) s.Swap() if s.Depth() != 2 { t.Error("Expected depth of 2") } a := s.Pop() b := s.Pop() if s.Depth() != 0 { t.Error("Expected depth of 0") } if a != 1 || b != 2 { t.Error("Expected swapped values") } } func TestInsert(t *testing.T) { s := New() s.Push(1) s.Insert(2) if s.Depth() != 2 { t.Error("Expected depth of 2") } a := s.Pop() b := s.Pop() if s.Depth() != 0 { t.Error("Expected depth of 0") } if a != 1 || b != 2 { t.Error("Expected swapped values") } } func TestPeek(t *testing.T) { s := New() v := s.Peek() if v != nil { t.Error("Expected nil") } s.Push(1) v = s.Peek() if v != 1 { t.Error("Expected 1") } if s.Depth() != 1 { t.Error("Expected depth of 1") } } func BenchmarkPushPopSingle(b *testing.B) { s := New() for i := 0; i < b.N; i++ { s.Push(1) s.Pop() } } func BenchmarkPushPopAlot(b *testing.B) { s := New() for i := 0; i < b.N; i++ { s.Push(i) } for i := 0; i < b.N; i++ { s.Pop() } } func BenchmarkInsetPopSingle(b *testing.B) { s := New() for i := 0; i < b.N; i++ { s.Insert(1) s.Pop() } } func BenchmarkInsetPopAlot(b *testing.B) { s := New() for i := 0; i < b.N; i++ { s.Insert(i) } for i := 0; i < b.N; i++ { s.Pop() } }