diff --git a/NucleotideCount/NucleotideCountExample.elm b/NucleotideCount/NucleotideCountExample.elm new file mode 100644 index 0000000..3d706df --- /dev/null +++ b/NucleotideCount/NucleotideCountExample.elm @@ -0,0 +1,15 @@ +module NucleotideCountExample where + +import String +import List + +nucleotideCounts : String -> List (Char, Int) +nucleotideCounts sequence = [ + (getCount 'A' sequence), + (getCount 'T' sequence), + (getCount 'C' sequence), + (getCount 'G' sequence) + ] + +getCount : Char -> String -> (Char, Int) +getCount base sequence = (base, (List.length (String.split (String.fromChar base) sequence)) - 1) diff --git a/NucleotideCount/NucleotideCountTest.elm b/NucleotideCount/NucleotideCountTest.elm new file mode 100644 index 0000000..6a64bf9 --- /dev/null +++ b/NucleotideCount/NucleotideCountTest.elm @@ -0,0 +1,22 @@ +module NucleotideCountTest where + +-- TODO - remove example inclusion once Problem sets are ready to go live or CI is set up. + +import NucleotideCountExample exposing (nucleotideCounts) + +import ElmTest.Test exposing (test, Test, suite) +import ElmTest.Assertion exposing (assert, assertEqual) +import ElmTest.Runner.Element exposing (runDisplay) + +tests : Test +tests = suite "NucleotideCount test suite" + [ + test "empty dna strand has no nucleotides" (assertEqual [('A', 0), ('T', 0), ('C', 0), ('G', 0)] + (nucleotideCounts "")), + test "repetitive-sequence-has-only-guanosine" (assertEqual [('A', 0), ('T', 0), ('C', 0), ('G', 8)] + (nucleotideCounts "GGGGGGGG")), + test "counts all nucleotides" (assertEqual [('A', 20), ('T', 21), ('C', 12), ('G', 17)] + (nucleotideCounts "AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC")) + ] + +main = runDisplay tests diff --git a/elm-package.json b/elm-package.json index 7b2b846..6eb0b95 100644 --- a/elm-package.json +++ b/elm-package.json @@ -24,7 +24,9 @@ "Bob", "SumOfMultiples", "Strain", - "SpaceAge" + "SpaceAge", + "Anagram", + "NucleotideCount" ], "exposed-modules": [], "dependencies": {