Skip to content

Commit

Permalink
sum-of-multiples: add generator and regenerate tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikSchierboom committed Jan 11, 2025
1 parent 9c2d084 commit 3c732eb
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 43 deletions.
8 changes: 8 additions & 0 deletions exercises/practice/sum-of-multiples/.meta/generator.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(ns sum-of-multiples-test
(:require [clojure.test :refer [deftest testing is]]
sum-of-multiples))
{{#test_cases.sum}}
(deftest sum-of-multiples?_test_{{idx}}
(testing "{{description}}"
(is ({{#ifequals expected compare=0}}zero?{{else}}= {{expected}}{{/ifequals}} (sum-of-multiples/sum-of-multiples {{list input.factors}} {{input.limit}})))))
{{/test_cases.sum}}
86 changes: 43 additions & 43 deletions exercises/practice/sum-of-multiples/test/sum_of_multiples_test.clj
Original file line number Diff line number Diff line change
@@ -1,59 +1,59 @@
(ns sum-of-multiples-test
(:require [clojure.test :refer [deftest testing is]]
[sum-of-multiples :refer [sum-of-multiples]]))
sum-of-multiples))

(deftest no-multiples
(testing "No multiples within limit"
(is (zero? (sum-of-multiples '(3 5) 1)))))
(deftest sum-of-multiples?_test_1
(testing "no multiples within limit"
(is (zero? (sum-of-multiples/sum-of-multiples '(3 5) 1)))))

(deftest one-factor-multiples
(testing "One factor has multiples within limit"
(is (= 3 (sum-of-multiples '(3 5) 4)))))
(deftest sum-of-multiples?_test_2
(testing "one factor has multiples within limit"
(is (= 3 (sum-of-multiples/sum-of-multiples '(3 5) 4)))))

(deftest more-than-one-multiple
(testing "More than one multiple within limit"
(is (= 9 (sum-of-multiples '(3) 7)))))
(deftest sum-of-multiples?_test_3
(testing "more than one multiple within limit"
(is (= 9 (sum-of-multiples/sum-of-multiples '(3) 7)))))

(deftest more-than-one-factor-multiples
(testing "More than one factor with multiples within limit"
(is (= 23 (sum-of-multiples '(3 5) 10)))))
(deftest sum-of-multiples?_test_4
(testing "more than one factor with multiples within limit"
(is (= 23 (sum-of-multiples/sum-of-multiples '(3 5) 10)))))

(deftest count-multiples-once
(testing "Each multiple is only counted once"
(is (= 2318 (sum-of-multiples '(3 5) 100)))))
(deftest sum-of-multiples?_test_5
(testing "each multiple is only counted once"
(is (= 2318 (sum-of-multiples/sum-of-multiples '(3 5) 100)))))

(deftest larger-limit
(testing "A much larger limit"
(is (= 233168 (sum-of-multiples '(3 5) 1000)))))
(deftest sum-of-multiples?_test_6
(testing "a much larger limit"
(is (= 233168 (sum-of-multiples/sum-of-multiples '(3 5) 1000)))))

(deftest three-factors
(testing "Three factors"
(is (= 51 (sum-of-multiples '(7 13 17) 20)))))
(deftest sum-of-multiples?_test_7
(testing "three factors"
(is (= 51 (sum-of-multiples/sum-of-multiples '(7 13 17) 20)))))

(deftest factors-not-relatively-prime
(testing "Factors not relatively prime"
(is (= 30 (sum-of-multiples '(4 6) 15)))))
(deftest sum-of-multiples?_test_8
(testing "factors not relatively prime"
(is (= 30 (sum-of-multiples/sum-of-multiples '(4 6) 15)))))

(deftest some-factors-relatively-prime
(testing "Some pairs of factors relatively prime and some not"
(is (= 4419 (sum-of-multiples '(5 6 8) 150)))))
(deftest sum-of-multiples?_test_9
(testing "some pairs of factors relatively prime and some not"
(is (= 4419 (sum-of-multiples/sum-of-multiples '(5 6 8) 150)))))

(deftest factor-multiple-of-other-factor
(testing "One factor is a multiple of another"
(is (= 275 (sum-of-multiples '(5 25) 51)))))
(deftest sum-of-multiples?_test_10
(testing "one factor is a multiple of another"
(is (= 275 (sum-of-multiples/sum-of-multiples '(5 25) 51)))))

(deftest larger-factors
(testing "Much larger factors"
(is (= 2203160 (sum-of-multiples '(43 47) 10000)))))
(deftest sum-of-multiples?_test_11
(testing "much larger factors"
(is (= 2203160 (sum-of-multiples/sum-of-multiples '(43 47) 10000)))))

(deftest all-factors-multiples-of-1
(testing "All factors are multiples of 1"
(is (= 4950 (sum-of-multiples '(1) 100)))))
(deftest sum-of-multiples?_test_12
(testing "all numbers are multiples of 1"
(is (= 4950 (sum-of-multiples/sum-of-multiples '(1) 100)))))

(deftest no-factors
(testing "No factors means sum is 0"
(is (zero? (sum-of-multiples '() 10000)))))
(deftest sum-of-multiples?_test_13
(testing "no factors means an empty sum"
(is (zero? (sum-of-multiples/sum-of-multiples ' 10000)))))

(deftest more-than-three-factors
(testing "More than 3 factors"
(is (= 39614537 (sum-of-multiples '(2 3 5 7 11) 10000)))))
(deftest sum-of-multiples?_test_14
(testing "solutions using include-exclude must extend to cardinality greater than 3"
(is (= 39614537 (sum-of-multiples/sum-of-multiples '(2 3 5 7 11) 10000)))))

0 comments on commit 3c732eb

Please sign in to comment.