|
1 |
| -test> dndCharacter.tests.testModifier = verify do |
2 |
| - testCases = [ (18, +4), (17, +3), (16, +3), (15, +2), (14, +2) |
3 |
| - , (13, +1), (12, +1), (11, +0), (10, +0), (9, -1) |
4 |
| - , (8, -1), (7, -2), (6, -2), (5, -3), (4, -3) |
5 |
| - , (3, -4) ] |
6 |
| - checkCase : (Nat, Int) -> Boolean |
7 |
| - checkCase testCase = |
8 |
| - (input, expected) = testCase |
9 |
| - expected == modifier input |
10 |
| - ensure (List.all checkCase testCases) |
11 |
| - |
12 |
| -test> dndCharacter.tests.testAbility = verify do |
13 |
| - calculatedAbility = !ability_ |
14 |
| - ensure (Nat.inRange 3 19 calculatedAbility) |
15 |
| - |
16 |
| -test> dndCharacter.tests.testCharacter = verify do |
17 |
| - (Character strength dexterity constitution intelligence wisdom charisma hitpoints) = !character |
| 1 | +use base.test.gen |
| 2 | + |
| 3 | +dndCharacter.test.testModifier.ex1 = |
| 4 | + input = 18 |
| 5 | + expected = +4 |
| 6 | + label "computes the modifier for 18 to be 4" <| expect (expected == modifier input) |
| 7 | + |
| 8 | +dndCharacter.test.testModifier.ex2 = |
| 9 | + input = 17 |
| 10 | + expected = +3 |
| 11 | + label "computes the modifier for 17 to be 3" <| expect (expected == modifier input) |
| 12 | + |
| 13 | +dndCharacter.test.testModifier.ex3 = |
| 14 | + input = 16 |
| 15 | + expected = +3 |
| 16 | + label "computes the modifier for 16 to be 3" <| expect (expected == modifier input) |
| 17 | + |
| 18 | +dndCharacter.test.testModifier.ex4 = |
| 19 | + input = 15 |
| 20 | + expected = +2 |
| 21 | + label "computes the modifier for 15 to be 2" <| expect (expected == modifier input) |
| 22 | + |
| 23 | +dndCharacter.test.testModifier.ex5 = |
| 24 | + input = 14 |
| 25 | + expected = +2 |
| 26 | + label "computes the modifier for 14 to be 2" <| expect (expected == modifier input) |
| 27 | + |
| 28 | +dndCharacter.test.testModifier.ex6 = |
| 29 | + input = 13 |
| 30 | + expected = +1 |
| 31 | + label "computes the modifier for 13 to be 1" <| expect (expected == modifier input) |
| 32 | + |
| 33 | +dndCharacter.test.testModifier.ex7 = |
| 34 | + input = 12 |
| 35 | + expected = +1 |
| 36 | + label "computes the modifier for 12 to be 1" <| expect (expected == modifier input) |
| 37 | + |
| 38 | +dndCharacter.test.testModifier.ex8 = |
| 39 | + input = 11 |
| 40 | + expected = +0 |
| 41 | + label "computes the modifier for 11 to be 0" <| expect (expected == modifier input) |
| 42 | + |
| 43 | +dndCharacter.test.testModifier.ex9 = |
| 44 | + input = 10 |
| 45 | + expected = +0 |
| 46 | + label "computes the modifier for 10 to be 0" <| expect (expected == modifier input) |
| 47 | + |
| 48 | +dndCharacter.test.testModifier.ex10 = |
| 49 | + input = 9 |
| 50 | + expected = -1 |
| 51 | + label "computes the modifier for 9 to be -1" <| expect (expected == modifier input) |
| 52 | + |
| 53 | +dndCharacter.test.testModifier.ex11 = |
| 54 | + input = 8 |
| 55 | + expected = -1 |
| 56 | + label "computes the modifier for 8 to be -1" <| expect (expected == modifier input) |
| 57 | + |
| 58 | +dndCharacter.test.testModifier.ex12 = |
| 59 | + input = 7 |
| 60 | + expected = -2 |
| 61 | + label "computes the modifier for 7 to be -2" <| expect (expected == modifier input) |
| 62 | + |
| 63 | +dndCharacter.test.testModifier.ex13 = |
| 64 | + input = 6 |
| 65 | + expected = -2 |
| 66 | + label "computes the modifier for 6 to be -2" <| expect (expected == modifier input) |
| 67 | + |
| 68 | +dndCharacter.test.testModifier.ex14 = |
| 69 | + input = 5 |
| 70 | + expected = -3 |
| 71 | + label "computes the modifier for 5 to be -3" <| expect (expected == modifier input) |
| 72 | + |
| 73 | +dndCharacter.test.testModifier.ex15 = |
| 74 | + input = 4 |
| 75 | + expected = -3 |
| 76 | + label "computes the modifier for 4 to be -3" <| expect (expected == modifier input) |
| 77 | + |
| 78 | +dndCharacter.test.testModifier.ex16 = |
| 79 | + input = 3 |
| 80 | + expected = -4 |
| 81 | + label "computes the modifier for 3 to be -4" <| expect (expected == modifier input) |
| 82 | + |
| 83 | + |
| 84 | +dndCharacter.test.testAbility = do |
| 85 | + seed = !nat |
| 86 | + calculatedAbility = Random.lcg seed ability_ |
| 87 | + label "generates value within range" <| expect (Nat.inRange 3 19 calculatedAbility) |
| 88 | + |
| 89 | +dndCharacter.test.testCharacter = do |
| 90 | + seed = !nat |
| 91 | + (Character strength dexterity constitution intelligence wisdom charisma hitpoints) = Random.lcg seed character |
18 | 92 | expectedHitpoints = Int.abs (+10 Int.+ modifier constitution)
|
19 |
| - ensure ( |
20 |
| - (Nat.inRange 3 19 strength) && |
21 |
| - (Nat.inRange 3 19 dexterity) && |
22 |
| - (Nat.inRange 3 19 constitution) && |
23 |
| - (Nat.inRange 3 19 intelligence) && |
24 |
| - (Nat.inRange 3 19 wisdom) && |
25 |
| - (Nat.inRange 3 19 charisma) && |
26 |
| - (hitpoints == expectedHitpoints) |
27 |
| - ) |
| 93 | + expect ((Nat.inRange 3 19 strength) && (Nat.inRange 3 19 dexterity) && (Nat.inRange 3 19 constitution) && (Nat.inRange 3 19 intelligence) && (Nat.inRange 3 19 wisdom) && (Nat.inRange 3 19 charisma) && (hitpoints == expectedHitpoints) |
| 94 | + ) |> label "generates valid character" |
| 95 | + |
| 96 | +test> dndCharacter.tests = |
| 97 | + [ runs 10 dndCharacter.test.testAbility |
| 98 | + , runs 10 dndCharacter.test.testCharacter |
| 99 | + , Test.run dndCharacter.test.testModifier.ex1 |
| 100 | + , Test.run dndCharacter.test.testModifier.ex2 |
| 101 | + , Test.run dndCharacter.test.testModifier.ex3 |
| 102 | + , Test.run dndCharacter.test.testModifier.ex4 |
| 103 | + , Test.run dndCharacter.test.testModifier.ex5 |
| 104 | + , Test.run dndCharacter.test.testModifier.ex6 |
| 105 | + , Test.run dndCharacter.test.testModifier.ex7 |
| 106 | + , Test.run dndCharacter.test.testModifier.ex8 |
| 107 | + , Test.run dndCharacter.test.testModifier.ex9 |
| 108 | + , Test.run dndCharacter.test.testModifier.ex10 |
| 109 | + , Test.run dndCharacter.test.testModifier.ex11 |
| 110 | + , Test.run dndCharacter.test.testModifier.ex12 |
| 111 | + , Test.run dndCharacter.test.testModifier.ex13 |
| 112 | + , Test.run dndCharacter.test.testModifier.ex14 |
| 113 | + , Test.run dndCharacter.test.testModifier.ex15 |
| 114 | + , Test.run dndCharacter.test.testModifier.ex16 |
| 115 | + ] |> List.join |
0 commit comments