-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack_test.go
More file actions
47 lines (35 loc) · 952 Bytes
/
stack_test.go
File metadata and controls
47 lines (35 loc) · 952 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package faq
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestPushAndPeek(t *testing.T) {
stack := Stack{}
q1 := Question{
Text: "Who are you",
Answer: "I'm a bot",
}
q2 := Question{
Text: "Where to apply new identity",
Answer: "Please come to gov office",
}
stack.Push(q1)
stack.Push(q2)
assert.Equal(t, stack.Peek(0).(Question), q2)
assert.Equal(t, stack.Peek(1).(Question), q1)
}
func TestPopAndLength(t *testing.T) {
stack := Stack{}
if stack.Length() != 0 {
t.Errorf("length is not right %v", stack.Length())
}
q1 := Question{Text: "Who are you", Answer: "I'm a bot"}
q2 := Question{Text: "Where to apply?", Answer: "Please come to gov office"}
stack.Push(q1)
stack.Push(q2)
assert.Equal(t, stack.Pop().(Question), q2)
assert.Equal(t, stack.Length(), 1)
stack.Push(Question{Text: "a", Answer: "b"})
stack.Push(Question{Text: "c", Answer: "d"})
assert.Equal(t, stack.Length(), 3)
}