This repository has been archived by the owner on May 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathseries_test.go
88 lines (75 loc) · 1.9 KB
/
series_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
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
package seriessort_test
import (
"testing"
"github.com/Roman2K/scat/seriessort"
assert "github.com/stretchr/testify/require"
)
func TestSeries(t *testing.T) {
s := seriessort.Series{}
sorted := s.Sorted()
assert.Equal(t, 0, len(sorted))
assert.Equal(t, 0, s.Len())
s.Add(1, "b")
sorted = s.Sorted()
assert.Equal(t, 0, len(sorted))
assert.Equal(t, 2, s.Len())
s.Add(2, "c")
sorted = s.Sorted()
assert.Equal(t, 0, len(sorted))
assert.Equal(t, 3, s.Len())
s.Add(0, "a")
sorted = s.Sorted()
assert.Equal(t, 3, len(sorted))
assert.Equal(t, 3, s.Len())
assert.Equal(t, "a", sorted[0].(string))
assert.Equal(t, "b", sorted[1].(string))
assert.Equal(t, "c", sorted[2].(string))
s.Drop(0)
sorted = s.Sorted()
assert.Equal(t, 3, len(sorted))
assert.Equal(t, 3, s.Len())
assert.Equal(t, "a", sorted[0].(string))
s.Drop(1)
sorted = s.Sorted()
assert.Equal(t, 2, len(sorted))
assert.Equal(t, 2, s.Len())
assert.Equal(t, "b", sorted[0].(string))
s.Drop(1)
sorted = s.Sorted()
assert.Equal(t, 1, len(sorted))
assert.Equal(t, 1, s.Len())
assert.Equal(t, "c", sorted[0].(string))
s.Add(3, "d")
sorted = s.Sorted()
assert.Equal(t, 2, len(sorted))
assert.Equal(t, 2, s.Len())
assert.Equal(t, "c", sorted[0].(string))
assert.Equal(t, "d", sorted[1].(string))
s.Add(2, "x")
sorted = s.Sorted()
assert.Equal(t, 2, len(sorted))
assert.Equal(t, 2, s.Len())
assert.Equal(t, "x", sorted[0].(string))
assert.Equal(t, "d", sorted[1].(string))
assert.Panics(t, func() {
s.Add(0, "x")
})
assert.Panics(t, func() {
s.Add(1, "x")
})
sorted = s.Sorted()
assert.Equal(t, 2, len(sorted))
assert.Equal(t, 2, s.Len())
s.Drop(-1)
sorted = s.Sorted()
assert.Equal(t, 2, len(sorted))
assert.Equal(t, 2, s.Len())
s.Drop(99)
sorted = s.Sorted()
assert.Equal(t, 0, len(sorted))
assert.Equal(t, 0, s.Len())
s.Drop(99)
sorted = s.Sorted()
assert.Equal(t, 0, len(sorted))
assert.Equal(t, 0, s.Len())
}