aboutsummaryrefslogtreecommitdiff
path: root/go/game/unit_test.go
blob: 341fb350a4e3737cc1150d3df3a126d6815f673e (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
package game

import (
	"strings"
	"testing"
)

func TestCrew(t *testing.T) {
	mapDef := `map: |1-
 HST
 HSF
 TSW
symbols:
  T: tower
  H: house
  F: farm
  S: street
  W: deep water
`
	s := NewState()
	r := strings.NewReader(mapDef)
	s.Map, _ = readMap(r)
	f := NewUnit(NewCard("nautics/fisher"), s.Map.TileAt(Position{2, 2}), nil)
	a := NewUnit(NewCard("base/archer"), s.Map.TileAt(Position{1, 1}), nil)
	sword := newEquipment(NewCard("base/sword"), s.Map.TileAt(Position{0, 1}), nil)

	a.move(s, f.Tile())
	if len(f.Pile()) != 1 {
		t.Fatalf("fisher's pile size is not 1")
	}

	if f.Pile()[0] != a {
		t.Fatalf("fisher's pile does not contain the archer")
	}

	if a.Tile() != nil {
		t.Fatalf("piled archer has still a tile %v", a.Tile())
	}

	for r, d := range f.Attack.attacks {
		if d != a.Attack.attacks[r] {
			t.Fatalf("fisher's attack %d is not equal to the archer's attack %d at range %d",
				d, a.Attack.attacks[r], r)
		}
	}

	a.move(s, s.Map.TileAt(Position{1, 1}))
	if len(f.Pile()) != 0 {
		t.Fatalf("fisher's pile is not empty")
	}

	if !INVALID_ATTACK(f.Attack) {
		t.Fatalf("fisher has still a valid atack")
	}

	AddPermanentToPile(a, sword)
	if a.Attack.attacks[0] != 2 {
		t.Fatalf("archer's mele attack is not 2")
	}
}