forked from shazow/ssh-chat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhistory_test.go
53 lines (42 loc) · 908 Bytes
/
history_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
package main
import (
"reflect"
"testing"
)
func TestHistory(t *testing.T) {
var r, expected []string
var size int
h := NewHistory(5)
r = h.Get(10)
expected = []string{}
if !reflect.DeepEqual(r, expected) {
t.Errorf("Got: %v, Expected: %v", r, expected)
}
h.Add("1")
if size = h.Len(); size != 1 {
t.Errorf("Wrong size: %v", size)
}
r = h.Get(1)
expected = []string{"1"}
if !reflect.DeepEqual(r, expected) {
t.Errorf("Got: %v, Expected: %v", r, expected)
}
h.Add("2")
h.Add("3")
h.Add("4")
h.Add("5")
h.Add("6")
if size = h.Len(); size != 5 {
t.Errorf("Wrong size: %v", size)
}
r = h.Get(2)
expected = []string{"5", "6"}
if !reflect.DeepEqual(r, expected) {
t.Errorf("Got: %v, Expected: %v", r, expected)
}
r = h.Get(10)
expected = []string{"2", "3", "4", "5", "6"}
if !reflect.DeepEqual(r, expected) {
t.Errorf("Got: %v, Expected: %v", r, expected)
}
}