diff options
Diffstat (limited to 'logic/score_test.go')
| -rw-r--r-- | logic/score_test.go | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/logic/score_test.go b/logic/score_test.go new file mode 100644 index 0000000..8371014 --- /dev/null +++ b/logic/score_test.go @@ -0,0 +1,110 @@ +package logic + +import "testing" + +func TestScore(t *testing.T) { + s := NewScore() + s.values = [13]int{1, 2, 3, 4, 5, 6, 23, 27, 25, 30, 40, -1, 26} + if s.Score() != 192 { + t.Errorf("Score of \n%v should be 192", s) + } + s.values = [13]int{3, 6, 9, 12, 15, 18, 23, 27, 25, 30, 40, -1, 26} + if s.Score() != 269 { + t.Errorf("Score of \n%v should be 269", s) + } + s.values = [13]int{1, 8, 6, 8, 15, 12, 23, 15, -1, 30, 40, -1, 26} + if s.Score() != 184 { + t.Errorf("Score of \n%v should be 184", s) + } +} + +func TestInsert(t *testing.T) { + s := NewScore() + d := Dices{1, 2, 3, 4, 5} + p, err := s.Insert(d, 0) + if p != 1 || err != nil { + t.Errorf("Inserting %v as aces should return 1", d) + } + + d = Dices{1, 2, 2, 3, 4} + p, err = s.Insert(d, 1) + if p != 4 || err != nil { + t.Errorf("Inserting %v as twos should return 4", d) + } + + p, err = s.Insert(d, 1) + if p != 0 || err == nil { + t.Errorf("Inserting %v as twos again should fail", d) + } + + d = Dices{1, 2, 2, 4, 4} + p, err = s.Insert(d, 2) + if p != 0 || err != nil { + t.Errorf("Inserting %v as threes should return 0", d) + } + + d = Dices{1, 2, 2, 6, 6} + p, err = s.Insert(d, 5) + if p != 12 || err != nil { + t.Errorf("Inserting %v as sixes should return 12", d) + } + + d = Dices{1, 2, 6, 6, 6} + p, err = s.Insert(d, 6) + if p != 21 || err != nil { + t.Errorf("Inserting %v as three of a kind should return 21", d) + } + + d = Dices{1, 1, 2, 2, 2} + p, err = s.Insert(d, 7) + if p != 0 || err == nil { + t.Errorf("Inserting %v as four of a kind should fail", d) + } + + d = Dices{1, 2, 2, 2, 2} + p, err = s.Insert(d, 7) + if p != 9 || err != nil { + t.Errorf("Inserting %v as four of a kind should return 9", d) + } + + d = Dices{1, 1, 2, 2, 2} + p, err = s.Insert(d, 8) + if p != 25 || err != nil { + t.Errorf("Inserting %v as full house should return 25", d) + } + + d = Dices{1, 2, 3, 4, 5} + p, err = s.Insert(d, 9) + if p != 30 || err != nil { + t.Errorf("Inserting %v as small straight should return 30", d) + } + + d = Dices{1, 2, 3, 4, 5} + p, err = s.Insert(d, 10) + if p != 40 || err != nil { + t.Errorf("Inserting %v as large straight should return 40", d) + } + + d = Dices{2, 2, 3, 4, 5} + p, err = s.Insert(d, 10) + if p != 0 || err == nil { + t.Errorf("Inserting %v as large straight should fail", d) + } + + d = Dices{2, 2, 2, 2, 2} + p, err = s.Insert(d, 11) + if p != 50 || err != nil { + t.Errorf("Inserting %v as yahtzee should return 50", d) + } + + d = Dices{1, 3, 3, 5, 6} + p, err = s.Insert(d, 12) + if p != 18 || err != nil { + t.Errorf("Inserting %v as chance should return 18", d) + } + + p, err = s.Insert(d, 200) + if p != 0 || err == nil { + t.Errorf("Inserting %v at index 200 should fail", d) + } +} |
