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 TestSwap(t *testing.T) { s := NewStack() 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 := NewStack() 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 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() } } func BenchmarkInsetPopSingle(b *testing.B) { s := NewStack() for i := 0; i < b.N; i++ { s.Insert(1) s.Pop() } } func BenchmarkInsetPopAlot(b *testing.B) { s := NewStack() for i := 0; i < b.N; i++ { s.Insert(i) } for i := 0; i < b.N; i++ { s.Pop() } }