M3: Zählerlogik - Scoreboard mit Rot/Grün, Runden, Reset
This commit is contained in:
@@ -0,0 +1,162 @@
|
||||
package logik
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestNewScoreboard(t *testing.T) {
|
||||
sb := NewScoreboard()
|
||||
|
||||
if sb.CurrentRound != 1 {
|
||||
t.Errorf("NewScoreboard() CurrentRound = %d, want 1", sb.CurrentRound)
|
||||
}
|
||||
if sb.RedScore != 0 {
|
||||
t.Errorf("NewScoreboard() RedScore = %d, want 0", sb.RedScore)
|
||||
}
|
||||
if sb.GreenScore != 0 {
|
||||
t.Errorf("NewScoreboard() GreenScore = %d, want 0", sb.GreenScore)
|
||||
}
|
||||
if len(sb.Rounds) != 0 {
|
||||
t.Errorf("NewScoreboard() len(Rounds) = %d, want 0", len(sb.Rounds))
|
||||
}
|
||||
}
|
||||
|
||||
func TestScore_Red(t *testing.T) {
|
||||
sb := NewScoreboard()
|
||||
sb.Score(TeamRed)
|
||||
|
||||
if sb.RedScore != 1 {
|
||||
t.Errorf("Score(TeamRed) RedScore = %d, want 1", sb.RedScore)
|
||||
}
|
||||
if sb.GreenScore != 0 {
|
||||
t.Errorf("Score(TeamRed) GreenScore = %d, want 0", sb.GreenScore)
|
||||
}
|
||||
}
|
||||
|
||||
func TestScore_Green(t *testing.T) {
|
||||
sb := NewScoreboard()
|
||||
sb.Score(TeamGreen)
|
||||
|
||||
if sb.GreenScore != 1 {
|
||||
t.Errorf("Score(TeamGreen) GreenScore = %d, want 1", sb.GreenScore)
|
||||
}
|
||||
if sb.RedScore != 0 {
|
||||
t.Errorf("Score(TeamGreen) RedScore = %d, want 0", sb.RedScore)
|
||||
}
|
||||
}
|
||||
|
||||
func TestScore_Multiple(t *testing.T) {
|
||||
sb := NewScoreboard()
|
||||
sb.Score(TeamRed)
|
||||
sb.Score(TeamRed)
|
||||
sb.Score(TeamRed)
|
||||
sb.Score(TeamGreen)
|
||||
|
||||
if sb.RedScore != 3 {
|
||||
t.Errorf("Score() RedScore = %d, want 3", sb.RedScore)
|
||||
}
|
||||
if sb.GreenScore != 1 {
|
||||
t.Errorf("Score() GreenScore = %d, want 1", sb.GreenScore)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNextRound(t *testing.T) {
|
||||
sb := NewScoreboard()
|
||||
sb.Score(TeamRed)
|
||||
sb.Score(TeamRed)
|
||||
sb.Score(TeamGreen)
|
||||
sb.NextRound()
|
||||
|
||||
if sb.CurrentRound != 2 {
|
||||
t.Errorf("NextRound() CurrentRound = %d, want 2", sb.CurrentRound)
|
||||
}
|
||||
if sb.RedScore != 0 {
|
||||
t.Errorf("NextRound() RedScore = %d, want 0", sb.RedScore)
|
||||
}
|
||||
if sb.GreenScore != 0 {
|
||||
t.Errorf("NextRound() GreenScore = %d, want 0", sb.GreenScore)
|
||||
}
|
||||
if len(sb.Rounds) != 1 {
|
||||
t.Errorf("NextRound() len(Rounds) = %d, want 1", len(sb.Rounds))
|
||||
}
|
||||
if sb.Rounds[0].Red != 2 {
|
||||
t.Errorf("NextRound() Rounds[0].Red = %d, want 2", sb.Rounds[0].Red)
|
||||
}
|
||||
if sb.Rounds[0].Green != 1 {
|
||||
t.Errorf("NextRound() Rounds[0].Green = %d, want 1", sb.Rounds[0].Green)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNextRound_Multiple(t *testing.T) {
|
||||
sb := NewScoreboard()
|
||||
sb.Score(TeamRed)
|
||||
sb.Score(TeamRed)
|
||||
sb.NextRound()
|
||||
|
||||
sb.Score(TeamGreen)
|
||||
sb.Score(TeamGreen)
|
||||
sb.Score(TeamGreen)
|
||||
sb.Score(TeamGreen)
|
||||
sb.NextRound()
|
||||
|
||||
if sb.CurrentRound != 3 {
|
||||
t.Errorf("NextRound() CurrentRound = %d, want 2", sb.CurrentRound)
|
||||
}
|
||||
if len(sb.Rounds) != 2 {
|
||||
t.Errorf("NextRound() len(Rounds) = %d, want 2", len(sb.Rounds))
|
||||
}
|
||||
if sb.Rounds[1].Green != 4 {
|
||||
t.Errorf("NextRound() Rounds[1].Green = %d, want 4", sb.Rounds[1].Green)
|
||||
}
|
||||
}
|
||||
|
||||
func TestReset(t *testing.T) {
|
||||
sb := NewScoreboard()
|
||||
sb.Score(TeamRed)
|
||||
sb.Score(TeamGreen)
|
||||
sb.Score(TeamGreen)
|
||||
sb.NextRound()
|
||||
sb.Score(TeamRed)
|
||||
sb.Score(TeamRed)
|
||||
sb.Score(TeamRed)
|
||||
sb.Reset()
|
||||
|
||||
if sb.CurrentRound != 1 {
|
||||
t.Errorf("Reset() CurrentRound = %d, want 1", sb.CurrentRound)
|
||||
}
|
||||
if sb.RedScore != 0 {
|
||||
t.Errorf("Reset() RedScore = %d, want 0", sb.RedScore)
|
||||
}
|
||||
if sb.GreenScore != 0 {
|
||||
t.Errorf("Reset() GreenScore = %d, want 0", sb.GreenScore)
|
||||
}
|
||||
if len(sb.Rounds) != 0 {
|
||||
t.Errorf("Reset() len(Rounds) = %d, want 0", len(sb.Rounds))
|
||||
}
|
||||
}
|
||||
|
||||
func TestString(t *testing.T) {
|
||||
sb := NewScoreboard()
|
||||
sb.Score(TeamRed)
|
||||
sb.Score(TeamRed)
|
||||
sb.Score(TeamGreen)
|
||||
output := sb.String()
|
||||
|
||||
expected := "Runde 1\nrot: 2 | gruen: 1\n"
|
||||
if output != expected {
|
||||
t.Errorf("String() = %q, want %q", output, expected)
|
||||
}
|
||||
}
|
||||
|
||||
func TestString_WithRounds(t *testing.T) {
|
||||
sb := NewScoreboard()
|
||||
sb.Score(TeamRed)
|
||||
sb.NextRound()
|
||||
sb.Score(TeamGreen)
|
||||
sb.Score(TeamGreen)
|
||||
sb.NextRound()
|
||||
output := sb.String()
|
||||
|
||||
expected := "Runde 3\nrot: 0 | gruen: 0\n---\nRunde 1: 1:0\nRunde 2: 0:2\n"
|
||||
if output != expected {
|
||||
t.Errorf("String() = %q, want %q", output, expected)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user