Skip to content

Commit 84ec133

Browse files
committed
[test] Add publisher tests
1 parent c7b56eb commit 84ec133

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package controller
2+
3+
import (
4+
"reflect"
5+
"testing"
6+
"time"
7+
8+
"github.com/RoboCup-SSL/ssl-go-tools/sslproto"
9+
)
10+
11+
func Test_updateMessage(t *testing.T) {
12+
proto := sslproto.SSL_Referee{}
13+
initRefereeMessage(&proto)
14+
state := NewState()
15+
team := TeamYellow
16+
command := EventCommand{ForTeam: &team, Type: CommandDirect}
17+
18+
updateMessage(&proto, state, &command)
19+
20+
if *proto.PacketTimestamp <= 0 {
21+
t.Errorf("Wrong packet timestamp: %v", *proto.PacketTimestamp)
22+
}
23+
if *proto.Stage != sslproto.SSL_Referee_NORMAL_FIRST_HALF_PRE {
24+
t.Errorf("Wrong Stage: %v", *proto.Stage)
25+
}
26+
if *proto.StageTimeLeft != 0 {
27+
t.Errorf("Wrong StageTimeLeft: %v", *proto.StageTimeLeft)
28+
}
29+
if *proto.Command != sslproto.SSL_Referee_DIRECT_FREE_YELLOW {
30+
t.Errorf("Wrong command: %v", *proto.Command)
31+
}
32+
if *proto.CommandCounter != 1 {
33+
t.Errorf("Wrong CommandCounter: %v", *proto.CommandCounter)
34+
}
35+
if *proto.CommandTimestamp <= 0 {
36+
t.Errorf("Wrong CommandTimestamp: %v", *proto.CommandTimestamp)
37+
}
38+
if *proto.BlueTeamOnPositiveHalf != false {
39+
t.Errorf("Wrong half: %v", *proto.BlueTeamOnPositiveHalf)
40+
}
41+
if proto.Yellow == nil {
42+
t.Errorf("Missing Yellow")
43+
}
44+
if proto.Blue == nil {
45+
t.Errorf("Missing Blue")
46+
}
47+
}
48+
49+
func Test_mapTimes(t *testing.T) {
50+
type args struct {
51+
durations []time.Duration
52+
}
53+
tests := []struct {
54+
name string
55+
args args
56+
want []uint32
57+
}{
58+
{"zero", args{durations: []time.Duration{0}}, []uint32{0}},
59+
{"second", args{durations: []time.Duration{1 * time.Second}}, []uint32{1000000}},
60+
{"multiple", args{durations: []time.Duration{1 * time.Millisecond, 5 * time.Millisecond}}, []uint32{1000, 5000}},
61+
}
62+
for _, tt := range tests {
63+
t.Run(tt.name, func(t *testing.T) {
64+
if got := mapTimes(tt.args.durations); !reflect.DeepEqual(got, tt.want) {
65+
t.Errorf("mapTimes() = %v, want %v", got, tt.want)
66+
}
67+
})
68+
}
69+
}

0 commit comments

Comments
 (0)