aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fl.fischer@fau.de>2017-02-09 14:18:40 +0100
committerFlorian Fischer <florian.fl.fischer@fau.de>2017-02-09 14:18:40 +0100
commit059304e75e6483cead75a18115b67a4aee75cdb3 (patch)
tree3361928e959ad3b5d7cea73368b9b30f1dc6986c
parentba2e08b09989ad68c3cfb9787c2b8322ea0a8c26 (diff)
downloadgoffel-059304e75e6483cead75a18115b67a4aee75cdb3.tar.gz
goffel-059304e75e6483cead75a18115b67a4aee75cdb3.zip
Score: fix Cancel() and add tests
-rw-r--r--logic/score.go4
-rw-r--r--logic/score_test.go25
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")
+ }
+
+}