aboutsummaryrefslogtreecommitdiff
path: root/go/game/action_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'go/game/action_test.go')
-rw-r--r--go/game/action_test.go64
1 files changed, 64 insertions, 0 deletions
diff --git a/go/game/action_test.go b/go/game/action_test.go
new file mode 100644
index 00000000..b1642bd1
--- /dev/null
+++ b/go/game/action_test.go
@@ -0,0 +1,64 @@
+package game
+
+import (
+ "testing"
+)
+
+const PASS_STRING = "muhq\u00A0pass"
+
+var s *LocalState = NewLocalState()
+var p *Player = s.AddNewPlayer("muhq", NewDeck(), nil)
+
+func TestMarshalPass(t *testing.T) {
+ exp := PASS_STRING
+ a := NewPassPriority(p)
+ is := string(MarshalAction(a))
+ if is != exp {
+ t.Fatalf("expected string %s does not match %s\n", exp, is)
+ }
+}
+
+func TestUnmarshalPass(t *testing.T) {
+ in := PASS_STRING
+ a, err := UnmarshalAction(s, []byte(in))
+ if err != nil {
+ t.Fatal(err)
+ }
+ if _, ok := a.(*PassPriority); !ok {
+ t.Fatalf("expexted PassPriority not %s", a)
+ }
+}
+
+const PICK_ACTION_STRING = "muhq\u00A0pick\u00A0base/archer:[base/archer, magic/more!]"
+
+func TestMarshalPickAction(t *testing.T) {
+ exp := PICK_ACTION_STRING
+ poc := NewPileOfCards()
+ c := NewCard("base/archer")
+ poc.AddCard(c)
+ poc.AddCard(NewCard("magic/more!"))
+ a := NewDraftPick(p, poc, c)
+ is := string(MarshalAction(a))
+ if is != exp {
+ t.Fatalf("expected string %s does not match %s\n", exp, is)
+ }
+}
+
+func TestUnmarshalPickAction(t *testing.T) {
+ in := PICK_ACTION_STRING
+ a, err := UnmarshalAction(s, []byte(in))
+ if err != nil {
+ t.Fatal(err)
+ }
+ var p *DraftPick
+ var ok bool
+ if p, ok = a.(*DraftPick); !ok {
+ t.Fatalf("expexted DraftPick not %v", a)
+ }
+ if len(p.pack.Cards()) != 2 {
+ t.Fatalf("expexted two cards in pack not %d", len(p.pack.Cards()))
+ }
+ if p.pick.Name != "Archer" {
+ t.Fatalf("expexted archer beeing picked not %s", p.pick.Path())
+ }
+}