mirror of
https://github.com/Team254/cheesy-arena-lite.git
synced 2026-03-09 13:46:44 -04:00
Fixed broken tests.
This commit is contained in:
@@ -107,7 +107,7 @@ func TestDecodeStatusPacket(t *testing.T) {
|
||||
assert.Equal(t, false, dsStatus.Auto)
|
||||
assert.Equal(t, false, dsStatus.Enabled)
|
||||
assert.Equal(t, false, dsStatus.EmergencyStop)
|
||||
assert.Equal(t, 0, dsStatus.BatteryVoltage)
|
||||
assert.Equal(t, 0.0, dsStatus.BatteryVoltage)
|
||||
assert.Equal(t, "02121300", dsStatus.DsVersion)
|
||||
assert.Equal(t, 16171, dsStatus.PacketCount)
|
||||
assert.Equal(t, 25288, dsStatus.MissedPacketCount)
|
||||
@@ -263,5 +263,5 @@ func TestListenForDsPackets(t *testing.T) {
|
||||
dsConn.Update()
|
||||
assert.Equal(t, false, dsConn.DriverStationStatus.DsLinked)
|
||||
assert.Equal(t, false, dsConn.DriverStationStatus.RobotLinked)
|
||||
assert.Equal(t, 0, dsConn.DriverStationStatus.BatteryVoltage)
|
||||
assert.Equal(t, 0.0, dsConn.DriverStationStatus.BatteryVoltage)
|
||||
}
|
||||
|
||||
@@ -450,6 +450,15 @@ func CommitMatchScore(match *Match, matchResult *MatchResult) error {
|
||||
|
||||
// Update and save the match record to the database.
|
||||
match.Status = "complete"
|
||||
redScore := matchResult.RedScoreSummary()
|
||||
blueScore := matchResult.BlueScoreSummary()
|
||||
if redScore.Score > blueScore.Score {
|
||||
match.Winner = "R"
|
||||
} else if redScore.Score < blueScore.Score {
|
||||
match.Winner = "B"
|
||||
} else {
|
||||
match.Winner = "T"
|
||||
}
|
||||
err := db.SaveMatch(match)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -543,10 +552,18 @@ func buildMatchPlayList(matchType string) (MatchPlayList, error) {
|
||||
matchPlayList[i].DisplayName = prefix + match.DisplayName
|
||||
matchPlayList[i].Time = match.Time.Local().Format("3:04 PM")
|
||||
matchPlayList[i].Status = match.Status
|
||||
switch match.Winner {
|
||||
case "R":
|
||||
matchPlayList[i].ColorClass = "danger"
|
||||
case "B":
|
||||
matchPlayList[i].ColorClass = "info"
|
||||
case "T":
|
||||
matchPlayList[i].ColorClass = "warning"
|
||||
default:
|
||||
matchPlayList[i].ColorClass = ""
|
||||
}
|
||||
if mainArena.currentMatch != nil && matchPlayList[i].Id == mainArena.currentMatch.Id {
|
||||
matchPlayList[i].ColorClass = "success"
|
||||
} else if match.Status == "complete" {
|
||||
matchPlayList[i].ColorClass = "warning"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -145,6 +145,7 @@ func TestCommitMatch(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
defer db.Close()
|
||||
eventSettings, _ = db.GetEventSettings()
|
||||
mainArena.Setup()
|
||||
|
||||
// Committing test match should do nothing.
|
||||
match := &Match{Id: 0, Type: "test", Red1: 101, Red2: 102, Red3: 103, Blue1: 104, Blue2: 105, Blue3: 106}
|
||||
@@ -201,7 +202,7 @@ func TestCommitEliminationTie(t *testing.T) {
|
||||
|
||||
match := &Match{Id: 0, Type: "qualification", Red1: 1, Red2: 2, Red3: 3, Blue1: 4, Blue2: 5, Blue3: 6}
|
||||
db.CreateMatch(match)
|
||||
matchResult := &MatchResult{MatchId: match.Id, RedScore: Score{AutoRobotSet: true}}
|
||||
matchResult := &MatchResult{MatchId: match.Id, RedScore: Score{AutoToteSet: true, Fouls: []Foul{Foul{}}}}
|
||||
err = CommitMatchScore(match, matchResult)
|
||||
assert.Nil(t, err)
|
||||
match, _ = db.GetMatchById(1)
|
||||
@@ -210,7 +211,7 @@ func TestCommitEliminationTie(t *testing.T) {
|
||||
db.SaveMatch(match)
|
||||
CommitMatchScore(match, matchResult)
|
||||
match, _ = db.GetMatchById(1)
|
||||
assert.Equal(t, "B", match.Winner)
|
||||
assert.Equal(t, "T", match.Winner) // No elimination tiebreakers in 2015.
|
||||
}
|
||||
|
||||
func TestCommitCards(t *testing.T) {
|
||||
@@ -257,7 +258,7 @@ func TestCommitCards(t *testing.T) {
|
||||
err = CommitMatchScore(match, matchResult)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 0, matchResult.RedScoreSummary().Score)
|
||||
assert.Equal(t, 593, matchResult.BlueScoreSummary().Score)
|
||||
assert.Equal(t, 104, matchResult.BlueScoreSummary().Score)
|
||||
}
|
||||
|
||||
func TestMatchPlayWebsocketCommands(t *testing.T) {
|
||||
@@ -282,6 +283,7 @@ func TestMatchPlayWebsocketCommands(t *testing.T) {
|
||||
readWebsocketType(t, ws, "status")
|
||||
readWebsocketType(t, ws, "matchTiming")
|
||||
readWebsocketType(t, ws, "matchTime")
|
||||
readWebsocketType(t, ws, "realtimeScore")
|
||||
readWebsocketType(t, ws, "setAudienceDisplay")
|
||||
readWebsocketType(t, ws, "scoringStatus")
|
||||
readWebsocketType(t, ws, "setAllianceStationDisplay")
|
||||
@@ -334,17 +336,15 @@ func TestMatchPlayWebsocketCommands(t *testing.T) {
|
||||
readWebsocketType(t, ws, "status")
|
||||
readWebsocketType(t, ws, "setAudienceDisplay")
|
||||
assert.Equal(t, POST_MATCH, mainArena.MatchState)
|
||||
mainArena.redRealtimeScore.CurrentScore.AutoRobotSet = true
|
||||
mainArena.redRealtimeScore.CurrentScore.AutoRobotSet = true
|
||||
mainArena.blueRealtimeScore.CurrentScore.AutoToteSet = true
|
||||
ws.Write("commitResults", nil)
|
||||
readWebsocketType(t, ws, "reload")
|
||||
readWebsocketType(t, ws, "setAllianceStationDisplay")
|
||||
readWebsocketMultiple(t, ws, 3) // reload, realtimeScore, setAllianceStationDisplay
|
||||
assert.Equal(t, true, mainArena.savedMatchResult.RedScore.AutoRobotSet)
|
||||
assert.Equal(t, true, mainArena.savedMatchResult.BlueScore.AutoToteSet)
|
||||
assert.Equal(t, PRE_MATCH, mainArena.MatchState)
|
||||
ws.Write("discardResults", nil)
|
||||
readWebsocketType(t, ws, "reload")
|
||||
readWebsocketType(t, ws, "setAllianceStationDisplay")
|
||||
readWebsocketMultiple(t, ws, 3) // reload, realtimeScore, setAllianceStationDisplay
|
||||
assert.Equal(t, PRE_MATCH, mainArena.MatchState)
|
||||
|
||||
// Test changing the displays.
|
||||
@@ -378,6 +378,7 @@ func TestMatchPlayWebsocketNotifications(t *testing.T) {
|
||||
readWebsocketType(t, ws, "status")
|
||||
readWebsocketType(t, ws, "matchTiming")
|
||||
readWebsocketType(t, ws, "matchTime")
|
||||
readWebsocketType(t, ws, "realtimeScore")
|
||||
readWebsocketType(t, ws, "setAudienceDisplay")
|
||||
readWebsocketType(t, ws, "scoringStatus")
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ type Score struct {
|
||||
AutoContainerSet bool
|
||||
AutoToteSet bool
|
||||
AutoStackedToteSet bool
|
||||
Stacks []Stack
|
||||
Stacks []Stack
|
||||
CoopertitionSet bool
|
||||
CoopertitionStack bool
|
||||
Fouls []Foul
|
||||
@@ -42,9 +42,9 @@ type Score struct {
|
||||
}
|
||||
|
||||
type Stack struct {
|
||||
Totes int
|
||||
Totes int
|
||||
Container bool
|
||||
Litter bool
|
||||
Litter bool
|
||||
}
|
||||
|
||||
type Foul struct {
|
||||
@@ -184,10 +184,10 @@ func scoreSummary(score *Score) *ScoreSummary {
|
||||
for _, stack := range score.Stacks {
|
||||
summary.TotePoints += 2 * stack.Totes
|
||||
if stack.Container {
|
||||
summary.ContainerPoints += 4 * stack.Totes
|
||||
if stack.Litter && stack.Totes > 0 {
|
||||
summary.LitterPoints += 6
|
||||
}
|
||||
summary.ContainerPoints += 4 * stack.Totes
|
||||
if stack.Litter && stack.Totes > 0 {
|
||||
summary.LitterPoints += 6
|
||||
}
|
||||
}
|
||||
}
|
||||
if score.CoopertitionStack {
|
||||
|
||||
@@ -80,35 +80,25 @@ func TestGetMatchResultForMatch(t *testing.T) {
|
||||
assert.Equal(t, matchResult2, *matchResult4)
|
||||
}
|
||||
|
||||
func TestScoring(t *testing.T) {
|
||||
matchResult := MatchResult{}
|
||||
score := &matchResult.RedScore
|
||||
assert.Equal(t, 0, matchResult.RedScoreSummary().Score)
|
||||
|
||||
// TODO(pat): Test all scoring combinations.
|
||||
*score = Score{}
|
||||
assert.Equal(t, 0, matchResult.RedScoreSummary().Score)
|
||||
}
|
||||
|
||||
func TestScoreSummary(t *testing.T) {
|
||||
matchResult := buildTestMatchResult(1, 1)
|
||||
redSummary := matchResult.RedScoreSummary()
|
||||
assert.Equal(t, 40, redSummary.CoopertitionPoints)
|
||||
assert.Equal(t, 28, redSummary.AutoPoints)
|
||||
assert.Equal(t, 36, redSummary.ContainerPoints)
|
||||
assert.Equal(t, 2, redSummary.TotePoints)
|
||||
assert.Equal(t, 64, redSummary.LitterPoints)
|
||||
assert.Equal(t, 24, redSummary.ContainerPoints)
|
||||
assert.Equal(t, 12, redSummary.TotePoints)
|
||||
assert.Equal(t, 6, redSummary.LitterPoints)
|
||||
assert.Equal(t, 18, redSummary.FoulPoints)
|
||||
assert.Equal(t, 152, redSummary.Score)
|
||||
assert.Equal(t, 92, redSummary.Score)
|
||||
|
||||
blueSummary := matchResult.BlueScoreSummary()
|
||||
assert.Equal(t, 20, blueSummary.CoopertitionPoints)
|
||||
assert.Equal(t, 40, blueSummary.CoopertitionPoints)
|
||||
assert.Equal(t, 10, blueSummary.AutoPoints)
|
||||
assert.Equal(t, 36, blueSummary.ContainerPoints)
|
||||
assert.Equal(t, 12, blueSummary.TotePoints)
|
||||
assert.Equal(t, 24, blueSummary.LitterPoints)
|
||||
assert.Equal(t, 24, blueSummary.ContainerPoints)
|
||||
assert.Equal(t, 24, blueSummary.TotePoints)
|
||||
assert.Equal(t, 6, blueSummary.LitterPoints)
|
||||
assert.Equal(t, 0, blueSummary.FoulPoints)
|
||||
assert.Equal(t, 102, blueSummary.Score)
|
||||
assert.Equal(t, 104, blueSummary.Score)
|
||||
}
|
||||
|
||||
func TestCorrectEliminationScore(t *testing.T) {
|
||||
@@ -116,7 +106,7 @@ func TestCorrectEliminationScore(t *testing.T) {
|
||||
matchResult := MatchResult{}
|
||||
matchResult.CorrectEliminationScore()
|
||||
|
||||
// TODO(patrick): Put back elim tiebreaker tests.
|
||||
// TODO(patrick): Put back elim tiebreaker tests if the game calls for it.
|
||||
}
|
||||
|
||||
func buildTestMatchResult(matchId int, playNumber int) MatchResult {
|
||||
@@ -124,8 +114,8 @@ func buildTestMatchResult(matchId int, playNumber int) MatchResult {
|
||||
stacks1 := []Stack{Stack{6, true, true}, Stack{0, false, false}, Stack{0, true, false}}
|
||||
stacks2 := []Stack{Stack{5, true, false}, Stack{6, false, false}, Stack{1, true, true}}
|
||||
matchResult := MatchResult{MatchId: matchId, PlayNumber: playNumber}
|
||||
matchResult.RedScore = Score{false, false, true, true, stacks1, false, true, fouls, false}
|
||||
matchResult.BlueScore = Score{true, true, false, false, stacks2, true, false, []Foul{}, false}
|
||||
matchResult.RedScore = Score{false, true, false, true, stacks1, false, true, fouls, false}
|
||||
matchResult.BlueScore = Score{true, false, true, false, stacks2, false, true, []Foul{}, false}
|
||||
matchResult.RedCards = map[string]string{"1868": "yellow"}
|
||||
matchResult.BlueCards = map[string]string{}
|
||||
return matchResult
|
||||
|
||||
@@ -49,8 +49,8 @@ func TestMatchReviewEditExistingResult(t *testing.T) {
|
||||
eventSettings, _ = db.GetEventSettings()
|
||||
mainArena.Setup()
|
||||
|
||||
match := Match{Type: "elimination", DisplayName: "QF4-3", Status: "complete", Winner: "R", Red1: 101,
|
||||
Red2: 102, Red3: 103, Blue1: 104, Blue2: 105, Blue3: 106}
|
||||
match := Match{Type: "elimination", DisplayName: "QF4-3", Status: "complete", Winner: "R", Red1: 1001,
|
||||
Red2: 1002, Red3: 1003, Blue1: 1004, Blue2: 1005, Blue3: 1006}
|
||||
db.CreateMatch(&match)
|
||||
matchResult := buildTestMatchResult(match.Id, 1)
|
||||
db.CreateMatchResult(&matchResult)
|
||||
@@ -59,8 +59,8 @@ func TestMatchReviewEditExistingResult(t *testing.T) {
|
||||
recorder := getHttpResponse("/match_review")
|
||||
assert.Equal(t, 200, recorder.Code)
|
||||
assert.Contains(t, recorder.Body.String(), "QF4-3")
|
||||
assert.Contains(t, recorder.Body.String(), "312") // The red score
|
||||
assert.Contains(t, recorder.Body.String(), "593") // The blue score
|
||||
assert.Contains(t, recorder.Body.String(), "92") // The red score
|
||||
assert.Contains(t, recorder.Body.String(), "104") // The blue score
|
||||
|
||||
// Check response for non-existent match.
|
||||
recorder = getHttpResponse(fmt.Sprintf("/match_review/%d/edit", 12345))
|
||||
@@ -72,9 +72,8 @@ func TestMatchReviewEditExistingResult(t *testing.T) {
|
||||
assert.Contains(t, recorder.Body.String(), "QF4-3")
|
||||
|
||||
// Update the score to something else.
|
||||
postBody := "redScoreJson={\"AutoMobilityBonuses\":3}&blueScoreJson={\"Cycles\":[{\"ScoredHigh\":true}]}&" +
|
||||
"redFoulsJson=[{\"TeamId\":103,\"IsTechnical\":false}]&blueFoulsJson=[{\"TeamId\":104,\"IsTechnical\":" +
|
||||
"true}]&redCardsJson={\"105\":\"yellow\"}&blueCardsJson={}"
|
||||
postBody := "redScoreJson={\"AutoRobotSet\":true}&blueScoreJson={\"Stacks\":[{\"Totes\":6,\"Container\":true,\"Litter\":true}]," +
|
||||
"\"Fouls\":[{\"TeamId\":973,\"Rule\":\"G22\"}]}&redCardsJson={\"105\":\"yellow\"}&blueCardsJson={}"
|
||||
recorder = postHttpResponse(fmt.Sprintf("/match_review/%d/edit", match.Id), postBody)
|
||||
assert.Equal(t, 302, recorder.Code)
|
||||
|
||||
@@ -82,8 +81,8 @@ func TestMatchReviewEditExistingResult(t *testing.T) {
|
||||
recorder = getHttpResponse("/match_review")
|
||||
assert.Equal(t, 200, recorder.Code)
|
||||
assert.Contains(t, recorder.Body.String(), "QF4-3")
|
||||
assert.Contains(t, recorder.Body.String(), "65") // The red score
|
||||
assert.Contains(t, recorder.Body.String(), "30") // The blue score
|
||||
assert.Contains(t, recorder.Body.String(), "4") // The red score
|
||||
assert.Contains(t, recorder.Body.String(), "36") // The blue score
|
||||
}
|
||||
|
||||
func TestMatchReviewCreateNewResult(t *testing.T) {
|
||||
@@ -95,24 +94,24 @@ func TestMatchReviewCreateNewResult(t *testing.T) {
|
||||
defer db.Close()
|
||||
eventSettings, _ = db.GetEventSettings()
|
||||
|
||||
match := Match{Type: "elimination", DisplayName: "QF4-3", Status: "complete", Winner: "R", Red1: 101,
|
||||
Red2: 102, Red3: 103, Blue1: 104, Blue2: 105, Blue3: 106}
|
||||
match := Match{Type: "elimination", DisplayName: "QF4-3", Status: "complete", Winner: "R", Red1: 1001,
|
||||
Red2: 1002, Red3: 1003, Blue1: 1004, Blue2: 1005, Blue3: 1006}
|
||||
db.CreateMatch(&match)
|
||||
createTestAlliances(db, 2)
|
||||
|
||||
recorder := getHttpResponse("/match_review")
|
||||
assert.Equal(t, 200, recorder.Code)
|
||||
assert.Contains(t, recorder.Body.String(), "QF4-3")
|
||||
assert.NotContains(t, recorder.Body.String(), "312") // The red score
|
||||
assert.NotContains(t, recorder.Body.String(), "593") // The blue score
|
||||
assert.NotContains(t, recorder.Body.String(), "92") // The red score
|
||||
assert.NotContains(t, recorder.Body.String(), "104") // The blue score
|
||||
|
||||
recorder = getHttpResponse(fmt.Sprintf("/match_review/%d/edit", match.Id))
|
||||
assert.Equal(t, 200, recorder.Code)
|
||||
assert.Contains(t, recorder.Body.String(), "QF4-3")
|
||||
|
||||
// Update the score to something else.
|
||||
postBody := "redScoreJson={\"AutoHighHot\":4}&blueScoreJson={\"Cycles\":[{\"Assists\":3," +
|
||||
"\"ScoredLow\":true}]}&redFoulsJson=[]&blueFoulsJson=[]&redCardsJson={}&blueCardsJson={}"
|
||||
postBody := "redScoreJson={\"AutoToteSet\":true}&blueScoreJson={\"Stacks\":[{\"Totes\":6,\"Container\":true,\"Litter\":true}]," +
|
||||
"\"Fouls\":[{\"TeamId\":973,\"Rule\":\"G22\"}]}&redCardsJson={\"105\":\"yellow\"}&blueCardsJson={}"
|
||||
recorder = postHttpResponse(fmt.Sprintf("/match_review/%d/edit", match.Id), postBody)
|
||||
assert.Equal(t, 302, recorder.Code)
|
||||
|
||||
@@ -120,6 +119,6 @@ func TestMatchReviewCreateNewResult(t *testing.T) {
|
||||
recorder = getHttpResponse("/match_review")
|
||||
assert.Equal(t, 200, recorder.Code)
|
||||
assert.Contains(t, recorder.Body.String(), "QF4-3")
|
||||
assert.Contains(t, recorder.Body.String(), "80") // The red score
|
||||
assert.Contains(t, recorder.Body.String(), "31") // The blue score
|
||||
assert.Contains(t, recorder.Body.String(), "6") // The red score
|
||||
assert.Contains(t, recorder.Body.String(), "36") // The blue score
|
||||
}
|
||||
|
||||
@@ -98,12 +98,12 @@ func TestCalculateRankings(t *testing.T) {
|
||||
rankings, err := db.GetAllRankings()
|
||||
assert.Nil(t, err)
|
||||
if assert.Equal(t, 6, len(rankings)) {
|
||||
assert.Equal(t, Ranking{4, 1, 127, 60, 38, 72, 14, 88, 0.897169713149801, 0, 2}, rankings[0])
|
||||
assert.Equal(t, Ranking{1, 2, 101.33, 80, 56, 72, 4, 128, 0.2730468047134829, 0, 3}, rankings[1])
|
||||
assert.Equal(t, Ranking{5, 3, 84.66, 60, 38, 72, 14, 88, 0.2885856518054551, 0, 3}, rankings[2])
|
||||
assert.Equal(t, Ranking{3, 4, 76, 40, 28, 36, 2, 64, 0.9026048462705047, 0, 2}, rankings[3])
|
||||
assert.Equal(t, Ranking{6, 5, 51, 20, 10, 36, 12, 24, 0.16735444255905835, 0, 2}, rankings[4])
|
||||
assert.Equal(t, Ranking{2, 6, 50.66, 40, 28, 36, 2, 64, 0.8497802817628735, 1, 3}, rankings[5])
|
||||
assert.Equal(t, Ranking{4, 1, 98, 80, 38, 48, 36, 12, 0.897169713149801, 0, 2}, rankings[0])
|
||||
assert.Equal(t, Ranking{5, 2, 65.33, 80, 38, 48, 36, 12, 0.2885856518054551, 0, 3}, rankings[1])
|
||||
assert.Equal(t, Ranking{1, 3, 61.33, 80, 56, 48, 24, 12, 0.2730468047134829, 0, 3}, rankings[2])
|
||||
assert.Equal(t, Ranking{6, 4, 52, 40, 10, 24, 24, 6, 0.16735444255905835, 0, 2}, rankings[3])
|
||||
assert.Equal(t, Ranking{3, 5, 46, 40, 28, 24, 12, 6, 0.9026048462705047, 0, 2}, rankings[4])
|
||||
assert.Equal(t, Ranking{2, 6, 30.66, 40, 28, 24, 12, 6, 0.8497802817628735, 1, 3}, rankings[5])
|
||||
}
|
||||
|
||||
// Test after changing a match result.
|
||||
@@ -116,12 +116,12 @@ func TestCalculateRankings(t *testing.T) {
|
||||
rankings, err = db.GetAllRankings()
|
||||
assert.Nil(t, err)
|
||||
if assert.Equal(t, 6, len(rankings)) {
|
||||
assert.Equal(t, Ranking{3, 1, 152, 80, 56, 72, 4, 128, 0.6930700440076261, 0, 2}, rankings[0])
|
||||
assert.Equal(t, Ranking{1, 2, 152, 120, 84, 108, 6, 192, 0.284824110942037, 0, 3}, rankings[1])
|
||||
assert.Equal(t, Ranking{4, 3, 127, 60, 38, 72, 14, 88, 0.5102423328818813, 0, 2}, rankings[2])
|
||||
assert.Equal(t, Ranking{5, 4, 118.66, 80, 48, 108, 26, 112, 0.2092018731282357, 0, 3}, rankings[3])
|
||||
assert.Equal(t, Ranking{6, 5, 102, 40, 20, 72, 24, 48, 0.24043190328608438, 0, 2}, rankings[4])
|
||||
assert.Equal(t, Ranking{2, 6, 101.33, 80, 56, 72, 4, 128, 0.4018978925803393, 1, 3}, rankings[5])
|
||||
assert.Equal(t, Ranking{6, 1, 104, 80, 20, 48, 48, 12, 0.24043190328608438, 0, 2}, rankings[0])
|
||||
assert.Equal(t, Ranking{5, 2, 100, 120, 48, 72, 60, 18, 0.2092018731282357, 0, 3}, rankings[1])
|
||||
assert.Equal(t, Ranking{4, 3, 98, 80, 38, 48, 36, 12, 0.5102423328818813, 0, 2}, rankings[2])
|
||||
assert.Equal(t, Ranking{3, 4, 92, 80, 56, 48, 24, 12, 0.6930700440076261, 0, 2}, rankings[3])
|
||||
assert.Equal(t, Ranking{1, 5, 92, 120, 84, 72, 36, 18, 0.284824110942037, 0, 3}, rankings[4])
|
||||
assert.Equal(t, Ranking{2, 6, 61.33, 80, 56, 48, 24, 12, 0.4018978925803393, 1, 3}, rankings[5])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -63,14 +63,14 @@ func TestRefereeDisplayWebsocket(t *testing.T) {
|
||||
if assert.Equal(t, 2, len(mainArena.redRealtimeScore.Fouls)) {
|
||||
assert.Equal(t, 256, mainArena.redRealtimeScore.Fouls[0].TeamId)
|
||||
assert.Equal(t, "G22", mainArena.redRealtimeScore.Fouls[0].Rule)
|
||||
assert.Equal(t, 0, mainArena.redRealtimeScore.Fouls[0].TimeInMatchSec)
|
||||
assert.Equal(t, 0.0, mainArena.redRealtimeScore.Fouls[0].TimeInMatchSec)
|
||||
assert.Equal(t, 359, mainArena.redRealtimeScore.Fouls[1].TeamId)
|
||||
assert.Equal(t, "G22", mainArena.redRealtimeScore.Fouls[1].Rule)
|
||||
}
|
||||
if assert.Equal(t, 1, len(mainArena.blueRealtimeScore.Fouls)) {
|
||||
assert.Equal(t, 1680, mainArena.blueRealtimeScore.Fouls[0].TeamId)
|
||||
assert.Equal(t, "G22", mainArena.blueRealtimeScore.Fouls[0].Rule)
|
||||
assert.Equal(t, 0, mainArena.blueRealtimeScore.Fouls[0].TimeInMatchSec)
|
||||
assert.Equal(t, 0.0, mainArena.blueRealtimeScore.Fouls[0].TimeInMatchSec)
|
||||
}
|
||||
assert.False(t, mainArena.redRealtimeScore.FoulsCommitted)
|
||||
assert.False(t, mainArena.blueRealtimeScore.FoulsCommitted)
|
||||
|
||||
@@ -177,6 +177,7 @@ func ScoringDisplayWebsocketHandler(w http.ResponseWriter, r *http.Request) {
|
||||
case "commitMatch":
|
||||
if mainArena.MatchState != POST_MATCH {
|
||||
// Don't allow committing the score until the match is over.
|
||||
websocket.WriteError("Cannot commit score: Match is not over.")
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
@@ -52,100 +52,69 @@ func TestScoringDisplayWebsocket(t *testing.T) {
|
||||
defer blueConn.Close()
|
||||
blueWs := &Websocket{blueConn}
|
||||
|
||||
// Should a score update right after connection.
|
||||
// Should receive a score update right after connection.
|
||||
readWebsocketType(t, redWs, "score")
|
||||
readWebsocketType(t, redWs, "matchTime")
|
||||
readWebsocketType(t, blueWs, "score")
|
||||
readWebsocketType(t, blueWs, "matchTime")
|
||||
|
||||
// Send a match worth of scoring commands in.
|
||||
// TODO(pat): Update for 2015.
|
||||
/*
|
||||
redWs.Write("preload", "3")
|
||||
blueWs.Write("preload", "3")
|
||||
redWs.Write("mobility", nil)
|
||||
blueWs.Write("mobility", nil)
|
||||
blueWs.Write("mobility", nil)
|
||||
blueWs.Write("mobility", nil)
|
||||
blueWs.Write("scoredHighHot", nil)
|
||||
blueWs.Write("scoredHigh", nil)
|
||||
blueWs.Write("scoredLowHot", nil)
|
||||
blueWs.Write("scoredLow", nil)
|
||||
blueWs.Write("undo", nil)
|
||||
redWs.Write("commit", nil)
|
||||
blueWs.Write("commit", nil)
|
||||
redWs.Write("deadBall", nil)
|
||||
redWs.Write("commit", nil)
|
||||
redWs.Write("scoredLow", nil)
|
||||
redWs.Write("commit", nil)
|
||||
redWs.Write("scoredHigh", nil)
|
||||
redWs.Write("commit", nil)
|
||||
redWs.Write("assist", nil)
|
||||
blueWs.Write("assist", nil)
|
||||
blueWs.Write("assist", nil)
|
||||
blueWs.Write("assist", nil)
|
||||
blueWs.Write("assist", nil)
|
||||
blueWs.Write("scoredLow", nil)
|
||||
blueWs.Write("scoredHigh", nil)
|
||||
blueWs.Write("commit", nil)
|
||||
blueWs.Write("assist", nil)
|
||||
blueWs.Write("assist", nil)
|
||||
blueWs.Write("truss", nil)
|
||||
blueWs.Write("catch", nil)
|
||||
blueWs.Write("undo", nil)
|
||||
blueWs.Write("scoredLow", nil)
|
||||
blueWs.Write("commit", nil)
|
||||
mainArena.MatchState = POST_MATCH
|
||||
redWs.Write("commitMatch", nil)
|
||||
for i := 0; i < 11; i++ {
|
||||
readWebsocketType(t, redWs, "score")
|
||||
}
|
||||
for i := 0; i < 24; i++ {
|
||||
readWebsocketType(t, blueWs, "score")
|
||||
}
|
||||
redWs.Write("robotSet", nil)
|
||||
blueWs.Write("containerSet", nil)
|
||||
redWs.Write("stackedToteSet", nil)
|
||||
redWs.Write("robotSet", nil)
|
||||
redWs.Write("toteSet", nil)
|
||||
blueWs.Write("stackedToteSet", nil)
|
||||
redWs.Write("commit", nil)
|
||||
blueWs.Write("commit", nil)
|
||||
redWs.Write("uncommitAuto", nil)
|
||||
redWs.Write("robotSet", nil)
|
||||
redWs.Write("commit", nil)
|
||||
for i := 0; i < 8; i++ {
|
||||
readWebsocketType(t, redWs, "score")
|
||||
}
|
||||
for i := 0; i < 3; i++ {
|
||||
readWebsocketType(t, blueWs, "score")
|
||||
}
|
||||
assert.True(t, mainArena.redRealtimeScore.CurrentScore.AutoRobotSet)
|
||||
assert.False(t, mainArena.redRealtimeScore.CurrentScore.AutoContainerSet)
|
||||
assert.True(t, mainArena.redRealtimeScore.CurrentScore.AutoToteSet)
|
||||
assert.False(t, mainArena.redRealtimeScore.CurrentScore.AutoStackedToteSet)
|
||||
assert.False(t, mainArena.blueRealtimeScore.CurrentScore.AutoRobotSet)
|
||||
assert.True(t, mainArena.blueRealtimeScore.CurrentScore.AutoContainerSet)
|
||||
assert.False(t, mainArena.blueRealtimeScore.CurrentScore.AutoToteSet)
|
||||
assert.True(t, mainArena.blueRealtimeScore.CurrentScore.AutoStackedToteSet)
|
||||
|
||||
assert.Equal(t, 1, mainArena.redRealtimeScore.CurrentScore.AutoMobilityBonuses)
|
||||
assert.Equal(t, 0, mainArena.redRealtimeScore.CurrentScore.AutoHighHot)
|
||||
assert.Equal(t, 0, mainArena.redRealtimeScore.CurrentScore.AutoHigh)
|
||||
assert.Equal(t, 0, mainArena.redRealtimeScore.CurrentScore.AutoLowHot)
|
||||
assert.Equal(t, 0, mainArena.redRealtimeScore.CurrentScore.AutoLow)
|
||||
assert.Equal(t, 1, mainArena.redRealtimeScore.CurrentScore.AutoClearHigh)
|
||||
assert.Equal(t, 1, mainArena.redRealtimeScore.CurrentScore.AutoClearLow)
|
||||
assert.Equal(t, 1, mainArena.redRealtimeScore.CurrentScore.AutoClearDead)
|
||||
if assert.Equal(t, 1, len(mainArena.redRealtimeScore.CurrentScore.Cycles)) {
|
||||
assert.Equal(t, 1, mainArena.redRealtimeScore.CurrentScore.Cycles[0].Assists)
|
||||
assert.False(t, mainArena.redRealtimeScore.CurrentScore.Cycles[0].Truss)
|
||||
assert.False(t, mainArena.redRealtimeScore.CurrentScore.Cycles[0].Catch)
|
||||
assert.False(t, mainArena.redRealtimeScore.CurrentScore.Cycles[0].ScoredHigh)
|
||||
assert.False(t, mainArena.redRealtimeScore.CurrentScore.Cycles[0].ScoredLow)
|
||||
assert.False(t, mainArena.redRealtimeScore.CurrentScore.Cycles[0].DeadBall)
|
||||
}
|
||||
assert.True(t, mainArena.redRealtimeScore.AutoCommitted)
|
||||
assert.True(t, mainArena.redRealtimeScore.TeleopCommitted)
|
||||
stacks := []Stack{Stack{6, true, true}, Stack{1, false, false}, Stack{2, true, false}, Stack{}}
|
||||
blueWs.Write("commit", stacks)
|
||||
redWs.Write("commit", stacks)
|
||||
stacks[0].Litter = false
|
||||
blueWs.Write("commit", stacks)
|
||||
redWs.Write("toteSet", nil)
|
||||
blueWs.Write("stackedToteSet", nil)
|
||||
for i := 0; i < 2; i++ {
|
||||
readWebsocketType(t, redWs, "score")
|
||||
}
|
||||
for i := 0; i < 3; i++ {
|
||||
readWebsocketType(t, blueWs, "score")
|
||||
}
|
||||
assert.Equal(t, stacks, mainArena.blueRealtimeScore.CurrentScore.Stacks)
|
||||
stacks[0].Litter = true
|
||||
assert.Equal(t, stacks, mainArena.redRealtimeScore.CurrentScore.Stacks)
|
||||
|
||||
assert.Equal(t, 3, mainArena.blueRealtimeScore.CurrentScore.AutoMobilityBonuses)
|
||||
assert.Equal(t, 1, mainArena.blueRealtimeScore.CurrentScore.AutoHighHot)
|
||||
assert.Equal(t, 1, mainArena.blueRealtimeScore.CurrentScore.AutoHigh)
|
||||
assert.Equal(t, 1, mainArena.blueRealtimeScore.CurrentScore.AutoLowHot)
|
||||
assert.Equal(t, 0, mainArena.blueRealtimeScore.CurrentScore.AutoLow)
|
||||
assert.Equal(t, 0, mainArena.blueRealtimeScore.CurrentScore.AutoClearHigh)
|
||||
assert.Equal(t, 0, mainArena.blueRealtimeScore.CurrentScore.AutoClearLow)
|
||||
assert.Equal(t, 0, mainArena.blueRealtimeScore.CurrentScore.AutoClearDead)
|
||||
if assert.Equal(t, 2, len(mainArena.blueRealtimeScore.CurrentScore.Cycles)) {
|
||||
assert.Equal(t, 3, mainArena.blueRealtimeScore.CurrentScore.Cycles[0].Assists)
|
||||
assert.False(t, mainArena.blueRealtimeScore.CurrentScore.Cycles[0].Truss)
|
||||
assert.False(t, mainArena.blueRealtimeScore.CurrentScore.Cycles[0].Catch)
|
||||
assert.True(t, mainArena.blueRealtimeScore.CurrentScore.Cycles[0].ScoredHigh)
|
||||
assert.False(t, mainArena.blueRealtimeScore.CurrentScore.Cycles[0].ScoredLow)
|
||||
assert.False(t, mainArena.blueRealtimeScore.CurrentScore.Cycles[0].DeadBall)
|
||||
assert.Equal(t, 2, mainArena.blueRealtimeScore.CurrentScore.Cycles[1].Assists)
|
||||
assert.True(t, mainArena.blueRealtimeScore.CurrentScore.Cycles[1].Truss)
|
||||
assert.False(t, mainArena.blueRealtimeScore.CurrentScore.Cycles[1].Catch)
|
||||
assert.False(t, mainArena.blueRealtimeScore.CurrentScore.Cycles[1].ScoredHigh)
|
||||
assert.True(t, mainArena.blueRealtimeScore.CurrentScore.Cycles[1].ScoredLow)
|
||||
assert.False(t, mainArena.blueRealtimeScore.CurrentScore.Cycles[1].DeadBall)
|
||||
}
|
||||
assert.True(t, mainArena.blueRealtimeScore.AutoCommitted)
|
||||
assert.False(t, mainArena.blueRealtimeScore.TeleopCommitted)
|
||||
*/
|
||||
// Test committing logic.
|
||||
redWs.Write("commitMatch", nil)
|
||||
readWebsocketType(t, redWs, "error")
|
||||
mainArena.MatchState = POST_MATCH
|
||||
redWs.Write("commitMatch", nil)
|
||||
blueWs.Write("commitMatch", nil)
|
||||
readWebsocketType(t, redWs, "dialog") // Should be an error message about co-op not matching.
|
||||
readWebsocketType(t, blueWs, "dialog")
|
||||
redWs.Write("stackedToteSet", nil)
|
||||
redWs.Write("commitMatch", nil)
|
||||
blueWs.Write("commitMatch", nil)
|
||||
readWebsocketType(t, redWs, "score")
|
||||
readWebsocketType(t, blueWs, "score")
|
||||
|
||||
// Load another match to reset the results.
|
||||
mainArena.ResetMatch()
|
||||
|
||||
@@ -47,9 +47,9 @@ func TestSetupSchedule(t *testing.T) {
|
||||
assert.Contains(t, recorder.Body.String(), "Failed to publish matches")
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 64, len(matches))
|
||||
assert.Equal(t, 1388595600, matches[0].Time.Unix())
|
||||
assert.Equal(t, 1388685360, matches[7].Time.Unix())
|
||||
assert.Equal(t, 1388782800, matches[24].Time.Unix())
|
||||
assert.Equal(t, int64(1388595600), matches[0].Time.Unix())
|
||||
assert.Equal(t, int64(1388685360), matches[7].Time.Unix())
|
||||
assert.Equal(t, int64(1388782800), matches[24].Time.Unix())
|
||||
}
|
||||
|
||||
func TestSetupScheduleErrors(t *testing.T) {
|
||||
|
||||
10
tba_test.go
10
tba_test.go
@@ -61,11 +61,11 @@ func TestPublishMatches(t *testing.T) {
|
||||
tbaServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
var reader bytes.Buffer
|
||||
reader.ReadFrom(r.Body)
|
||||
assert.Equal(t, "[{\"comp_level\":\"qm\",\"match_number\":2,\"alliances\":{\"blue\":{\"score\":102,"+
|
||||
"\"teams\":[\"frc10\",\"frc11\",\"frc12\"]},\"red\":{\"score\":152,\"teams\":[\"frc7\","+
|
||||
"\"frc8\",\"frc9\"]}},\"score_breakdown\":{\"blue\":{\"coopertition\":20,\"auto\":10,"+
|
||||
"\"container\":36,\"tote\":12,\"litter\":24,\"foul\":0},\"red\":{\"coopertition\":40,"+
|
||||
"\"auto\":28,\"container\":36,\"tote\":2,\"litter\":64,\"foul\":18}},\"time_string\":"+
|
||||
assert.Equal(t, "[{\"comp_level\":\"qm\",\"match_number\":2,\"alliances\":{\"blue\":{\"score\":104,"+
|
||||
"\"teams\":[\"frc10\",\"frc11\",\"frc12\"]},\"red\":{\"score\":92,\"teams\":[\"frc7\","+
|
||||
"\"frc8\",\"frc9\"]}},\"score_breakdown\":{\"blue\":{\"coopertition\":40,\"auto\":10,"+
|
||||
"\"container\":24,\"tote\":24,\"litter\":6,\"foul\":0},\"red\":{\"coopertition\":40,"+
|
||||
"\"auto\":28,\"container\":24,\"tote\":12,\"litter\":6,\"foul\":18}},\"time_string\":"+
|
||||
"\"4:10 PM\",\"time_utc\":\"1970-01-01T00:10:00\"},{\"comp_level\":\"sf\",\"match_number\":2,"+
|
||||
"\"alliances\":{\"blue\":{\"score\":null,\"teams\":[\"frc0\",\"frc0\",\"frc0\"]},\"red\":"+
|
||||
"{\"score\":null,\"teams\":[\"frc0\",\"frc0\",\"frc0\"]}},\"score_breakdown\":null,"+
|
||||
|
||||
Reference in New Issue
Block a user