diff options
Diffstat (limited to 'logic')
| -rw-r--r-- | logic/score.go | 4 | ||||
| -rw-r--r-- | logic/score_test.go | 25 |
2 files changed, 27 insertions, 2 deletions
diff --git a/logic/score.go b/logic/score.go index af6eefc..d65bb7c 100644 --- a/logic/score.go +++ b/logic/score.go @@ -129,8 +129,8 @@ func (s_ *Score) Cancel(pos int) error { if pos < 0 || pos > 12 { return errors.New("Index out of range") } - if s[pos] == 0 { - s[pos] = -1 + if s[pos] == -1 { + s[pos] = 0 return nil } return errors.New("Already recorded") diff --git a/logic/score_test.go b/logic/score_test.go index 4fe0000..11a460c 100644 --- a/logic/score_test.go +++ b/logic/score_test.go @@ -111,3 +111,28 @@ func TestInsert(t *testing.T) { 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") + } + +} |
