aboutsummaryrefslogtreecommitdiff
path: root/go/game/playerControl_test.go
blob: 2727df0bf964ca4f4d59b7e91ca1348eea563ff7 (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package game

import (
	"testing"
)

type MockPlayerControl struct {
	p                 *Player
	sentNotifications []PlayerNotification
	actionToSend      Action
}

func newMockPlayerControl(p *Player) *MockPlayerControl {
	return &MockPlayerControl{p: p}
}

func (ctrl *MockPlayerControl) Close()          {}
func (ctrl *MockPlayerControl) Player() *Player { return ctrl.p }
func (ctrl *MockPlayerControl) RecvNotification() (n PlayerNotification, err error) {
	return
}

func (ctrl *MockPlayerControl) SendNotification(n PlayerNotification) error {
	ctrl.sentNotifications = append(ctrl.sentNotifications, n)
	return nil
}

func (ctrl *MockPlayerControl) RecvAction() (Action, error) {
	return ctrl.actionToSend, nil
}
func (ctrl *MockPlayerControl) SendAction(Action) error { return nil }

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