-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathquotes_test.go
More file actions
86 lines (68 loc) · 1.65 KB
/
quotes_test.go
File metadata and controls
86 lines (68 loc) · 1.65 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
package stats
import (
"math/rand"
"testing"
"time"
)
func TestQuotes(t *testing.T) {
rand.Seed(81) // returns (0, 9)
var q quotes
m := &Message{ID: 4}
if q.Random != nil {
t.Error("Random message should not be set.")
}
if q.Last != nil {
t.Error("Last message should not be set.")
}
q.addMessage(m)
if q.Random != m {
t.Error("Random message should be set")
}
if q.Last != m {
t.Error("Last message should be set")
}
m2 := &Message{ID: 5}
q.addMessage(m2)
if q.Random != m {
t.Error("Random message should not change")
}
if q.Last != m2 {
t.Error("Last message be updated")
}
}
func TestQuotesUpdates(t *testing.T) {
rand.Seed(7075) // returns (0,0,0,0) - dont ask
s := NewStats()
n := s.addNetwork(network)
c := s.addChannel(n, channel)
u := s.addUser(n, nick)
cu := u.addChannelUser(channel)
if n.Quotes.Last != nil && n.Quotes.Random != nil {
t.Error("Last message and random message should not be set.")
}
if c.Quotes.Last != nil && c.Quotes.Random != nil {
t.Error("Last message and random message should not be set.")
}
if u.Quotes.Last != nil && u.Quotes.Random != nil {
t.Error("Last message and random message should not be set.")
}
m := s.addMessage(Msg, n, c, u, cu, time.Now(), "nihao")
if n.Quotes.Random != m {
t.Error("Random message should be set")
}
if c.Quotes.Random != m {
t.Error("Random message should be set")
}
if u.Quotes.Random != m {
t.Error("Random message should be set")
}
if n.Quotes.Last != m {
t.Error("Last message should be set")
}
if c.Quotes.Last != m {
t.Error("Last message should be set")
}
if u.Quotes.Last != m {
t.Error("Last message should be set")
}
}