-
-
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.
* update example solution * add generators and regenerate tests * update function template * update contributors [no important files changed]
- Loading branch information
1 parent
d0db435
commit 74904a5
Showing
6 changed files
with
59 additions
and
31 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
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,5 +1,6 @@ | ||
(ns hamming) | ||
|
||
(defn distance [a b] | ||
(when (= (count a) (count b)) | ||
(count (filter true? (map not= a b))))) | ||
(if (= (count a) (count b)) | ||
(count (filter true? (map not= a b))) | ||
(throw (IllegalArgumentException. "strands must be of equal length")))) |
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,6 @@ | ||
(ns hamming-generator) | ||
|
||
(defn update-test-case [test-case] | ||
(if-let [error (get-in test-case [:expected :error])] | ||
(assoc-in test-case [:expected :error] (str "^" error "$")) | ||
test-case)) |
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,14 @@ | ||
(ns hamming-test | ||
(:require [clojure.test :refer [deftest testing is]] | ||
hamming)) | ||
|
||
{{#test_cases.distance}} | ||
(deftest distance_test_{{idx}} | ||
(testing {{description}} | ||
{{~#if error}} | ||
(is (thrown-with-msg? IllegalArgumentException #{{error}} | ||
(hamming/distance {{input.strand1}} {{input.strand2}}))))) | ||
{{else}} | ||
(is (= {{expected}} (hamming/hamming {{input.strand1}} {{input.strand2}}))))) | ||
{{/if~}} | ||
{{/test_cases.distance}} |
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,5 +1,7 @@ | ||
(ns hamming) | ||
|
||
(defn distance [strand1 strand2] ; <- arglist goes here | ||
;; your code goes here | ||
(defn distance | ||
"Returns the hamming distance between two DNA strands." | ||
[strand1 strand2] | ||
;; function body | ||
) |
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,39 +1,43 @@ | ||
(ns hamming-test | ||
(:require [clojure.test :refer [deftest is testing]] | ||
(:require [clojure.test :refer [deftest testing is]] | ||
hamming)) | ||
|
||
(deftest empty-strands | ||
(testing "Empty strands" | ||
(deftest distance_test_1 | ||
(testing "empty strands" | ||
(is (= 0 (hamming/distance "" ""))))) | ||
|
||
(deftest single-letter-identical-strands | ||
(testing "Single letter identical strands" | ||
(deftest distance_test_2 | ||
(testing "single letter identical strands" | ||
(is (= 0 (hamming/distance "A" "A"))))) | ||
|
||
(deftest single-letter-different-strands | ||
(testing "Single letter different strands" | ||
(deftest distance_test_3 | ||
(testing "single letter different strands" | ||
(is (= 1 (hamming/distance "G" "T"))))) | ||
|
||
(deftest long-identical-strands | ||
(testing "Long identical strands" | ||
(deftest distance_test_4 | ||
(testing "long identical strands" | ||
(is (= 0 (hamming/distance "GGACTGAAATCTG" "GGACTGAAATCTG"))))) | ||
|
||
(deftest long-different-strands | ||
(testing "Long different strands" | ||
(deftest distance_test_5 | ||
(testing "long different strands" | ||
(is (= 9 (hamming/distance "GGACGGATTCTG" "AGGACGGATTCT"))))) | ||
|
||
(deftest disallow-first-strand-longer | ||
(testing "Disallow first strand longer" | ||
(is (= nil (hamming/distance "AATG" "AAA"))))) | ||
|
||
(deftest disallow-second-strand-longer | ||
(testing "Disallow second strand longer" | ||
(is (= nil (hamming/distance "ATA" "AGTG"))))) | ||
|
||
(deftest disallow-empty-first-strand | ||
(testing "Disallow empty first strand" | ||
(is (= nil (hamming/distance "" "G"))))) | ||
|
||
(deftest disallow-empty-second-strand | ||
(testing "Disallow empty second strand" | ||
(is (= nil (hamming/distance "G" ""))))) | ||
(deftest distance_test_6 | ||
(testing "disallow first strand longer" | ||
(is (thrown-with-msg? IllegalArgumentException #"^strands must be of equal length$" | ||
(hamming/distance "AATG" "AAA"))))) | ||
|
||
(deftest distance_test_7 | ||
(testing "disallow second strand longer" | ||
(is (thrown-with-msg? IllegalArgumentException #"^strands must be of equal length$" | ||
(hamming/distance "ATA" "AGTG"))))) | ||
|
||
(deftest distance_test_8 | ||
(testing "disallow empty first strand" | ||
(is (thrown-with-msg? IllegalArgumentException #"^strands must be of equal length$" | ||
(hamming/distance "" "G"))))) | ||
|
||
(deftest distance_test_9 | ||
(testing "disallow empty second strand" | ||
(is (thrown-with-msg? IllegalArgumentException #"^strands must be of equal length$" | ||
(hamming/distance "G" ""))))) |