Skip to content

Commit

Permalink
dnd-character: fixes
Browse files Browse the repository at this point in the history
- Fixed tests.
- Added new contributor.
  • Loading branch information
SimaDovakin committed Apr 17, 2024
1 parent 03ca68c commit b79cc5e
Show file tree
Hide file tree
Showing 3 changed files with 191 additions and 26 deletions.
3 changes: 3 additions & 0 deletions exercises/practice/dnd-character/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"authors": [
"SimaDovakin"
],
"contributors": [
"rlmark"
],
"files": {
"solution": [
"dndCharacter.u"
Expand Down
74 changes: 74 additions & 0 deletions exercises/practice/dnd-character/.meta/testAnnotation.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
[
{
"test_code": "input = 18\n expected = 4\n label \"computes the modifier for 18 to be 4\" <| expect (expected == modifier input)",
"name": "dndCharacter.test.testModifier.ex1"
},
{
"test_code": "input = 17\n expected = 3\n label \"computes the modifier for 17 to be 3\" <| expect (expected == modifier input)",
"name": "dndCharacter.test.testModifier.ex2"
},
{
"test_code": "input = 16\n expected = 3\n label \"computes the modifier for 16 to be 3\" <| expect (expected == modifier input)",
"name": "dndCharacter.test.testModifier.ex3"
},
{
"test_code": "input = 15\n expected = 2\n label \"computes the modifier for 15 to be 2\" <| expect (expected == modifier input)",
"name": "dndCharacter.test.testModifier.ex4"
},
{
"test_code": "input = 14\n expected = 2\n label \"computes the modifier for 14 to be 2\" <| expect (expected == modifier input)",
"name": "dndCharacter.test.testModifier.ex5"
},
{
"test_code": "input = 13\n expected = 1\n label \"computes the modifier for 13 to be 1\" <| expect (expected == modifier input)",
"name": "dndCharacter.test.testModifier.ex6"
},
{
"test_code": "input = 12\n expected = 1\n label \"computes the modifier for 12 to be 1\" <| expect (expected == modifier input)",
"name": "dndCharacter.test.testModifier.ex7"
},
{
"test_code": "input = 11\n expected = 0\n label \"computes the modifier for 11 to be 0\" <| expect (expected == modifier input)",
"name": "dndCharacter.test.testModifier.ex8"
},
{
"test_code": "input = 10\n expected = 0\n label \"computes the modifier for 10 to be 0\" <| expect (expected == modifier input)",
"name": "dndCharacter.test.testModifier.ex9"
},
{
"test_code": "input = 9\n expected = -1\n label \"computes the modifier for 9 to be -1\" <| expect (expected == modifier input)",
"name": "dndCharacter.test.testModifier.ex10"
},
{
"test_code": "input = 8\n expected = -1\n label \"computes the modifier for 8 to be -1\" <| expect (expected == modifier input)",
"name": "dndCharacter.test.testModifier.ex11"
},
{
"test_code": "input = 7\n expected = -2\n label \"computes the modifier for 7 to be -2\" <| expect (expected == modifier input)",
"name": "dndCharacter.test.testModifier.ex12"
},
{
"test_code": "input = 6\n expected = -2\n label \"computes the modifier for 6 to be -2\" <| expect (expected == modifier input)",
"name": "dndCharacter.test.testModifier.ex13"
},
{
"test_code": "input = 5\n expected = -3\n label \"computes the modifier for 5 to be -3\" <| expect (expected == modifier input)",
"name": "dndCharacter.test.testModifier.ex14"
},
{
"test_code": "input = 4\n expected = -3\n label \"computes the modifier for 4 to be -3\" <| expect (expected == modifier input)",
"name": "dndCharacter.test.testModifier.ex15"
},
{
"test_code": "input = 3\n expected = -4\n label \"computes the modifier for 3 to be -4\" <| expect (expected == modifier input)",
"name": "dndCharacter.test.testModifier.ex16"
},
{
"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",
"name": "dndCharacter.test.testAbility"
},
{
"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\"",
"name": "dndCharacter.test.testCharacter"
}
]
140 changes: 114 additions & 26 deletions exercises/practice/dnd-character/dndCharacter.test.u
Original file line number Diff line number Diff line change
@@ -1,27 +1,115 @@
test> dndCharacter.tests.testModifier = verify do
testCases = [ (18, +4), (17, +3), (16, +3), (15, +2), (14, +2)
, (13, +1), (12, +1), (11, +0), (10, +0), (9, -1)
, (8, -1), (7, -2), (6, -2), (5, -3), (4, -3)
, (3, -4) ]
checkCase : (Nat, Int) -> Boolean
checkCase testCase =
(input, expected) = testCase
expected == modifier input
ensure (List.all checkCase testCases)

test> dndCharacter.tests.testAbility = verify do
calculatedAbility = !ability_
ensure (Nat.inRange 3 19 calculatedAbility)

test> dndCharacter.tests.testCharacter = verify do
(Character strength dexterity constitution intelligence wisdom charisma hitpoints) = !character
use base.test.gen

dndCharacter.test.testModifier.ex1 =
input = 18
expected = +4
label "computes the modifier for 18 to be 4" <| expect (expected == modifier input)

dndCharacter.test.testModifier.ex2 =
input = 17
expected = +3
label "computes the modifier for 17 to be 3" <| expect (expected == modifier input)

dndCharacter.test.testModifier.ex3 =
input = 16
expected = +3
label "computes the modifier for 16 to be 3" <| expect (expected == modifier input)

dndCharacter.test.testModifier.ex4 =
input = 15
expected = +2
label "computes the modifier for 15 to be 2" <| expect (expected == modifier input)

dndCharacter.test.testModifier.ex5 =
input = 14
expected = +2
label "computes the modifier for 14 to be 2" <| expect (expected == modifier input)

dndCharacter.test.testModifier.ex6 =
input = 13
expected = +1
label "computes the modifier for 13 to be 1" <| expect (expected == modifier input)

dndCharacter.test.testModifier.ex7 =
input = 12
expected = +1
label "computes the modifier for 12 to be 1" <| expect (expected == modifier input)

dndCharacter.test.testModifier.ex8 =
input = 11
expected = +0
label "computes the modifier for 11 to be 0" <| expect (expected == modifier input)

dndCharacter.test.testModifier.ex9 =
input = 10
expected = +0
label "computes the modifier for 10 to be 0" <| expect (expected == modifier input)

dndCharacter.test.testModifier.ex10 =
input = 9
expected = -1
label "computes the modifier for 9 to be -1" <| expect (expected == modifier input)

dndCharacter.test.testModifier.ex11 =
input = 8
expected = -1
label "computes the modifier for 8 to be -1" <| expect (expected == modifier input)

dndCharacter.test.testModifier.ex12 =
input = 7
expected = -2
label "computes the modifier for 7 to be -2" <| expect (expected == modifier input)

dndCharacter.test.testModifier.ex13 =
input = 6
expected = -2
label "computes the modifier for 6 to be -2" <| expect (expected == modifier input)

dndCharacter.test.testModifier.ex14 =
input = 5
expected = -3
label "computes the modifier for 5 to be -3" <| expect (expected == modifier input)

dndCharacter.test.testModifier.ex15 =
input = 4
expected = -3
label "computes the modifier for 4 to be -3" <| expect (expected == modifier input)

dndCharacter.test.testModifier.ex16 =
input = 3
expected = -4
label "computes the modifier for 3 to be -4" <| expect (expected == modifier input)


dndCharacter.test.testAbility = do
seed = !nat
calculatedAbility = Random.lcg seed ability_
label "generates value within range" <| expect (Nat.inRange 3 19 calculatedAbility)

dndCharacter.test.testCharacter = do
seed = !nat
(Character strength dexterity constitution intelligence wisdom charisma hitpoints) = Random.lcg seed character
expectedHitpoints = Int.abs (+10 Int.+ modifier constitution)
ensure (
(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)
)
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)
) |> label "generates valid character"

test> dndCharacter.tests =
[ runs 10 dndCharacter.test.testAbility
, runs 10 dndCharacter.test.testCharacter
, Test.run dndCharacter.test.testModifier.ex1
, Test.run dndCharacter.test.testModifier.ex2
, Test.run dndCharacter.test.testModifier.ex3
, Test.run dndCharacter.test.testModifier.ex4
, Test.run dndCharacter.test.testModifier.ex5
, Test.run dndCharacter.test.testModifier.ex6
, Test.run dndCharacter.test.testModifier.ex7
, Test.run dndCharacter.test.testModifier.ex8
, Test.run dndCharacter.test.testModifier.ex9
, Test.run dndCharacter.test.testModifier.ex10
, Test.run dndCharacter.test.testModifier.ex11
, Test.run dndCharacter.test.testModifier.ex12
, Test.run dndCharacter.test.testModifier.ex13
, Test.run dndCharacter.test.testModifier.ex14
, Test.run dndCharacter.test.testModifier.ex15
, Test.run dndCharacter.test.testModifier.ex16
] |> List.join

0 comments on commit b79cc5e

Please sign in to comment.