aboutsummaryrefslogtreecommitdiff
path: root/go/game/action_test.go
blob: 1c5a7262970c8568946780e2758b969437005e4f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package game

import (
	"testing"
)

const PASS_STRING = "muhq\u00A0pass"

var s *LocalState = NewLocalState()
var p *Player = s.AddNewPlayer("muhq", NewDeck())

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())
	}
}