forked from Team254/cheesy-arena
-
Notifications
You must be signed in to change notification settings - Fork 0
/
match_test.go
139 lines (122 loc) · 4.66 KB
/
match_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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// Copyright 2014 Team 254. All Rights Reserved.
// Author: [email protected] (Patrick Fairbank)
package main
import (
"github.com/stretchr/testify/assert"
"testing"
"time"
)
func TestGetNonexistentMatch(t *testing.T) {
clearDb()
defer clearDb()
db, err := OpenDatabase(testDbPath)
assert.Nil(t, err)
defer db.Close()
match, err := db.GetMatchById(1114)
assert.Nil(t, err)
assert.Nil(t, match)
}
func TestMatchCrud(t *testing.T) {
clearDb()
defer clearDb()
db, err := OpenDatabase(testDbPath)
assert.Nil(t, err)
defer db.Close()
match := Match{0, "qualification", "254", time.Now().UTC(), 0, 0, 0, 1, false, 2, false, 3, false, 4, false,
5, false, 6, false, "", time.Now().UTC(), "", "LB", "M", "R", "RW", "RT", "LB", "CDF", "RT", "RW", "R"}
db.CreateMatch(&match)
match2, err := db.GetMatchById(1)
assert.Nil(t, err)
assert.Equal(t, match, *match2)
match3, err := db.GetMatchByName("qualification", "254")
assert.Nil(t, err)
assert.Equal(t, match, *match3)
match.Status = "started"
db.SaveMatch(&match)
match2, err = db.GetMatchById(1)
assert.Nil(t, err)
assert.Equal(t, match.Status, match2.Status)
db.DeleteMatch(&match)
match2, err = db.GetMatchById(1)
assert.Nil(t, err)
assert.Nil(t, match2)
}
func TestTruncateMatches(t *testing.T) {
clearDb()
defer clearDb()
db, err := OpenDatabase(testDbPath)
assert.Nil(t, err)
defer db.Close()
match := Match{0, "qualification", "254", time.Now().UTC(), 0, 0, 0, 1, false, 2, false, 3, false, 4, false,
5, false, 6, false, "", time.Now().UTC(), "", "LB", "M", "R", "RW", "RT", "LB", "CDF", "RT", "RW", "R"}
db.CreateMatch(&match)
db.TruncateMatches()
match2, err := db.GetMatchById(1)
assert.Nil(t, err)
assert.Nil(t, match2)
}
func TestGetMatchesByElimRoundGroup(t *testing.T) {
clearDb()
defer clearDb()
db, err := OpenDatabase(testDbPath)
assert.Nil(t, err)
defer db.Close()
match := Match{Type: "elimination", DisplayName: "SF1-1", ElimRound: 2, ElimGroup: 1, ElimInstance: 1}
db.CreateMatch(&match)
match2 := Match{Type: "elimination", DisplayName: "SF2-2", ElimRound: 2, ElimGroup: 2, ElimInstance: 2}
db.CreateMatch(&match2)
match3 := Match{Type: "elimination", DisplayName: "SF2-1", ElimRound: 2, ElimGroup: 2, ElimInstance: 1}
db.CreateMatch(&match3)
match4 := Match{Type: "elimination", DisplayName: "QF2-1", ElimRound: 4, ElimGroup: 2, ElimInstance: 1}
db.CreateMatch(&match4)
match5 := Match{Type: "practice", DisplayName: "1"}
db.CreateMatch(&match5)
matches, err := db.GetMatchesByElimRoundGroup(4, 1)
assert.Nil(t, err)
assert.Empty(t, matches)
matches, err = db.GetMatchesByElimRoundGroup(2, 2)
assert.Nil(t, err)
if assert.Equal(t, 2, len(matches)) {
assert.Equal(t, "SF2-1", matches[0].DisplayName)
assert.Equal(t, "SF2-2", matches[1].DisplayName)
}
}
func TestGetMatchesByType(t *testing.T) {
clearDb()
defer clearDb()
db, err := OpenDatabase(testDbPath)
assert.Nil(t, err)
defer db.Close()
match := Match{0, "qualification", "1", time.Now().UTC(), 0, 0, 0, 1, false, 2, false, 3, false, 4, false,
5, false, 6, false, "", time.Now().UTC(), "", "LB", "M", "R", "RW", "RT", "LB", "CDF", "RT", "RW", "R"}
db.CreateMatch(&match)
match2 := Match{0, "practice", "1", time.Now().UTC(), 0, 0, 0, 1, false, 2, false, 3, false, 4, false, 5,
false, 6, false, "", time.Now().UTC(), "", "LB", "M", "R", "RW", "RT", "LB", "CDF", "RT", "RW", "R"}
db.CreateMatch(&match2)
match3 := Match{0, "practice", "2", time.Now().UTC(), 0, 0, 0, 1, false, 2, false, 3, false, 4, false, 5,
false, 6, false, "", time.Now().UTC(), "", "LB", "M", "R", "RW", "RT", "LB", "CDF", "RT", "RW", "R"}
db.CreateMatch(&match3)
matches, err := db.GetMatchesByType("test")
assert.Nil(t, err)
assert.Empty(t, matches)
matches, err = db.GetMatchesByType("practice")
assert.Nil(t, err)
assert.Equal(t, 2, len(matches))
matches, err = db.GetMatchesByType("qualification")
assert.Nil(t, err)
assert.Equal(t, 1, len(matches))
}
func TestTbaCode(t *testing.T) {
match := Match{Type: "practice", DisplayName: "3"}
assert.Equal(t, "", match.TbaCode())
match = Match{Type: "qualification", DisplayName: "26"}
assert.Equal(t, "qm26", match.TbaCode())
match = Match{Type: "elimination", DisplayName: "EF2-1", ElimRound: 8, ElimGroup: 2, ElimInstance: 1}
assert.Equal(t, "ef2m1", match.TbaCode())
match = Match{Type: "elimination", DisplayName: "QF3-2", ElimRound: 4, ElimGroup: 3, ElimInstance: 2}
assert.Equal(t, "qf3m2", match.TbaCode())
match = Match{Type: "elimination", DisplayName: "SF1-3", ElimRound: 2, ElimGroup: 1, ElimInstance: 3}
assert.Equal(t, "sf1m3", match.TbaCode())
match = Match{Type: "elimination", DisplayName: "F2", ElimRound: 1, ElimGroup: 1, ElimInstance: 2}
assert.Equal(t, "f1m2", match.TbaCode())
}