Skip to content

Commit 4e43ef7

Browse files
committed
Add test that attack at distance 2 with range 1 doesn't work
1 parent 8b29d89 commit 4e43ef7

File tree

1 file changed

+85
-3
lines changed

1 file changed

+85
-3
lines changed

tests/Data/Fight/GeneratorTest.elm

Lines changed: 85 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module Data.Fight.GeneratorTest exposing (suite)
22

3-
import Data.Fight as Fight exposing (Action, Opponent, Who)
3+
import Data.Fight as Fight exposing (Opponent)
44
import Data.Fight.AttackStyle as AttackStyle
55
import Data.Fight.Generator exposing (Fight)
66
import Data.FightStrategy exposing (..)
@@ -15,14 +15,14 @@ import SeqDict
1515
import SeqSet
1616
import Test exposing (Test)
1717
import TestHelpers exposing (..)
18-
import Time
1918

2019

2120
suite : Test
2221
suite =
2322
Test.describe "Data.Fight.Generator"
2423
[ damageNeverNegative
2524
, meleeAttackAtDistance2WithRange2
25+
, meleeAttackAtDistance2WithRange1
2626
]
2727

2828

@@ -53,7 +53,25 @@ meleeAttackAtDistance2WithRange2 =
5353
\() ->
5454
let
5555
opponent =
56-
{ type_ = Fight.Player { name = "Opponent", xp = 0 }, hp = 100, maxHp = 100, maxAp = 10, sequence = 5, traits = SeqSet.empty, perks = SeqDict.empty, caps = 50, items = Dict.empty, drops = [], equippedArmor = Nothing, equippedWeapon = Just Item.SuperSledge, equippedAmmo = Nothing, naturalArmorClass = 5, attackStats = Logic.unarmedAttackStats { special = Special.init, unarmedSkill = 50, traits = SeqSet.empty, perks = SeqDict.empty, level = 1, npcExtraBonus = 0 }, addedSkillPercentages = SeqDict.empty, special = Special.init, fightStrategy = strategy }
56+
{ type_ = Fight.Player { name = "Opponent", xp = 0 }
57+
, hp = 100
58+
, maxHp = 100
59+
, maxAp = 10
60+
, sequence = 5
61+
, traits = SeqSet.empty
62+
, perks = SeqDict.empty
63+
, caps = 50
64+
, items = Dict.empty
65+
, drops = []
66+
, equippedArmor = Nothing
67+
, equippedWeapon = Just Item.SuperSledge
68+
, equippedAmmo = Nothing
69+
, naturalArmorClass = 5
70+
, attackStats = Logic.unarmedAttackStats { special = Special.init, unarmedSkill = 50, traits = SeqSet.empty, perks = SeqDict.empty, level = 1, npcExtraBonus = 0 }
71+
, addedSkillPercentages = SeqDict.empty
72+
, special = Special.init
73+
, fightStrategy = strategy
74+
}
5775

5876
result =
5977
Random.step
@@ -80,6 +98,70 @@ meleeAttackAtDistance2WithRange2 =
8098
|> Expect.onFail "Expected the attack to succeed"
8199

82100

101+
meleeAttackAtDistance2WithRange1 : Test
102+
meleeAttackAtDistance2WithRange1 =
103+
let
104+
strategy : FightStrategy
105+
strategy =
106+
If
107+
{ condition = Operator { lhs = Distance, op = GT_, rhs = Number 2 }
108+
, then_ = Command MoveForward
109+
, else_ = Command AttackRandomly
110+
}
111+
in
112+
Test.test "Melee combat at distance 2 with weapon with range 1 shouldn't work" <|
113+
\() ->
114+
let
115+
opponent =
116+
{ type_ =
117+
Fight.Player
118+
{ name = "Opponent"
119+
, xp = 0
120+
}
121+
, hp = 100
122+
, maxHp = 100
123+
, maxAp = 10
124+
, sequence = 5
125+
, traits = SeqSet.empty
126+
, perks = SeqDict.empty
127+
, caps = 50
128+
, items = Dict.empty
129+
, drops = []
130+
, equippedArmor = Nothing
131+
, equippedWeapon = Just Item.Wakizashi
132+
, equippedAmmo = Nothing
133+
, naturalArmorClass = 5
134+
, attackStats = Logic.unarmedAttackStats { special = Special.init, unarmedSkill = 50, traits = SeqSet.empty, perks = SeqDict.empty, level = 1, npcExtraBonus = 0 }
135+
, addedSkillPercentages = SeqDict.empty
136+
, special = Special.init
137+
, fightStrategy = strategy
138+
}
139+
140+
result =
141+
Random.step
142+
(Data.Fight.Generator.attack_
143+
Fight.Attacker
144+
{ distanceHexes = 2
145+
, attacker = opponent
146+
, attackerAp = 10
147+
, attackerItemsUsed = SeqDict.empty
148+
, target = opponent
149+
, targetAp = 10
150+
, targetItemsUsed = SeqDict.empty
151+
, reverseLog = []
152+
, actionsTaken = 0
153+
}
154+
AttackStyle.MeleeUnaimed
155+
4
156+
)
157+
(Random.initialSeed 3)
158+
|> Tuple.first
159+
in
160+
result.ranCommandSuccessfully
161+
|> Expect.equal False
162+
|> Expect.onFail "Expected the attack to fail"
163+
164+
83165
fightFuzzer :
84166
{ attacker : Fuzzer Opponent
85167
, target : Fuzzer Opponent

0 commit comments

Comments
 (0)