From 9484a03fbeb2a9f41ee26c1d25b12dc661418e28 Mon Sep 17 00:00:00 2001 From: Erik Simmler Date: Fri, 11 Mar 2016 18:44:46 -0500 Subject: [PATCH] Add rna-transcription exercise (closes #10) --- config.json | 1 + elm-package.json | 1 + .../rna-transcription/RNATranscription.elm | 1 + .../RNATranscription.example | 28 +++++++++++++ .../RNATranscriptionTests.elm | 39 +++++++++++++++++++ exercises/rna-transcription/elm-package.json | 16 ++++++++ 6 files changed, 86 insertions(+) create mode 100644 exercises/rna-transcription/RNATranscription.elm create mode 100644 exercises/rna-transcription/RNATranscription.example create mode 100644 exercises/rna-transcription/RNATranscriptionTests.elm create mode 100644 exercises/rna-transcription/elm-package.json diff --git a/config.json b/config.json index a347372..154a3ac 100644 --- a/config.json +++ b/config.json @@ -8,6 +8,7 @@ "hello-world", "leap", "pangram", + "rna-transcription", "bob" ], "deprecated": [ diff --git a/elm-package.json b/elm-package.json index 5cb03d6..0d0e753 100644 --- a/elm-package.json +++ b/elm-package.json @@ -8,6 +8,7 @@ "./exercises/hello_world", "./exercises/leap", "./exercises/pangram", + "./exercises/rna-transcription", "./exercises/bob" ], "exposed-modules": [], diff --git a/exercises/rna-transcription/RNATranscription.elm b/exercises/rna-transcription/RNATranscription.elm new file mode 100644 index 0000000..0c7925b --- /dev/null +++ b/exercises/rna-transcription/RNATranscription.elm @@ -0,0 +1 @@ +module RNATranscription (..) where diff --git a/exercises/rna-transcription/RNATranscription.example b/exercises/rna-transcription/RNATranscription.example new file mode 100644 index 0000000..cb94087 --- /dev/null +++ b/exercises/rna-transcription/RNATranscription.example @@ -0,0 +1,28 @@ +module RNATranscription (toRNA) where + +import String + + +toRNA : String -> Result Char String +toRNA dna = + dna + |> String.toList + |> List.map toRNANucleotide + |> resultExtraCombine + |> Result.map (List.map String.fromChar) + |> Result.map (String.join "") + + +-- Copied from elm-result-extra +resultExtraCombine : List (Result x a) -> Result x (List a) +resultExtraCombine = List.foldr (Result.map2 (::)) (Ok []) + + +toRNANucleotide : Char -> Result Char Char +toRNANucleotide nuc = + case nuc of + 'C' -> Ok 'G' + 'G' -> Ok 'C' + 'A' -> Ok 'U' + 'T' -> Ok 'A' + _ -> Err nuc diff --git a/exercises/rna-transcription/RNATranscriptionTests.elm b/exercises/rna-transcription/RNATranscriptionTests.elm new file mode 100644 index 0000000..88f10b9 --- /dev/null +++ b/exercises/rna-transcription/RNATranscriptionTests.elm @@ -0,0 +1,39 @@ +module Main (..) where + +import Task +import Console +import ElmTest exposing (..) +import RNATranscription exposing (toRNA) + + +tests : Test +tests = + suite + "RNATranscription" + [ test + "complement of cytosine is guanine" + (assertEqual (Ok "G") (toRNA "C")) + , test + "complement of guanine is cytosine" + (assertEqual (Ok "C") (toRNA "G")) + , test + "complement of thymine is adenine" + (assertEqual (Ok "A") (toRNA "T")) + , test + "complement of adenine is uracil" + (assertEqual (Ok "U") (toRNA "A")) + , test + "complement" + (assertEqual (Ok "UGCACCAGAAUU") (toRNA "ACGTGGTCTTAA")) + , test + "correctly handles completely invalid input" + (assertEqual (Err 'X') (toRNA "XXX")) + , test + "correctly handles partially invalid input" + (assertEqual (Err 'U') (toRNA "UGAAXXXGACAUG")) + ] + + +port runner : Signal (Task.Task x ()) +port runner = + Console.run (consoleRunner tests) diff --git a/exercises/rna-transcription/elm-package.json b/exercises/rna-transcription/elm-package.json new file mode 100644 index 0000000..d93a035 --- /dev/null +++ b/exercises/rna-transcription/elm-package.json @@ -0,0 +1,16 @@ +{ + "version": "1.0.0", + "summary": "Exercism problems in Elm.", + "repository": "https://github.com/exercism/xelm.git", + "license": "BSD3", + "source-directories": [ + "." + ], + "exposed-modules": [], + "dependencies": { + "deadfoxygrandpa/elm-test": "3.0.1 <= v < 4.0.0", + "elm-lang/core": "2.0.0 <= v < 4.0.0", + "laszlopandy/elm-console": "1.1.0 <= v < 2.0.0" + }, + "elm-version": "0.15.0 <= v < 0.17.0" +}