MCPcopy
hub / github.com/arnauddri/algorithms / TestNew

Function TestNew

data-structures/queue/queue_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 q := New()
10
11 if !q.isEmpty() ||
12 q.len != 0 ||
13 q.Len() != 0 {
14 t.Error()
15 }
16
17 q.Push(1)
18 q.Push(2)
19 q.Push(3)
20
21 if q.queue[0] != 1 ||
22 q.queue[1] != 2 ||
23 q.queue[2] != 3 {
24 fmt.Println(q.queue)
25 t.Error()
26 }
27
28 if q.Len() != 3 {
29 t.Error()
30 }
31
32 a := q.Shift()
33
34 if a != 1 || q.Len() != 2 {
35 t.Error()
36 }
37
38 b := q.Peek()
39
40 if b != 2 {
41 t.Error()
42 }
43}

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected