mirror of
https://github.com/correl/elm.git
synced 2025-03-10 17:00:07 -09:00
Add rna-transcription exercise (closes #10)
This commit is contained in:
parent
0b3ae4f8b8
commit
9484a03fbe
6 changed files with 86 additions and 0 deletions
|
@ -8,6 +8,7 @@
|
||||||
"hello-world",
|
"hello-world",
|
||||||
"leap",
|
"leap",
|
||||||
"pangram",
|
"pangram",
|
||||||
|
"rna-transcription",
|
||||||
"bob"
|
"bob"
|
||||||
],
|
],
|
||||||
"deprecated": [
|
"deprecated": [
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
"./exercises/hello_world",
|
"./exercises/hello_world",
|
||||||
"./exercises/leap",
|
"./exercises/leap",
|
||||||
"./exercises/pangram",
|
"./exercises/pangram",
|
||||||
|
"./exercises/rna-transcription",
|
||||||
"./exercises/bob"
|
"./exercises/bob"
|
||||||
],
|
],
|
||||||
"exposed-modules": [],
|
"exposed-modules": [],
|
||||||
|
|
1
exercises/rna-transcription/RNATranscription.elm
Normal file
1
exercises/rna-transcription/RNATranscription.elm
Normal file
|
@ -0,0 +1 @@
|
||||||
|
module RNATranscription (..) where
|
28
exercises/rna-transcription/RNATranscription.example
Normal file
28
exercises/rna-transcription/RNATranscription.example
Normal 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
|
39
exercises/rna-transcription/RNATranscriptionTests.elm
Normal file
39
exercises/rna-transcription/RNATranscriptionTests.elm
Normal 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)
|
16
exercises/rna-transcription/elm-package.json
Normal file
16
exercises/rna-transcription/elm-package.json
Normal 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"
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue