mirror of
https://github.com/Team254/cheesy-arena-lite.git
synced 2026-03-09 21:56:50 -04:00
65 lines
2.1 KiB
Go
65 lines
2.1 KiB
Go
// Copyright 2017 Team 254. All Rights Reserved.
|
|
// Author: pat@patfairbank.com (Patrick Fairbank)
|
|
|
|
package game
|
|
|
|
import (
|
|
"github.com/stretchr/testify/assert"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
var matchStartTime = time.Unix(10, 0)
|
|
|
|
func TestFuelBeforeMatch(t *testing.T) {
|
|
boiler := Boiler{}
|
|
|
|
boiler.UpdateState(1, 2, matchStartTime, timeAfterStart(-1))
|
|
checkBoilerCounts(t, 1, 2, 0, 0, &boiler)
|
|
}
|
|
|
|
func TestAutoFuel(t *testing.T) {
|
|
boiler := Boiler{}
|
|
|
|
boiler.UpdateState(3, 4, matchStartTime, timeAfterStart(1))
|
|
checkBoilerCounts(t, 3, 4, 0, 0, &boiler)
|
|
boiler.UpdateState(5, 6, matchStartTime, timeAfterStart(10))
|
|
checkBoilerCounts(t, 5, 6, 0, 0, &boiler)
|
|
boiler.UpdateState(7, 8, matchStartTime, timeAfterStart(19.9))
|
|
checkBoilerCounts(t, 7, 8, 0, 0, &boiler)
|
|
boiler.UpdateState(9, 11, matchStartTime, timeAfterStart(20.1))
|
|
checkBoilerCounts(t, 7, 8, 2, 3, &boiler)
|
|
}
|
|
|
|
func TestTeleopFuel(t *testing.T) {
|
|
boiler := Boiler{}
|
|
|
|
boiler.UpdateState(1, 2, matchStartTime, timeAfterStart(1))
|
|
boiler.UpdateState(3, 5, matchStartTime, timeAfterStart(21))
|
|
checkBoilerCounts(t, 1, 2, 2, 3, &boiler)
|
|
boiler.UpdateState(5, 7, matchStartTime, timeAfterStart(120))
|
|
checkBoilerCounts(t, 1, 2, 4, 5, &boiler)
|
|
boiler.UpdateState(7, 9, matchStartTime, timeAfterEnd(-1))
|
|
checkBoilerCounts(t, 1, 2, 6, 7, &boiler)
|
|
boiler.UpdateState(9, 11, matchStartTime, timeAfterEnd(4.9))
|
|
checkBoilerCounts(t, 1, 2, 8, 9, &boiler)
|
|
boiler.UpdateState(11, 13, matchStartTime, timeAfterEnd(5.1))
|
|
checkBoilerCounts(t, 1, 2, 8, 9, &boiler)
|
|
}
|
|
|
|
func checkBoilerCounts(t *testing.T, autoLow, autoHigh, low, high int, boiler *Boiler) {
|
|
assert.Equal(t, autoLow, boiler.AutoFuelLow)
|
|
assert.Equal(t, autoHigh, boiler.AutoFuelHigh)
|
|
assert.Equal(t, low, boiler.FuelLow)
|
|
assert.Equal(t, high, boiler.FuelHigh)
|
|
}
|
|
func timeAfterStart(sec float32) time.Time {
|
|
return matchStartTime.Add(time.Duration(1000*sec) * time.Millisecond)
|
|
}
|
|
|
|
func timeAfterEnd(sec float32) time.Time {
|
|
matchDuration := time.Duration(MatchTiming.AutoDurationSec+MatchTiming.PauseDurationSec+
|
|
MatchTiming.TeleopDurationSec) * time.Second
|
|
return matchStartTime.Add(matchDuration).Add(time.Duration(1000*sec) * time.Millisecond)
|
|
}
|