MCPcopy Index your code
hub / github.com/arnauddri/algorithms / TestNew

Function TestNew

data-structures/stack/stack_test.go:8–43  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

6)
7
8func TestNew(t *testing.T) {
9 s := New()
10
11 if !s.isEmpty() ||
12 s.len != 0 ||
13 s.Len() != 0 {
14 t.Error()
15 }
16
17 s.Push(1)
18 s.Push(2)
19 s.Push(3)
20
21 if s.stack[0] != 3 ||
22 s.stack[1] != 2 ||
23 s.stack[2] != 1 {
24 fmt.Println(s.stack)
25 t.Error()
26 }
27
28 if s.Len() != 3 {
29 t.Error()
30 }
31
32 a := s.Pop()
33
34 if a != 3 || s.Len() != 2 {
35 t.Error()
36 }
37
38 b := s.Peek()
39
40 if b != 2 {
41 t.Error()
42 }
43}

Callers

nothing calls this directly

Calls 6

PopMethod · 0.80
NewFunction · 0.70
isEmptyMethod · 0.45
LenMethod · 0.45
PushMethod · 0.45
PeekMethod · 0.45

Tested by

no test coverage detected