Skip to content

Commit e027b27

Browse files
difference-of-squares: add generator and regenerate tests
[no important files changed]
1 parent 89aec85 commit e027b27

File tree

4 files changed

+37
-11
lines changed

4 files changed

+37
-11
lines changed
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
(ns difference-of-squares)
22

3+
(defn- square [n] (* n n))
34
(defn- sum [xs] (reduce + xs))
45

56
(defn sum-of-squares [n]
6-
(sum (map #(int (Math/pow % 2)) (range 0 (inc n)))))
7+
(sum (map square (range 1 (inc n)))))
78

89
(defn square-of-sum [n]
9-
(int (Math/pow (sum (range 0 (inc n))) 2)))
10+
(square (sum (range 1 (inc n)))))
1011

1112
(defn difference [x]
1213
(- (square-of-sum x) (sum-of-squares x)))
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
(ns difference-of-squares-generator)
2+
3+
(defn- update-path [path]
4+
(take-last 1 path))
5+
6+
(defn transform [test-cases]
7+
(map #(update % :path update-path) test-cases))
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
(ns difference-of-squares-test
2+
(:require [clojure.test :refer [deftest testing is]]
3+
difference-of-squares))
4+
{{#test_cases.squareOfSum}}
5+
(deftest square-of-sum_test_{{idx}}
6+
(testing "{{description}}"
7+
(is (= {{expected}} (difference-of-squares/square-of-sum {{input.number}})))))
8+
{{/test_cases.squareOfSum~}}
9+
{{#test_cases.sumOfSquares}}
10+
(deftest sum-of-squares_test_{{idx}}
11+
(testing "{{description}}"
12+
(is (= {{expected}} (difference-of-squares/sum-of-squares {{input.number}})))))
13+
{{/test_cases.sumOfSquares~}}
14+
{{#test_cases.differenceOfSquares}}
15+
(deftest difference_test_{{idx}}
16+
(testing "{{description}}"
17+
(is (= {{expected}} (difference-of-squares/difference {{input.number}})))))
18+
{{/test_cases.differenceOfSquares~}}

exercises/practice/difference-of-squares/test/difference_of_squares_test.clj

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,37 @@
33
difference-of-squares))
44

55
(deftest square-of-sum_test_1
6-
(testing "Square the sum of the numbers up to the given number -> square of sum 1"
6+
(testing "square of sum 1"
77
(is (= 1 (difference-of-squares/square-of-sum 1)))))
88

99
(deftest square-of-sum_test_2
10-
(testing "Square the sum of the numbers up to the given number -> square of sum 5"
10+
(testing "square of sum 5"
1111
(is (= 225 (difference-of-squares/square-of-sum 5)))))
1212

1313
(deftest square-of-sum_test_3
14-
(testing "Square the sum of the numbers up to the given number -> square of sum 100"
14+
(testing "square of sum 100"
1515
(is (= 25502500 (difference-of-squares/square-of-sum 100)))))
1616

1717
(deftest sum-of-squares_test_1
18-
(testing "Sum the squares of the numbers up to the given number -> sum of squares 1"
18+
(testing "sum of squares 1"
1919
(is (= 1 (difference-of-squares/sum-of-squares 1)))))
2020

2121
(deftest sum-of-squares_test_2
22-
(testing "Sum the squares of the numbers up to the given number -> sum of squares 5"
22+
(testing "sum of squares 5"
2323
(is (= 55 (difference-of-squares/sum-of-squares 5)))))
2424

2525
(deftest sum-of-squares_test_3
26-
(testing "Sum the squares of the numbers up to the given number -> sum of squares 100"
26+
(testing "sum of squares 100"
2727
(is (= 338350 (difference-of-squares/sum-of-squares 100)))))
2828

2929
(deftest difference_test_1
30-
(testing "Subtract sum of squares from square of sums -> difference of squares 1"
30+
(testing "difference of squares 1"
3131
(is (= 0 (difference-of-squares/difference 1)))))
3232

3333
(deftest difference_test_2
34-
(testing "Subtract sum of squares from square of sums -> difference of squares 5"
34+
(testing "difference of squares 5"
3535
(is (= 170 (difference-of-squares/difference 5)))))
3636

3737
(deftest difference_test_3
38-
(testing "Subtract sum of squares from square of sums -> difference of squares 100"
38+
(testing "difference of squares 100"
3939
(is (= 25164150 (difference-of-squares/difference 100)))))

0 commit comments

Comments
 (0)