stack_test.gno
0.50 Kb ยท 28 lines
1package stack
2
3import "testing"
4
5func TestStack(t *testing.T) {
6 s := New() // Empty stack
7
8 if s.Len() != 0 {
9 t.Errorf("s.Len(): expected 0; got %d", s.Len())
10 }
11
12 s.Push(1)
13
14 if s.Len() != 1 {
15 t.Errorf("s.Len(): expected 1; got %d", s.Len())
16 }
17
18 if top := s.Top(); top.(int) != 1 {
19 t.Errorf("s.Top(): expected 1; got %v", top.(int))
20 }
21
22 if elem := s.Pop(); elem.(int) != 1 {
23 t.Errorf("s.Pop(): expected 1; got %v", elem.(int))
24 }
25 if s.Len() != 0 {
26 t.Errorf("s.Len(): expected 0; got %d", s.Len())
27 }
28}