-
-
Notifications
You must be signed in to change notification settings - Fork 161
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
89aec85
commit e027b27
Showing
4 changed files
with
37 additions
and
11 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_test_{{idx}} | ||
(testing "{{description}}" | ||
(is (= {{expected}} (difference-of-squares/difference {{input.number}}))))) | ||
{{/test_cases.differenceOfSquares~}} |
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