Debian Codegraph @

stack/stack_test.go

raw symbols SCIP
1 package stack
2
3 import (
4 "testing"
5 )
6
7 func Test(t *testing.T) {
8 s := New()
9
10 if s.Len() != 0 {
11 t.Errorf("Length of an empty stack should be 0")
12 }
13
14 s.Push(1)
15
16 if s.Len() != 1 {
17 t.Errorf("Length should be 0")
18 }
19
20 if s.Peek().(int) != 1 {
21 t.Errorf("Top item on the stack should be 1")
22 }
23
24 if s.Pop().(int) != 1 {
25 t.Errorf("Top item should have been 1")
26 }
27
28 if s.Len() != 0 {
29 t.Errorf("Stack should be empty")
30 }
31
32 s.Push(1)
33 s.Push(2)
34
35 if s.Len() != 2 {
36 t.Errorf("Length should be 2")
37 }
38
39 if s.Peek().(int) != 2 {
40 t.Errorf("Top of the stack should be 2")
41 }
42 }