-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathproblem043_test.go
57 lines (45 loc) · 1.35 KB
/
problem043_test.go
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
48
49
50
51
52
53
54
55
56
57
package problem043
import (
"fmt"
"testing"
)
func TestStack(t *testing.T) {
stack := NewStack(32).Push(4).Push(10).Push(12).Push(4).Push(12)
correctAnswer := 12
if maxValue, err := stack.Max(); err != nil || maxValue != correctAnswer {
t.Log(fmt.Sprintf("Max %d != %d", maxValue, correctAnswer), err)
t.Fail()
}
correctAnswer = 12
if poppedValue, err := stack.Pop(); err != nil || poppedValue != correctAnswer {
t.Log(fmt.Sprintf("Pop %d != %d", poppedValue, correctAnswer), err)
t.Fail()
}
correctAnswer = 12
if maxValue, err := stack.Max(); err != nil || maxValue != correctAnswer {
t.Log(fmt.Sprintf("Max %d != %d", maxValue, correctAnswer), err)
t.Fail()
}
correctAnswer = 4
if poppedValue, err := stack.Pop(); err != nil || poppedValue != correctAnswer {
t.Log(fmt.Sprintf("Pop %d != %d", poppedValue, correctAnswer), err)
t.Fail()
}
_, _ = stack.Pop()
correctAnswer = 10
if maxValue, err := stack.Max(); err != nil || maxValue != correctAnswer {
t.Log(fmt.Sprintf("Max %d != %d", maxValue, correctAnswer), err)
t.Fail()
}
_, _ = stack.Pop()
correctAnswer = 4
if maxValue, err := stack.Max(); err != nil || maxValue != correctAnswer {
t.Log(fmt.Sprintf("Max %d != %d", maxValue, correctAnswer), err)
t.Fail()
}
_, _ = stack.Pop()
if _, err := stack.Pop(); err == nil {
t.Log("Pop without error")
t.Fail()
}
}