Skip to content

Commit b79cc5e

Browse files
committed
dnd-character: fixes
- Fixed tests. - Added new contributor.
1 parent 03ca68c commit b79cc5e

File tree

3 files changed

+191
-26
lines changed

3 files changed

+191
-26
lines changed

exercises/practice/dnd-character/.meta/config.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
"authors": [
33
"SimaDovakin"
44
],
5+
"contributors": [
6+
"rlmark"
7+
],
58
"files": {
69
"solution": [
710
"dndCharacter.u"
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
[
2+
{
3+
"test_code": "input = 18\n expected = 4\n label \"computes the modifier for 18 to be 4\" <| expect (expected == modifier input)",
4+
"name": "dndCharacter.test.testModifier.ex1"
5+
},
6+
{
7+
"test_code": "input = 17\n expected = 3\n label \"computes the modifier for 17 to be 3\" <| expect (expected == modifier input)",
8+
"name": "dndCharacter.test.testModifier.ex2"
9+
},
10+
{
11+
"test_code": "input = 16\n expected = 3\n label \"computes the modifier for 16 to be 3\" <| expect (expected == modifier input)",
12+
"name": "dndCharacter.test.testModifier.ex3"
13+
},
14+
{
15+
"test_code": "input = 15\n expected = 2\n label \"computes the modifier for 15 to be 2\" <| expect (expected == modifier input)",
16+
"name": "dndCharacter.test.testModifier.ex4"
17+
},
18+
{
19+
"test_code": "input = 14\n expected = 2\n label \"computes the modifier for 14 to be 2\" <| expect (expected == modifier input)",
20+
"name": "dndCharacter.test.testModifier.ex5"
21+
},
22+
{
23+
"test_code": "input = 13\n expected = 1\n label \"computes the modifier for 13 to be 1\" <| expect (expected == modifier input)",
24+
"name": "dndCharacter.test.testModifier.ex6"
25+
},
26+
{
27+
"test_code": "input = 12\n expected = 1\n label \"computes the modifier for 12 to be 1\" <| expect (expected == modifier input)",
28+
"name": "dndCharacter.test.testModifier.ex7"
29+
},
30+
{
31+
"test_code": "input = 11\n expected = 0\n label \"computes the modifier for 11 to be 0\" <| expect (expected == modifier input)",
32+
"name": "dndCharacter.test.testModifier.ex8"
33+
},
34+
{
35+
"test_code": "input = 10\n expected = 0\n label \"computes the modifier for 10 to be 0\" <| expect (expected == modifier input)",
36+
"name": "dndCharacter.test.testModifier.ex9"
37+
},
38+
{
39+
"test_code": "input = 9\n expected = -1\n label \"computes the modifier for 9 to be -1\" <| expect (expected == modifier input)",
40+
"name": "dndCharacter.test.testModifier.ex10"
41+
},
42+
{
43+
"test_code": "input = 8\n expected = -1\n label \"computes the modifier for 8 to be -1\" <| expect (expected == modifier input)",
44+
"name": "dndCharacter.test.testModifier.ex11"
45+
},
46+
{
47+
"test_code": "input = 7\n expected = -2\n label \"computes the modifier for 7 to be -2\" <| expect (expected == modifier input)",
48+
"name": "dndCharacter.test.testModifier.ex12"
49+
},
50+
{
51+
"test_code": "input = 6\n expected = -2\n label \"computes the modifier for 6 to be -2\" <| expect (expected == modifier input)",
52+
"name": "dndCharacter.test.testModifier.ex13"
53+
},
54+
{
55+
"test_code": "input = 5\n expected = -3\n label \"computes the modifier for 5 to be -3\" <| expect (expected == modifier input)",
56+
"name": "dndCharacter.test.testModifier.ex14"
57+
},
58+
{
59+
"test_code": "input = 4\n expected = -3\n label \"computes the modifier for 4 to be -3\" <| expect (expected == modifier input)",
60+
"name": "dndCharacter.test.testModifier.ex15"
61+
},
62+
{
63+
"test_code": "input = 3\n expected = -4\n label \"computes the modifier for 3 to be -4\" <| expect (expected == modifier input)",
64+
"name": "dndCharacter.test.testModifier.ex16"
65+
},
66+
{
67+
"test_code": "do\n seed = !nat\n calculatedAbility = Random.lcg seed ability_\n label \"generates value within range\" <| expect (Nat.inRange 3 19 calculatedAbility)\n",
68+
"name": "dndCharacter.test.testAbility"
69+
},
70+
{
71+
"test_code": "do\n seed = !nat\n (Character strength dexterity constitution intelligence wisdom charisma hitpoints) = Random.lcg seed character\n expectedHitpoints = Int.abs (+10 Int.+ modifier constitution)\n 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)\n ) |> label \"generates valid character\"",
72+
"name": "dndCharacter.test.testCharacter"
73+
}
74+
]
Lines changed: 114 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,115 @@
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
1892
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

Comments
 (0)