aboutsummaryrefslogtreecommitdiff
path: root/go/game/pileOfCards_test.go
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2025-07-05 17:35:58 -0400
committerFlorian Fischer <florian.fischer@muhq.space>2025-08-20 15:57:24 +0200
commitf46c023f0eadd2be844d40afaafded1b0f14a9fc (patch)
tree3c5bcd0dff4c88ccc5eba53650dbbd0d21cbc439 /go/game/pileOfCards_test.go
parent91af2f3fe4a9b40093ea43c7c899f8281ee887f8 (diff)
downloadmuhqs-game-f46c023f0eadd2be844d40afaafded1b0f14a9fc.tar.gz
muhqs-game-f46c023f0eadd2be844d40afaafded1b0f14a9fc.zip
fail if loading an unknown card and add more poc test cases
Diffstat (limited to 'go/game/pileOfCards_test.go')
-rw-r--r--go/game/pileOfCards_test.go80
1 files changed, 80 insertions, 0 deletions
diff --git a/go/game/pileOfCards_test.go b/go/game/pileOfCards_test.go
index 0c9532fe..45203953 100644
--- a/go/game/pileOfCards_test.go
+++ b/go/game/pileOfCards_test.go
@@ -1,6 +1,7 @@
package game
import (
+ "errors"
"testing"
)
@@ -22,4 +23,83 @@ func TestPocFromString(t *testing.T) {
if err != nil {
t.Fatal(err)
}
+
+ // Error cases
+ poc = NewPileOfCards()
+ in = "base/archer, magic/ritual!]"
+ err = poc.FromString(in)
+ if !errors.Is(err, ErrInvalidPocString) {
+ t.Fatal("expected ErrInvalidPocString")
+ }
+
+ in = "[base/archer, magic/ritual!"
+ err = poc.FromString(in)
+ if !errors.Is(err, ErrInvalidPocString) {
+ t.Fatal("expected ErrInvalidPocString")
+ }
+
+ in = "[base/archer magic/ritual!]"
+ err = poc.FromString(in)
+ if !errors.Is(err, ErrUnknownCardPath) {
+ t.Fatal("expected url.Error")
+ }
+}
+
+func TestPocAddRemoveCard(t *testing.T) {
+ poc := NewPileOfCards()
+ archer := NewCard("base/archer")
+ poc.AddCard(archer)
+ if poc.IsEmpty() {
+ t.Fatal("poc till empty")
+ }
+ if poc.Size() != 1 {
+ t.Fatal("poc size != 1:", poc.Size())
+ }
+ if !poc.Contains(archer) {
+ t.Fatal("poc does not contain archer")
+ }
+ knight := NewCard("base/knight")
+ poc.RemoveCard(knight)
+ if poc.Size() != 1 {
+ t.Fatal("poc size != 1:", poc.Size())
+ }
+ poc.RemoveCard(archer)
+ if poc.Size() != 0 {
+ t.Fatal("poc size != 0:", poc.Size())
+ }
+ if poc.Contains(archer) {
+ t.Fatal("poc still contains archer")
+ }
+}
+
+func TestPocMoveCard(t *testing.T) {
+ poc1 := NewPileOfCards()
+ poc2 := NewPileOfCards()
+ archer := NewCard("base/archer")
+ poc1.AddCard(archer)
+ poc1.MoveCard(archer, poc2)
+ if poc1.Size() != 0 {
+ t.Fatal("poc1 size != 0:", poc1.Size())
+ }
+ if poc2.Size() != 1 {
+ t.Fatal("poc2 size != 1:", poc2.Size())
+ }
+}
+
+func TestPocToList(t *testing.T) {
+ poc := NewPileOfCards()
+ archer1 := NewCard("base/archer")
+ poc.AddCard(archer1)
+ archer2 := NewCard("base/archer")
+ poc.AddCard(archer2)
+ knight := NewCard("base/knight")
+ poc.AddCard(knight)
+ if poc.Size() != 3 {
+ t.Fatal("poc size != 3:", poc.Size())
+ }
+ is := poc.ToList()
+ exp := "2 base/archer\n1 base/knight"
+ if is != exp {
+ t.Fatal("is != exp:", is, exp)
+ }
}