// Copyright (c) 2016 Florian Fischer. All rights reserved. // Use of this source code is governed by a MIT license found in the LICENSE file. package logic import "testing" func TestScore(t *testing.T) { s := NewScore() s = []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 = []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 = []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 := Dice{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 = Dice{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 = Dice{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 = Dice{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 = Dice{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 = Dice{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 = Dice{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 = Dice{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 = Dice{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 = Dice{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 = Dice{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 = Dice{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 = Dice{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) } } func TestCancel(t *testing.T) { s := NewScore() err := s.Cancel(1) if err != nil { t.Errorf("Cancelling Aces should not fail: %v", err) } err = s.Cancel(1) if err == nil { t.Errorf("Cancelling Aces twice should fail") } err = s.Cancel(12) if err != nil { t.Errorf("Cancelling Yahtzee should not fail: %v", err) } err = s.Cancel(22) if err == nil { t.Errorf("Cancelling 22 should fail") } }