From dd7e98e4ab3a4be5fd38423bb97d0f0dd61b462b Mon Sep 17 00:00:00 2001 From: Erik Schierboom Date: Wed, 22 Jan 2025 15:41:34 +0100 Subject: [PATCH] More tweaks --- .../dnd-character/.meta/generator.clj | 1 - .../dnd-character/.meta/generator.tpl | 15 +-- .../practice/dnd-character/.meta/tests.toml | 1 + .../dnd-character/test/dnd_character_test.clj | 105 +++++++----------- 4 files changed, 48 insertions(+), 74 deletions(-) diff --git a/exercises/practice/dnd-character/.meta/generator.clj b/exercises/practice/dnd-character/.meta/generator.clj index cf0c60e01..4c573622a 100644 --- a/exercises/practice/dnd-character/.meta/generator.clj +++ b/exercises/practice/dnd-character/.meta/generator.clj @@ -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] diff --git a/exercises/practice/dnd-character/.meta/generator.tpl b/exercises/practice/dnd-character/.meta/generator.tpl index 1c0ea1399..758d35d77 100644 --- a/exercises/practice/dnd-character/.meta/generator.tpl +++ b/exercises/practice/dnd-character/.meta/generator.tpl @@ -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" @@ -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)))) diff --git a/exercises/practice/dnd-character/.meta/tests.toml b/exercises/practice/dnd-character/.meta/tests.toml index 719043b25..44b3c20e0 100644 --- a/exercises/practice/dnd-character/.meta/tests.toml +++ b/exercises/practice/dnd-character/.meta/tests.toml @@ -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 diff --git a/exercises/practice/dnd-character/test/dnd_character_test.clj b/exercises/practice/dnd-character/test/dnd_character_test.clj index 2a6c3a3a0..af5e81ff4 100644 --- a/exercises/practice/dnd-character/test/dnd_character_test.clj +++ b/exercises/practice/dnd-character/test/dnd_character_test.clj @@ -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)))) \ No newline at end of file