aboutsummaryrefslogtreecommitdiff
path: root/go/game/targets_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'go/game/targets_test.go')
-rw-r--r--go/game/targets_test.go43
1 files changed, 43 insertions, 0 deletions
diff --git a/go/game/targets_test.go b/go/game/targets_test.go
index 672df356..07df4b60 100644
--- a/go/game/targets_test.go
+++ b/go/game/targets_test.go
@@ -3,6 +3,8 @@ package game
import (
"strings"
"testing"
+
+ "muhq.space/muhqs-game/go/utils"
)
func TestTileTargets(t *testing.T) {
@@ -214,3 +216,44 @@ symbols:
t.Fatalf("%v not a valid target for %v", sword, fa)
}
}
+
+func TestUnitConstraint(t *testing.T) {
+ s, _, p, o := newMockState()
+
+ a := s.addNewUnit(NewCard("base/archer"), Position{0, 0}, p)
+ oa := s.addNewUnit(NewCard("base/archer"), Position{1, 1}, o)
+
+ desc := newTargetDesc("enemy unit")
+ // Use a dummy pass action to pass the player to the target constraints
+ target := newTarget(s, desc, NewPassPriority(p))
+ options := target.Options()
+ if !utils.InterfaceSliceContains(options, oa) {
+ t.Fatal("enemy units does not contain opponent's archer")
+ }
+ if utils.InterfaceSliceContains(options, a) {
+ t.Fatal("enemy units contain own archer")
+ }
+
+ desc = newTargetDesc("allied unit")
+ // Use a dummy pass action to pass the player to the target constraints
+ target = newTarget(s, desc, NewPassPriority(p))
+ options = target.Options()
+ if utils.InterfaceSliceContains(options, oa) {
+ t.Fatal("'allied units' does contain opponent's archer")
+ }
+ if !utils.InterfaceSliceContains(options, a) {
+ t.Fatal("'allied units' does not contain own archer")
+ }
+
+ // Test for controlled units
+ oa.changeController(p)
+ desc = newTargetDesc("unit you control")
+ target = newTarget(s, desc, NewPassPriority(p))
+ options = target.Options()
+ if !utils.InterfaceSliceContains(options, oa) {
+ t.Fatal("'units you control' does not contain controlled archer owned by the oponent")
+ }
+ if !utils.InterfaceSliceContains(options, a) {
+ t.Fatal("'units you control' does not contain own archer")
+ }
+}