-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhourly_chart_test.go
More file actions
69 lines (52 loc) · 1.23 KB
/
hourly_chart_test.go
File metadata and controls
69 lines (52 loc) · 1.23 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
package stats
import (
"testing"
"time"
)
func TestHourlyChart(t *testing.T) {
t.Parallel()
var chart HourlyChart
for i := 23; i >= 0; i-- {
for j := 0; j < i; j++ {
date := time.Date(2014, time.April, 29, i, 30, 0, 1, time.UTC)
m := &Message{
Date: date,
}
chart.addMessage(m)
}
}
for i := 0; i < 24; i++ {
if chart[i] != i {
t.Errorf("Hour[%d] has %d messages, expected: %d", i, chart[i], i)
}
}
}
func TestHourlyChartUpdates(t *testing.T) {
t.Parallel()
s := NewStats()
n := s.addNetwork(network)
c := s.addChannel(n, channel)
u := s.addUser(n, nick)
cu := u.addChannelUser(channel)
date := time.Now()
hour := date.Hour()
if n.HourlyChart[hour] != 0 {
t.Error("Network's chart should not have data in it")
}
if c.HourlyChart[hour] != 0 {
t.Error("Channel's chart should not have data in it")
}
if u.HourlyChart[hour] != 0 {
t.Error("User's chart should not have data in it")
}
s.addMessage(Msg, n, c, u, cu, date, "nihao")
if n.HourlyChart[hour] != 1 {
t.Error("Networks's chart should have data in it")
}
if c.HourlyChart[hour] != 1 {
t.Error("Channel's chart should have data in it")
}
if u.HourlyChart[hour] != 1 {
t.Error("User's chart should have data in it")
}
}