Skip to content

Commit

Permalink
Merge pull request #1410 from eval/fix-1310-clojure
Browse files Browse the repository at this point in the history
#1310 clojure: tests and example conform instruction
  • Loading branch information
kytrinyx committed Feb 21, 2014
2 parents 7d96ecc + 4043f21 commit e0b3450
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
20 changes: 12 additions & 8 deletions assignments/clojure/rna-transcription/example.clj
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
(ns dna)

(def adenosine \A)
(def cytadine \C)
(def guanosine \G)
(def thymidine \T)
(def uracil \U)
(def dna->rna {
\C \G
\G \C
\A \U
\T \A})

(defn validate-strand [strand]
(let [valid-dna (set (keys dna->rna))]
(every? valid-dna strand)))

(defn to-rna
[strand]
{:pre [(every? #{adenosine cytadine guanosine thymidine}
(set strand))]}
(clojure.string/replace strand thymidine uracil))
{:pre [(validate-strand strand)]}
(apply str
(map dna->rna (seq strand))))
10 changes: 5 additions & 5 deletions assignments/clojure/rna-transcription/rna_transcription_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
(load-file "dna.clj")

(deftest transcribes-cytidine-unchanged
(is (= "C" (dna/to-rna "C"))))
(is (= "G" (dna/to-rna "C"))))

(deftest transcribes-guanosine-unchanged
(is (= "G" (dna/to-rna "G"))))
(is (= "C" (dna/to-rna "G"))))

(deftest transcribes-adenosine-unchanged
(is (= "A" (dna/to-rna "A"))))
(is (= "U" (dna/to-rna "A"))))

(deftest it-transcribes-thymidine-to-uracil
(is (= "U" (dna/to-rna "T"))))
(is (= "A" (dna/to-rna "T"))))

(deftest it-transcribes-all-occurrences-of-thymidine-to-uracil
(is (= "ACGUGGUCUUAA" (dna/to-rna "ACGTGGTCTTAA"))))
(is (= "UGCACCAGAAUU" (dna/to-rna "ACGTGGTCTTAA"))))

(deftest it-validates-dna-strands
(is (thrown? AssertionError (dna/to-rna "XCGFGGTDTTAA"))))
Expand Down

0 comments on commit e0b3450

Please sign in to comment.