Add rna-transcription exercise (closes #10)

This commit is contained in:
Erik Simmler 2016-03-11 18:44:46 -05:00
parent 0b3ae4f8b8
commit 9484a03fbe
6 changed files with 86 additions and 0 deletions

View file

@ -8,6 +8,7 @@
"hello-world",
"leap",
"pangram",
"rna-transcription",
"bob"
],
"deprecated": [

View file

@ -8,6 +8,7 @@
"./exercises/hello_world",
"./exercises/leap",
"./exercises/pangram",
"./exercises/rna-transcription",
"./exercises/bob"
],
"exposed-modules": [],

View file

@ -0,0 +1 @@
module RNATranscription (..) where

View file

@ -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

View file

@ -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)

View file

@ -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"
}