-
-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
difference-of-squares: add generator and regenerate tests
[no important files changed]
- Loading branch information
1 parent
b866e68
commit f664348
Showing
6 changed files
with
61 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
(ns difference-of-squares) | ||
|
||
(defn- square [n] (* n n)) | ||
(defn- sum [xs] (reduce + xs)) | ||
|
||
(defn sum-of-squares [n] | ||
(sum (map #(int (Math/pow % 2)) (range 0 (inc n))))) | ||
(sum (map square (range 1 (inc n))))) | ||
|
||
(defn square-of-sum [n] | ||
(int (Math/pow (sum (range 0 (inc n))) 2))) | ||
(square (sum (range 1 (inc n))))) | ||
|
||
(defn difference [x] | ||
(- (square-of-sum x) (sum-of-squares x))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
(ns difference-of-squares-generator) | ||
|
||
(defn- update-path [path] | ||
(take-last 1 path)) | ||
|
||
(defn transform [test-cases] | ||
(map #(update % :path update-path) test-cases)) |
18 changes: 18 additions & 0 deletions
18
exercises/practice/difference-of-squares/.meta/generator.tpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
(ns difference-of-squares-test | ||
(:require [clojure.test :refer [deftest testing is]] | ||
difference-of-squares)) | ||
{{#test_cases.squareOfSum}} | ||
(deftest square-of-sum_test_{{idx}} | ||
(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 "{{description}}" | ||
(is (= {{expected}} (difference-of-squares/sum-of-squares {{input.number}}))))) | ||
{{/test_cases.sumOfSquares~}} | ||
{{#test_cases.differenceOfSquares}} | ||
(deftest difference-of-squares_test_{{idx}} | ||
(testing "{{description}}" | ||
(is (= {{expected}} (difference-of-squares/difference {{input.number}}))))) | ||
{{/test_cases.differenceOfSquares}} |
4 changes: 2 additions & 2 deletions
4
exercises/practice/difference-of-squares/src/difference_of_squares.clj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
(ns difference-of-squares) | ||
|
||
(defn difference [] ;; <- arglist goes here | ||
(defn square-of-sum [] ;; <- arglist goes here | ||
;; your code goes here | ||
) | ||
|
||
(defn sum-of-squares [] ;; <- arglist goes here | ||
;; your code goes here | ||
) | ||
|
||
(defn square-of-sum [] ;; <- arglist goes here | ||
(defn difference [] ;; <- arglist goes here | ||
;; your code goes here | ||
) |
50 changes: 30 additions & 20 deletions
50
exercises/practice/difference-of-squares/test/difference_of_squares_test.clj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,40 @@ | ||
(ns difference-of-squares-test | ||
(:require [clojure.test :refer [deftest is]] | ||
[difference-of-squares :as dos])) | ||
(:require [clojure.test :refer [deftest testing is]] | ||
difference-of-squares)) | ||
|
||
(deftest square-of-sum-to-5 | ||
(is (= 225 (dos/square-of-sum 5)))) | ||
(deftest square-of-sum_test_1 | ||
(testing "square of sum 1" | ||
(is (= 1 (difference-of-squares/square-of-sum 1))))) | ||
|
||
(deftest sum-of-squares-to-5 | ||
(is (= 55 (dos/sum-of-squares 5)))) | ||
(deftest square-of-sum_test_2 | ||
(testing "square of sum 5" | ||
(is (= 225 (difference-of-squares/square-of-sum 5))))) | ||
|
||
(deftest difference-of-squares-to-5 | ||
(is (= 170 (dos/difference 5)))) | ||
(deftest square-of-sum_test_3 | ||
(testing "square of sum 100" | ||
(is (= 25502500 (difference-of-squares/square-of-sum 100))))) | ||
|
||
(deftest square-of-sum-to-10 | ||
(is (= 3025 (dos/square-of-sum 10)))) | ||
(deftest sum-of-squares_test_1 | ||
(testing "sum of squares 1" | ||
(is (= 1 (difference-of-squares/sum-of-squares 1))))) | ||
|
||
(deftest sum-of-squares-to-10 | ||
(is (= 385 (dos/sum-of-squares 10)))) | ||
(deftest sum-of-squares_test_2 | ||
(testing "sum of squares 5" | ||
(is (= 55 (difference-of-squares/sum-of-squares 5))))) | ||
|
||
(deftest difference-of-squares-to-10 | ||
(is (= 2640 (dos/difference 10)))) | ||
(deftest sum-of-squares_test_3 | ||
(testing "sum of squares 100" | ||
(is (= 338350 (difference-of-squares/sum-of-squares 100))))) | ||
|
||
(deftest square-of-sum-to-100 | ||
(is (= 25502500 (dos/square-of-sum 100)))) | ||
(deftest difference-of-squares_test_1 | ||
(testing "difference of squares 1" | ||
(is (= 0 (difference-of-squares/difference 1))))) | ||
|
||
(deftest sum-of-squares-to-100 | ||
(is (= 338350 (dos/sum-of-squares 100)))) | ||
(deftest difference-of-squares_test_2 | ||
(testing "difference of squares 5" | ||
(is (= 170 (difference-of-squares/difference 5))))) | ||
|
||
(deftest difference-of-squares_test_3 | ||
(testing "difference of squares 100" | ||
(is (= 25164150 (difference-of-squares/difference 100))))) | ||
|
||
(deftest difference-of-squares-to-100 | ||
(is (= 25164150 (dos/difference 100)))) |
Submodule .problem-specifications
added at
162890