-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack_test.go
More file actions
94 lines (84 loc) · 1.74 KB
/
stack_test.go
File metadata and controls
94 lines (84 loc) · 1.74 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestPush(t *testing.T) {
stack := NewStack()
stack.Push(10)
stack.Push(10)
stack.Push(10)
assert.Equal(t, stack.Len(), 3, nil)
}
func TestPop(t *testing.T) {
stack := NewStack()
stack.Push(1)
stack.Push(2)
stack.Push(3)
results, err := stack.PopN(3)
assert.Nil(t, err)
assert.Equal(t, []float64{3, 2, 1}, results)
stack.Push(1)
stack.Push(2)
stack.Push(3)
results, err = stack.PopN(2)
assert.Nil(t, err)
assert.Equal(t, []float64{3, 2}, results)
}
func TestPopR(t *testing.T) {
stack := NewStack()
stack.Push(1)
stack.Push(2)
stack.Push(3)
results, err := stack.PopR(3)
assert.Nil(t, err)
assert.Equal(t, []float64{1, 2, 3}, results)
stack.Push(1)
stack.Push(2)
stack.Push(3)
results, err = stack.PopR(2)
assert.Nil(t, err)
assert.Equal(t, []float64{2, 3}, results)
}
func TestSwap(t *testing.T) {
stack := NewStack()
stack.Push(1)
stack.Push(2)
stack.Push(3)
_ = stack.Swap()
results, err := stack.PopN(2)
assert.Nil(t, err)
assert.Equal(t, []float64{2, 3}, results)
}
func TestClear(t *testing.T) {
stack := NewStack()
stack.Push(1)
stack.Push(2)
stack.Push(3)
assert.Equal(t, stack.Len(), 3, nil)
stack.Clear()
assert.Equal(t, stack.Len(), 0, nil)
}
func TestStringF(t *testing.T) {
stack := NewStack()
stack.Push(1)
stack.Push(2)
stack.Push(3)
assert.Equal(t, "[ 1.000000 2.000000 3.000000 ]", stack.StringF())
}
func TestSort(t *testing.T) {
stack := NewStack()
stack.Push(3)
stack.Push(1)
stack.Push(2)
stack.Sort()
assert.Equal(t, "[ 1 2 3 ]", stack.String())
}
func TestCopy(t *testing.T) {
stack := NewStack()
stack.Push(3)
stack.Push(1)
stack.Push(2)
arr := stack.Copy()
assert.Equal(t, []float64{3, 1, 2}, arr)
}