aboutsummaryrefslogtreecommitdiff
path: root/go/game/playerControl_test.go
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2025-07-04 09:20:48 -0400
committerFlorian Fischer <florian.fischer@muhq.space>2025-07-06 11:49:19 -0400
commitf3e085ceccd95899d8d705a28266003709ab87b7 (patch)
tree30869054b059b2484d44e8caf60d4755fd244318 /go/game/playerControl_test.go
parent53ba6a1c0cd020f26d501912320a41e8dc736976 (diff)
downloadmuhqs-game-f3e085ceccd95899d8d705a28266003709ab87b7.tar.gz
muhqs-game-f3e085ceccd95899d8d705a28266003709ab87b7.zip
refactor playerControl
Allow to propagate errors in order to handle them acordingly. Use playerNotifications by value to reduce the amount of allocations. Add session managment playerNotifications. Support marshalling notifications to plain text.
Diffstat (limited to 'go/game/playerControl_test.go')
-rw-r--r--go/game/playerControl_test.go56
1 files changed, 56 insertions, 0 deletions
diff --git a/go/game/playerControl_test.go b/go/game/playerControl_test.go
new file mode 100644
index 00000000..34f20c59
--- /dev/null
+++ b/go/game/playerControl_test.go
@@ -0,0 +1,56 @@
+package game
+
+import (
+ "testing"
+)
+
+const PRORITY_STRING = "!priority{}"
+
+func TestMarshalPriority(t *testing.T) {
+ exp := PRORITY_STRING
+ n := newPriorityNotification()
+ is := string(n.Marshal(nil))
+ if is != exp {
+ t.Fatalf("expected string %s does not match %s\n", exp, is)
+ }
+}
+
+func TestUnmarshalPriority(t *testing.T) {
+ in := PRORITY_STRING
+ n, err := UnmarshalPlayerNotification(nil, []byte(in))
+ if err != nil {
+ t.Fatal(err)
+ }
+ if n.Notification != PriorityNotification {
+ t.Fatalf("expexted PriorityNotificaton not %s", n.Notification)
+ }
+}
+
+const PICK_STRING = "!pick{[base/archer, magic/more!]}"
+
+func TestMarshalPick(t *testing.T) {
+ exp := PICK_STRING
+ poc := NewPileOfCards()
+ poc.AddCard(NewCard("base/archer"))
+ poc.AddCard(NewCard("magic/more!"))
+ n := newDraftPickPrompt(poc)
+ is := string(n.Marshal(nil))
+ if is != exp {
+ t.Fatalf("expected string %s does not match %s\n", exp, is)
+ }
+}
+
+func TestUnmarshalPick(t *testing.T) {
+ in := PICK_STRING
+ n, err := UnmarshalPlayerNotification(nil, []byte(in))
+ if err != nil {
+ t.Fatal(err)
+ }
+ if n.Notification != DraftPickPrompt {
+ t.Fatalf("expexted DraftPickPrompt not %s", n.Notification)
+ }
+ pack := n.Context.(PileOfCards)
+ if len(pack.Cards()) != 2 {
+ t.Fatalf("expexted two cards in pack not %d", len(pack.Cards()))
+ }
+}