Skip to content

Commit

Permalink
Simplify templates (#765)
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikSchierboom authored Jan 15, 2025
1 parent e73ac8b commit 8a23f63
Show file tree
Hide file tree
Showing 19 changed files with 51 additions and 41 deletions.
4 changes: 2 additions & 2 deletions exercises/practice/anagram/.meta/generator.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
anagram))
{{#test_cases.findAnagrams}}
(deftest anagrams-for_test_{{idx}}
(testing {{string description}}
(testing {{description}}
(is (= {{expected}}
(anagram/anagrams-for {{string input.subject}} {{input.candidates}})))))
(anagram/anagrams-for {{input.subject}} {{input.candidates}})))))
{{/test_cases.findAnagrams~}}
2 changes: 1 addition & 1 deletion exercises/practice/armstrong-numbers/.meta/generator.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
armstrong-numbers))
{{#test_cases.isArmstrongNumber}}
(deftest armstrong?_test_{{idx}}
(testing "{{description}}"
(testing {{description}}
(is ({{#expected}}true?{{else}}false?{{/expected}} (armstrong-numbers/armstrong? {{input.number}})))))
{{/test_cases.isArmstrongNumber~}}
2 changes: 1 addition & 1 deletion exercises/practice/darts/.meta/generator.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
darts))
{{#test_cases.score}}
(deftest score_test_{{idx}}
(testing {{string description}}
(testing {{description}}
(is (= {{expected}} (darts/score {{input.x}} {{input.y}})))))
{{/test_cases.score~}}
6 changes: 3 additions & 3 deletions exercises/practice/difference-of-squares/.meta/generator.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
difference-of-squares))
{{#test_cases.squareOfSum}}
(deftest square-of-sum_test_{{idx}}
(testing {{string description}}
(testing {{description}}
(is (= {{expected}} (difference-of-squares/square-of-sum {{input.number}})))))
{{/test_cases.squareOfSum~}}
{{#test_cases.sumOfSquares}}
(deftest sum-of-squares_test_{{idx}}
(testing {{string description}}
(testing {{description}}
(is (= {{expected}} (difference-of-squares/sum-of-squares {{input.number}})))))
{{/test_cases.sumOfSquares~}}
{{#test_cases.differenceOfSquares}}
(deftest difference_test_{{idx}}
(testing {{string description}}
(testing {{description}}
(is (= {{expected}} (difference-of-squares/difference {{input.number}})))))
{{/test_cases.differenceOfSquares~}}
6 changes: 6 additions & 0 deletions exercises/practice/high-scores/.meta/generator.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(ns high-scores-generator)

(defn- transform-test-case [test-case]
(-> test-case
(update-in [:input :scores] #(apply list %))
(update-in [:expected] #(if (vector? %) (apply list %) %))))
16 changes: 8 additions & 8 deletions exercises/practice/high-scores/.meta/generator.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
high-scores))
{{#test_cases.scores}}
(deftest scores_test_{{idx}}
(testing {{string description}}
(is (= {{list expected}} (high-scores/scores {{list input.scores}})))))
(testing {{description}}
(is (= {{expected}} (high-scores/scores {{input.scores}})))))
{{/test_cases.scores~}}
{{#test_cases.latest}}
(deftest latest_test_{{idx}}
(testing {{string description}}
(is (= {{expected}} (high-scores/latest {{list input.scores}})))))
(testing {{description}}
(is (= {{expected}} (high-scores/latest {{input.scores}})))))
{{/test_cases.latest~}}
{{#test_cases.personalBest}}
(deftest personal-best_test_{{idx}}
(testing {{string description}}
(is (= {{expected}} (high-scores/personal-best {{list input.scores}})))))
(testing {{description}}
(is (= {{expected}} (high-scores/personal-best {{input.scores}})))))
{{/test_cases.personalBest~}}
{{#test_cases.personalTopThree}}
(deftest personal-top-three_test_{{idx}}
(testing {{string description}}
(is (= {{list expected}} (high-scores/personal-top-three {{list input.scores}})))))
(testing {{description}}
(is (= {{expected}} (high-scores/personal-top-three {{input.scores}})))))
{{/test_cases.personalTopThree~}}
4 changes: 2 additions & 2 deletions exercises/practice/isbn-verifier/.meta/generator.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
isbn-verifier))
{{#test_cases.isValid}}
(deftest isbn?_test_{{idx}}
(testing {{string description}}
(is ({{#expected~}}true?{{else}}false?{{/expected}} (isbn-verifier/isbn? {{string input.isbn}})))))
(testing {{description}}
(is ({{#expected~}}true?{{else}}false?{{/expected}} (isbn-verifier/isbn? {{input.isbn}})))))
{{/test_cases.isValid~}}
4 changes: 2 additions & 2 deletions exercises/practice/isogram/.meta/generator.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
isogram))
{{#test_cases.isIsogram}}
(deftest isogram?_test_{{idx}}
(testing {{string description}}
(is ({{#expected~}}true?{{else}}false?{{/expected}} (isogram/isogram? {{string input.phrase}})))))
(testing {{description}}
(is ({{#expected~}}true?{{else}}false?{{/expected}} (isogram/isogram? {{input.phrase}})))))
{{/test_cases.isIsogram~}}
2 changes: 1 addition & 1 deletion exercises/practice/leap/.meta/generator.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
leap))
{{#test_cases.leapYear}}
(deftest leap-year?_test_{{idx}}
(testing "{{description}}"
(testing {{description}}
(is ({{#expected}}true?{{else}}false?{{/expected}} (leap/leap-year? {{input.year}})))))
{{/test_cases.leapYear~}}
8 changes: 4 additions & 4 deletions exercises/practice/matrix/.meta/generator.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
matrix))
{{#test_cases.row}}
(deftest get-row_test_{{idx}}
(testing {{string description}}
(is (= {{expected}} (matrix/get-row {{string input.string}} {{input.index}})))))
(testing {{description}}
(is (= {{expected}} (matrix/get-row {{input.string}} {{input.index}})))))
{{/test_cases.row~}}
{{#test_cases.column}}
(deftest get-column_test_{{idx}}
(testing {{string description}}
(is (= {{expected}} (matrix/get-column {{string input.string}} {{input.index}})))))
(testing {{description}}
(is (= {{expected}} (matrix/get-column {{input.string}} {{input.index}})))))
{{/test_cases.column~}}
4 changes: 2 additions & 2 deletions exercises/practice/pangram/.meta/generator.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
pangram))
{{#test_cases.isPangram}}
(deftest pangram?_test_{{idx}}
(testing {{string description}}
(is ({{#expected}}true?{{else}}false?{{/expected}} (pangram/pangram? {{string input.sentence}})))))
(testing {{description}}
(is ({{#expected}}true?{{else}}false?{{/expected}} (pangram/pangram? {{input.sentence}})))))
{{/test_cases.isPangram~}}
6 changes: 3 additions & 3 deletions exercises/practice/resistor-color/.meta/generator.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
resistor-color))
{{#test_cases.colors}}
(deftest colors_test_{{idx}}
(testing {{string description}}
(testing {{description}}
(is (= {{expected}}
resistor-color/colors))))
{{/test_cases.colors~}}
{{#test_cases.colorCode}}
(deftest color-code_test_{{idx}}
(testing {{string description}}
(is (= {{expected}} (resistor-color/color-code {{string input.color}})))))
(testing {{description}}
(is (= {{expected}} (resistor-color/color-code {{input.color}})))))
{{/test_cases.colorCode~}}
4 changes: 2 additions & 2 deletions exercises/practice/roman-numerals/.meta/generator.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
roman-numerals))
{{#test_cases.roman}}
(deftest numerals_test_{{idx}}
(testing {{string description}}
(is (= {{string expected}} (roman-numerals/numerals {{input.number}})))))
(testing {{description}}
(is (= {{expected}} (roman-numerals/numerals {{input.number}})))))
{{/test_cases.roman~}}
4 changes: 2 additions & 2 deletions exercises/practice/scrabble-score/.meta/generator.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
scrabble-score))
{{#test_cases.score}}
(deftest score-word_test_{{idx}}
(testing {{string description}}
(is (= {{expected}} (scrabble-score/score-word {{string input.word}})))))
(testing {{description}}
(is (= {{expected}} (scrabble-score/score-word {{input.word}})))))
{{/test_cases.score~}}
2 changes: 1 addition & 1 deletion exercises/practice/square-root/.meta/generator.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
square-root))
{{#test_cases.squareRoot}}
(deftest square-root_test_{{idx}}
(testing "{{description}}"
(testing {{description}}
(is (= {{expected}} (square-root/square-root {{input.radicand}})))))
{{/test_cases.squareRoot~}}
4 changes: 4 additions & 0 deletions exercises/practice/sum-of-multiples/.meta/generator.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(ns sum-of-multiples-generator)

(defn- transform-test-case [test-case]
(update-in test-case [:input :factors] #(apply list %)))
4 changes: 2 additions & 2 deletions exercises/practice/sum-of-multiples/.meta/generator.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
sum-of-multiples))
{{#test_cases.sum}}
(deftest sum-of-multiples_test_{{idx}}
(testing "{{description}}"
(is ({{#ifzero expected}}zero?{{else}}= {{expected}}{{/ifzero}} (sum-of-multiples/sum-of-multiples {{list input.factors}} {{input.limit}})))))
(testing {{description}}
(is ({{#ifzero expected}}zero?{{else}}= {{expected}}{{/ifzero}} (sum-of-multiples/sum-of-multiples {{input.factors}} {{input.limit}})))))
{{/test_cases.sum~}}
6 changes: 3 additions & 3 deletions exercises/practice/triangle/.meta/generator.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
triangle))
{{#test_cases.equilateral}}
(deftest equilateral?_test_{{idx}}
(testing "{{description}}"
(testing {{description}}
(is ({{#expected}}true?{{else}}false?{{/expected}} (triangle/equilateral? {{input.sides.0}} {{input.sides.1}} {{input.sides.2}})))))
{{/test_cases.equilateral~}}
{{#test_cases.isosceles}}
(deftest isosceles?_test_{{idx}}
(testing "{{description}}"
(testing {{description}}
(is ({{#expected}}true?{{else}}false?{{/expected}} (triangle/isosceles? {{input.sides.0}} {{input.sides.1}} {{input.sides.2}})))))
{{/test_cases.isosceles~}}
{{#test_cases.scalene}}
(deftest scalene?_test_{{idx}}
(testing "{{description}}"
(testing {{description}}
(is ({{#expected}}true?{{else}}false?{{/expected}} (triangle/scalene? {{input.sides.0}} {{input.sides.1}} {{input.sides.2}})))))
{{/test_cases.scalene~}}
4 changes: 2 additions & 2 deletions exercises/practice/two-fer/.meta/generator.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
two-fer))
{{#test_cases.twoFer}}
(deftest two-fer_test_{{idx}}
(testing {{string description}}
(is (= {{string expected}} (two-fer/two-fer{{#input.name}} {{string input.name}}{{/input.name}})))))
(testing {{description}}
(is (= {{expected}} (two-fer/two-fer{{#input.name}} {{input.name}}{{/input.name}})))))
{{/test_cases.twoFer~}}

0 comments on commit 8a23f63

Please sign in to comment.