Skip to content

Commit

Permalink
More tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikSchierboom committed Jan 22, 2025
1 parent 150a2d6 commit dd7e98e
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 74 deletions.
1 change: 0 additions & 1 deletion exercises/practice/dnd-character/.meta/generator.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
(fn [ability]
(-> test-case
(update :path #(conj % (name ability)))
(assoc :once (= (:description test-case) "each ability is only calculated once"))
(assoc :ability (safe-str (str ability))))) random-abilities))

(defn- expand-test-case [test-case]
Expand Down
15 changes: 6 additions & 9 deletions exercises/practice/dnd-character/.meta/generator.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

(deftest rand-ability_test_1
(testing "random ability is within range"
(is (<= 3 (dnd-character/rand-ability) 18))))
(dotimes [_ 100]
(is (<= 3 (dnd-character/rand-ability) 18)))))

(deftest rand-ability_test_2
(testing "ability is generated randomly"
Expand All @@ -19,20 +20,16 @@
{{#test_cases.character}}
(deftest rand-character_test_{{idx}}
(testing {{description}}
{{#if once ~}}
(let [character (dnd-character/rand-character)]
(is (= ({{ability}} character) ({{ability}} character))))))
{{else~}}
(is (<= 3 ({{ability}} (dnd-character/rand-character)) 18))))
{{/if~}}
(dotimes [_ 100]
(is (<= 3 ({{ability}} (dnd-character/rand-character)) 18)))))
{{/test_cases.character}}

(deftest rand-character_test_13
(deftest rand-character_test_7
(testing "random character is valid ▶ hitpoints"
(let [character (dnd-character/rand-character)
expected (+ 10 (dnd-character/score-modifier (:constitution character)))]
(is (= expected (:hitpoints character))))))

(deftest rand-character_test_14
(deftest rand-character_test_8
(testing "random character is generated randomly"
(is (>= (count (set (repeatedly 100 #(dnd-character/rand-character)))) 5))))
1 change: 1 addition & 0 deletions exercises/practice/dnd-character/.meta/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,4 @@ include = false
[dca2b2ec-f729-4551-84b9-078876bb4808]
description = "each ability is only calculated once"
reimplements = "2ca77b9b-c099-46c3-a02c-0d0f68ffa0fe"
include = false
105 changes: 41 additions & 64 deletions exercises/practice/dnd-character/test/dnd_character_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,138 +2,115 @@
(:require [clojure.test :refer [deftest testing is]]
dnd-character))

(deftest modifier_test_1
(deftest score-modifier_test_1
(testing "ability modifier for score 3 is -4"
(is (= -4 (dnd-character/score-modifier 3)))))

(deftest modifier_test_2
(deftest score-modifier_test_2
(testing "ability modifier for score 4 is -3"
(is (= -3 (dnd-character/score-modifier 4)))))

(deftest modifier_test_3
(deftest score-modifier_test_3
(testing "ability modifier for score 5 is -3"
(is (= -3 (dnd-character/score-modifier 5)))))

(deftest modifier_test_4
(deftest score-modifier_test_4
(testing "ability modifier for score 6 is -2"
(is (= -2 (dnd-character/score-modifier 6)))))

(deftest modifier_test_5
(deftest score-modifier_test_5
(testing "ability modifier for score 7 is -2"
(is (= -2 (dnd-character/score-modifier 7)))))

(deftest modifier_test_6
(deftest score-modifier_test_6
(testing "ability modifier for score 8 is -1"
(is (= -1 (dnd-character/score-modifier 8)))))

(deftest modifier_test_7
(deftest score-modifier_test_7
(testing "ability modifier for score 9 is -1"
(is (= -1 (dnd-character/score-modifier 9)))))

(deftest modifier_test_8
(deftest score-modifier_test_8
(testing "ability modifier for score 10 is 0"
(is (= 0 (dnd-character/score-modifier 10)))))

(deftest modifier_test_9
(deftest score-modifier_test_9
(testing "ability modifier for score 11 is 0"
(is (= 0 (dnd-character/score-modifier 11)))))

(deftest modifier_test_10
(deftest score-modifier_test_10
(testing "ability modifier for score 12 is +1"
(is (= 1 (dnd-character/score-modifier 12)))))

(deftest modifier_test_11
(deftest score-modifier_test_11
(testing "ability modifier for score 13 is +1"
(is (= 1 (dnd-character/score-modifier 13)))))

(deftest modifier_test_12
(deftest score-modifier_test_12
(testing "ability modifier for score 14 is +2"
(is (= 2 (dnd-character/score-modifier 14)))))

(deftest modifier_test_13
(deftest score-modifier_test_13
(testing "ability modifier for score 15 is +2"
(is (= 2 (dnd-character/score-modifier 15)))))

(deftest modifier_test_14
(deftest score-modifier_test_14
(testing "ability modifier for score 16 is +3"
(is (= 3 (dnd-character/score-modifier 16)))))

(deftest modifier_test_15
(deftest score-modifier_test_15
(testing "ability modifier for score 17 is +3"
(is (= 3 (dnd-character/score-modifier 17)))))

(deftest modifier_test_16
(deftest score-modifier_test_16
(testing "ability modifier for score 18 is +4"
(is (= 4 (dnd-character/score-modifier 18)))))

(deftest ability_test_1
(deftest rand-ability_test_1
(testing "random ability is within range"
(is (<= 3 (dnd-character/rand-ability) 18))))
(dotimes [_ 100]
(is (<= 3 (dnd-character/rand-ability) 18)))))

(deftest ability_test_2
(deftest rand-ability_test_2
(testing "ability is generated randomly"
(is (>= (count (set (repeatedly 100 #(dnd-character/rand-ability)))) 5))))

(deftest character_test_1
(deftest rand-character_test_1
(testing "random character is valid ▶ strength"
(is (<= 3 (:strength (dnd-character/rand-character)) 18))))
(dotimes [_ 100]
(is (<= 3 (:strength (dnd-character/rand-character)) 18)))))

(deftest character_test_2
(deftest rand-character_test_2
(testing "random character is valid ▶ dexterity"
(is (<= 3 (:dexterity (dnd-character/rand-character)) 18))))
(dotimes [_ 100]
(is (<= 3 (:dexterity (dnd-character/rand-character)) 18)))))

(deftest character_test_3
(deftest rand-character_test_3
(testing "random character is valid ▶ charisma"
(is (<= 3 (:charisma (dnd-character/rand-character)) 18))))
(dotimes [_ 100]
(is (<= 3 (:charisma (dnd-character/rand-character)) 18)))))

(deftest character_test_4
(deftest rand-character_test_4
(testing "random character is valid ▶ wisdom"
(is (<= 3 (:wisdom (dnd-character/rand-character)) 18))))
(dotimes [_ 100]
(is (<= 3 (:wisdom (dnd-character/rand-character)) 18)))))

(deftest character_test_5
(deftest rand-character_test_5
(testing "random character is valid ▶ intelligence"
(is (<= 3 (:intelligence (dnd-character/rand-character)) 18))))
(dotimes [_ 100]
(is (<= 3 (:intelligence (dnd-character/rand-character)) 18)))))

(deftest character_test_6
(deftest rand-character_test_6
(testing "random character is valid ▶ constitution"
(is (<= 3 (:constitution (dnd-character/rand-character)) 18))))

(deftest character_test_7
(testing "each ability is only calculated once ▶ strength"
(let [character (dnd-character/rand-character)]
(is (= (:strength character) (:strength character))))))

(deftest character_test_8
(testing "each ability is only calculated once ▶ dexterity"
(let [character (dnd-character/rand-character)]
(is (= (:dexterity character) (:dexterity character))))))

(deftest character_test_9
(testing "each ability is only calculated once ▶ charisma"
(let [character (dnd-character/rand-character)]
(is (= (:charisma character) (:charisma character))))))

(deftest character_test_10
(testing "each ability is only calculated once ▶ wisdom"
(let [character (dnd-character/rand-character)]
(is (= (:wisdom character) (:wisdom character))))))

(deftest character_test_11
(testing "each ability is only calculated once ▶ intelligence"
(let [character (dnd-character/rand-character)]
(is (= (:intelligence character) (:intelligence character))))))

(deftest character_test_12
(testing "each ability is only calculated once ▶ constitution"
(let [character (dnd-character/rand-character)]
(is (= (:constitution character) (:constitution character))))))

(deftest character_test_13
(dotimes [_ 100]
(is (<= 3 (:constitution (dnd-character/rand-character)) 18)))))

(deftest rand-character_test_7
(testing "random character is valid ▶ hitpoints"
(let [character (dnd-character/rand-character)
expected (+ 10 (dnd-character/score-modifier (:constitution character)))]
(is (= expected (:hitpoints character))))))

(deftest character_test_14
(deftest rand-character_test_8
(testing "random character is generated randomly"
(is (>= (count (set (repeatedly 100 #(dnd-character/rand-character)))) 5))))

0 comments on commit dd7e98e

Please sign in to comment.