diff --git a/config.json b/config.json index 8ed262c..2b68954 100644 --- a/config.json +++ b/config.json @@ -5,18 +5,26 @@ "active": false, "test_pattern": "TODO", "problems": [ - "hello-world", - "bob", - "leap", - "raindrops", - "pangram", - "triangle", - "anagram", - "difference-of-squares", - "word-count", - "hamming", - "rna-transcription", - "run-length-encoding" + "hello-world", + "bob", + "leap", + "raindrops", + "pangram", + "accumulate", + "triangle", + "anagram", + "space-age", + "strain", + "difference-of-squares", + "word-count", + "sum-of-multiples", + "hamming", + "rna-transcription", + "run-length-encoding", + "sublist", + "nucleotide-count", + "phone-number", + "grade-school" ], "deprecated": [ @@ -28,6 +36,5 @@ "docs" ], "foregone": [ - ] } diff --git a/elm-package.json b/elm-package.json index 3f469c1..e6a166d 100644 --- a/elm-package.json +++ b/elm-package.json @@ -16,7 +16,15 @@ "./exercises/difference-of-squares", "./exercises/anagram", "./exercises/raindrops", - "./exercises/triangle" + "./exercises/triangle", + "./exercises/accumulate", + "./exercises/sublist", + "./exercises/sum-of-multiples", + "./exercises/strain", + "./exercises/space-age", + "./exercises/nucleotide-count", + "./exercises/phone-number", + "./exercises/grade-school" ], "exposed-modules": [], "dependencies": { diff --git a/exercises/accumulate/Accumulate.elm b/exercises/accumulate/Accumulate.elm new file mode 100644 index 0000000..daf8472 --- /dev/null +++ b/exercises/accumulate/Accumulate.elm @@ -0,0 +1 @@ +module Accumulate (..) where diff --git a/exercises/accumulate/Accumulate.example b/exercises/accumulate/Accumulate.example new file mode 100644 index 0000000..b1630c3 --- /dev/null +++ b/exercises/accumulate/Accumulate.example @@ -0,0 +1,6 @@ +module Accumulate (..) where + + +accumulate : (a -> b) -> List a -> List b +accumulate func input = + List.foldr (\v c -> func v :: c) [] input diff --git a/exercises/accumulate/AccumulateTests.elm b/exercises/accumulate/AccumulateTests.elm new file mode 100644 index 0000000..52932a5 --- /dev/null +++ b/exercises/accumulate/AccumulateTests.elm @@ -0,0 +1,36 @@ +module Main (..) where + +import Task +import Console +import ElmTest exposing (..) +import Accumulate exposing (accumulate) +import String + + +square : Int -> Int +square x = + x * x + + +tests : Test +tests = + suite + "Accumulate" + [ test + "[]] Accumulate" + (assertEqual [] (accumulate square [])) + , test + "square Accumulate" + (assertEqual [ 1, 4, 9 ] (accumulate square [ 1, 2, 3 ])) + , test + "toUpper Accumulate" + (assertEqual [ "HELLO", "WORLD" ] (accumulate String.toUpper [ "hello", "world" ])) + , test + "reverse Accumulate" + (assertEqual [ "olleh", "dlrow" ] (accumulate String.reverse [ "hello", "world" ])) + ] + + +port runner : Signal (Task.Task x ()) +port runner = + Console.run (consoleRunner tests) diff --git a/exercises/accumulate/elm-package.json b/exercises/accumulate/elm-package.json new file mode 100644 index 0000000..d93a035 --- /dev/null +++ b/exercises/accumulate/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" +} diff --git a/exercises/grade-school/GradeSchool.elm b/exercises/grade-school/GradeSchool.elm new file mode 100644 index 0000000..b693c89 --- /dev/null +++ b/exercises/grade-school/GradeSchool.elm @@ -0,0 +1,2 @@ +module GradeSchool (..) where + diff --git a/exercises/grade-school/GradeSchool.example b/exercises/grade-school/GradeSchool.example new file mode 100644 index 0000000..11af7ec --- /dev/null +++ b/exercises/grade-school/GradeSchool.example @@ -0,0 +1,40 @@ +module GradeSchool (..) where + +import Dict exposing (..) + + +type alias Grade = + Int + + +type alias Student = + String + + +type alias School = + Dict Int (List Student) + + +empty : School +empty = + Dict.empty + + +addStudent : Grade -> Student -> School -> School +addStudent grade student school = + Dict.insert grade (List.sort (student :: (studentsInGrade grade school))) school + + +studentsInGrade : Grade -> School -> List Student +studentsInGrade grade school = + case (Dict.get grade school) of + Just list -> + list + + Nothing -> + [] + + +allStudents : School -> List ( Grade, List Student ) +allStudents school = + Dict.toList school |> List.sortBy fst diff --git a/exercises/grade-school/GradeSchoolTests.elm b/exercises/grade-school/GradeSchoolTests.elm new file mode 100644 index 0000000..d5d37df --- /dev/null +++ b/exercises/grade-school/GradeSchoolTests.elm @@ -0,0 +1,77 @@ +module Main (..) where + +import Task +import Console +import ElmTest exposing (..) +import GradeSchool exposing (addStudent, studentsInGrade, allStudents) + + +tests : Test +tests = + suite + "GradeSchool" + [ test + "add student" + (assertEqual + [ "Aimee" ] + (GradeSchool.empty + |> addStudent 2 "Aimee" + |> studentsInGrade 2 + ) + ) + , test + "add more students in same class" + (assertEqual + [ "Blair", "James", "Paul" ] + (GradeSchool.empty + |> addStudent 2 "James" + |> addStudent 2 "Blair" + |> addStudent 2 "Paul" + |> studentsInGrade 2 + ) + ) + , test + "add students to different grades" + (assertEqual + [ [ "Chelsea" ], [ "Logan" ] ] + (let + school = + GradeSchool.empty + |> addStudent 3 "Chelsea" + |> addStudent 7 "Logan" + in + [ studentsInGrade 3 school, studentsInGrade 7 school ] + ) + ) + , test + "get students in a grade" + (assertEqual + [ "Bradley", "Franklin" ] + (GradeSchool.empty + |> addStudent 5 "Franklin" + |> addStudent 5 "Bradley" + |> addStudent 1 "Jeff" + |> studentsInGrade 5 + ) + ) + , test + "get all students in the school" + (assertEqual + [ ( 3, [ "Kyle" ] ), ( 4, [ "Christopher", "Jennifer" ] ), ( 6, [ "Kareem" ] ) ] + (GradeSchool.empty + |> addStudent 4 "Jennifer" + |> addStudent 6 "Kareem" + |> addStudent 4 "Christopher" + |> addStudent 3 "Kyle" + |> allStudents + ) + ) + , test + "get students in a non-existent grade" + (assertEqual [] (studentsInGrade 1 GradeSchool.empty)) + ] + + +port runner : Signal (Task.Task x ()) +port runner = + Console.run (consoleRunner tests) diff --git a/exercises/grade-school/elm-package.json b/exercises/grade-school/elm-package.json new file mode 100644 index 0000000..d93a035 --- /dev/null +++ b/exercises/grade-school/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" +} diff --git a/exercises/hello-world/HelloWorld.example b/exercises/hello-world/HelloWorld.example index 4c0dac0..bbec56a 100644 --- a/exercises/hello-world/HelloWorld.example +++ b/exercises/hello-world/HelloWorld.example @@ -5,6 +5,7 @@ helloWorld : Maybe String -> String helloWorld name = case name of Just name -> - "Hello, " ++ name ++ "!" + "Hello, " ++ name ++ "!" + Nothing -> "Hello, World!" diff --git a/exercises/nucleotide-count/NucleotideCount.elm b/exercises/nucleotide-count/NucleotideCount.elm new file mode 100644 index 0000000..4dccb71 --- /dev/null +++ b/exercises/nucleotide-count/NucleotideCount.elm @@ -0,0 +1 @@ +module NucleotideCount (..) where diff --git a/exercises/nucleotide-count/NucleotideCount.example b/exercises/nucleotide-count/NucleotideCount.example new file mode 100644 index 0000000..7f6b88c --- /dev/null +++ b/exercises/nucleotide-count/NucleotideCount.example @@ -0,0 +1,18 @@ +module NucleotideCount (..) 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/exercises/nucleotide-count/NucleotideCountTests.elm b/exercises/nucleotide-count/NucleotideCountTests.elm new file mode 100644 index 0000000..4ab66c4 --- /dev/null +++ b/exercises/nucleotide-count/NucleotideCountTests.elm @@ -0,0 +1,36 @@ +module Main (..) where + +import Task +import Console +import ElmTest exposing (..) +import NucleotideCount exposing (nucleotideCounts) + + +tests : Test +tests = + suite + "NucleotideCount" + [ 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") + ) + ] + + +port runner : Signal (Task.Task x ()) +port runner = + Console.run (consoleRunner tests) diff --git a/exercises/nucleotide-count/elm-package.json b/exercises/nucleotide-count/elm-package.json new file mode 100644 index 0000000..d93a035 --- /dev/null +++ b/exercises/nucleotide-count/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" +} diff --git a/exercises/phone-number/PhoneNumber.elm b/exercises/phone-number/PhoneNumber.elm new file mode 100644 index 0000000..076c905 --- /dev/null +++ b/exercises/phone-number/PhoneNumber.elm @@ -0,0 +1 @@ +module PhoneNumber (..) where diff --git a/exercises/phone-number/PhoneNumber.example b/exercises/phone-number/PhoneNumber.example new file mode 100644 index 0000000..c5271a3 --- /dev/null +++ b/exercises/phone-number/PhoneNumber.example @@ -0,0 +1,44 @@ +module PhoneNumber (..) where + +import String + + +nums = + [ '1', '2', '3', '4', '5', '6', '7', '8', '9', '0' ] + + +getNumber : String -> Maybe String +getNumber text = + getValidNum (String.filter isDigit text) + + +isDigit : Char -> Bool +isDigit char = + List.any (\n -> n == char) nums + + +getValidNum : String -> Maybe String +getValidNum num = + if String.length num == 10 then + Just num + else if (String.length num == 11) && (String.left 1 num == "1") then + Just (String.dropLeft 1 num) + else + Nothing + + +prettyPrint : String -> Maybe String +prettyPrint input = + Maybe.map formatNumber (getNumber input) + + +formatNumber : String -> String +formatNumber input = + String.concat + [ "(" + , (String.slice 0 3 input) + , ") " + , (String.slice 3 6 input) + , "-" + , (String.slice 6 10 input) + ] diff --git a/exercises/phone-number/PhoneNumberTests.elm b/exercises/phone-number/PhoneNumberTests.elm new file mode 100644 index 0000000..1a116dd --- /dev/null +++ b/exercises/phone-number/PhoneNumberTests.elm @@ -0,0 +1,54 @@ +module Main (..) where + +import Task +import Console +import ElmTest exposing (..) +import PhoneNumber exposing (getNumber, prettyPrint) + + +tests : Test +tests = + suite + "PhoneNumber" + [ test + "cleans number" + (assertEqual (Just "1234567890") (getNumber "(123) 456-7890")) + , test + "cleans number with dots" + (assertEqual (Just "1234567890") (getNumber "123.456.7890")) + , test + "valid when 11 digits and first is 1" + (assertEqual (Just "1234567890") (getNumber "11234567890")) + , test + "invalid when 11 digits" + (assertEqual Nothing (getNumber "21234567890")) + , test + "invalid when 9 digits" + (assertEqual Nothing (getNumber "123456789")) + , test + "invalid when 12 digits" + (assertEqual Nothing (getNumber "123456789012")) + , test + "invalid when empty" + (assertEqual Nothing (getNumber "")) + , test + "invalid when no digits present" + (assertEqual Nothing (getNumber " (-) ")) + , test + "valid with leading characters" + (assertEqual (Just "1234567890") (getNumber "my number is 123 456 7890")) + , test + "valid with trailing characters" + (assertEqual (Just "1234567890") (getNumber "123 456 7890 - bob")) + , test + "pretty print" + (assertEqual (Just "(123) 456-7890") (prettyPrint "1234567890")) + , test + "pretty print with full us phone number" + (assertEqual (Just "(123) 456-7890") (prettyPrint "11234567890")) + ] + + +port runner : Signal (Task.Task x ()) +port runner = + Console.run (consoleRunner tests) diff --git a/exercises/phone-number/elm-package.json b/exercises/phone-number/elm-package.json new file mode 100644 index 0000000..d93a035 --- /dev/null +++ b/exercises/phone-number/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" +} diff --git a/exercises/space-age/SpaceAge.elm b/exercises/space-age/SpaceAge.elm new file mode 100644 index 0000000..86aac4c --- /dev/null +++ b/exercises/space-age/SpaceAge.elm @@ -0,0 +1,11 @@ +module SpaceAge (..) where + +type Planet + = Mercury + | Venus + | Earth + | Mars + | Jupiter + | Saturn + | Uranus + | Neptune diff --git a/exercises/space-age/SpaceAge.example b/exercises/space-age/SpaceAge.example new file mode 100644 index 0000000..89241e0 --- /dev/null +++ b/exercises/space-age/SpaceAge.example @@ -0,0 +1,50 @@ +module SpaceAge (..) where + + +type Planet + = Mercury + | Venus + | Earth + | Mars + | Jupiter + | Saturn + | Uranus + | Neptune + + +earthYearInSeconds = + 365.25 * 24 * 60 * 60 + + +ageOn : Planet -> Float -> Float +ageOn planet seconds = + seconds / (secondsPerYear planet) + + +secondsPerYear : Planet -> Float +secondsPerYear planet = + earthYearInSeconds + * case planet of + Mercury -> + 0.2408467 + + Venus -> + 0.61519726 + + Earth -> + 1 + + Mars -> + 1.8808158 + + Jupiter -> + 11.862615 + + Saturn -> + 29.447498 + + Uranus -> + 84.016846 + + Neptune -> + 164.79132 diff --git a/exercises/space-age/SpaceAgeTests.elm b/exercises/space-age/SpaceAgeTests.elm new file mode 100644 index 0000000..3734264 --- /dev/null +++ b/exercises/space-age/SpaceAgeTests.elm @@ -0,0 +1,42 @@ +module Main (..) where + +import Task +import Console +import ElmTest exposing (..) +import SpaceAge exposing (Planet(..), ageOn) + + +tests : Test +tests = + suite + "SpaceAge" + [ test + "age in earth years" + (assertEqual 32 (round (ageOn Earth 1000000000))) + , test + "age in mercury years" + (assertEqual 281 (round (ageOn Mercury 2134835688))) + , test + "age in venus years" + (assertEqual 10 (round (ageOn Venus 189839836))) + , test + "age on mars" + (assertEqual 39 (round (ageOn Mars 2329871239))) + , test + "age on jupiter" + (assertEqual 2 (round (ageOn Jupiter 901876382))) + , test + "age on saturn" + (assertEqual 3 (round (ageOn Saturn 3000000000))) + , test + "age on uranus" + (assertEqual 1 (round (ageOn Uranus 3210123456))) + , test + "age on neptune" + (assertEqual 2 (round (ageOn Neptune 8210123456))) + ] + + +port runner : Signal (Task.Task x ()) +port runner = + Console.run (consoleRunner tests) diff --git a/exercises/space-age/elm-package.json b/exercises/space-age/elm-package.json new file mode 100644 index 0000000..d93a035 --- /dev/null +++ b/exercises/space-age/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" +} diff --git a/exercises/strain/Strain.elm b/exercises/strain/Strain.elm new file mode 100644 index 0000000..f9a33e6 --- /dev/null +++ b/exercises/strain/Strain.elm @@ -0,0 +1 @@ +module Strain (..) where diff --git a/exercises/strain/Strain.example b/exercises/strain/Strain.example new file mode 100644 index 0000000..3865e38 --- /dev/null +++ b/exercises/strain/Strain.example @@ -0,0 +1,21 @@ +module Strain (..) where + +import List + + +keep : (a -> Bool) -> List a -> List a +keep predicate list = + List.foldr (consIf predicate) [] list + + +discard : (a -> Bool) -> List a -> List a +discard predicate list = + List.foldr (consIf (\v -> not <| predicate v)) [] list + + +consIf : (a -> Bool) -> a -> List a -> List a +consIf predicate value list = + if predicate value then + value :: list + else + list diff --git a/exercises/strain/StrainTests.elm b/exercises/strain/StrainTests.elm new file mode 100644 index 0000000..ebc0337 --- /dev/null +++ b/exercises/strain/StrainTests.elm @@ -0,0 +1,111 @@ +module Main (..) where + +import Task +import Console +import ElmTest exposing (..) +import Strain exposing (keep, discard) +import String + + +even : Int -> Bool +even number = + number % 2 == 0 + + +odd : Int -> Bool +odd number = + number % 2 == 1 + + +isFirstLetter : String -> String -> Bool +isFirstLetter letter word = + (String.left 1 word) == letter + + +lessThanTen : number -> Bool +lessThanTen num = + num < 10 + + +tests : Test +tests = + suite + "Strain" + [ test + "empty keep" + (assertEqual + [] + (keep lessThanTen []) + ) + , test + "keep everything" + (assertEqual + [ 1, 2, 3 ] + (keep lessThanTen [ 1, 2, 3 ]) + ) + , test + "keep first and last" + (assertEqual + [ 1, 3 ] + (keep odd [ 1, 2, 3 ]) + ) + , test + "keep nothing" + (assertEqual + [] + (keep even [ 1, 3, 5, 7 ]) + ) + , test + "keep neither first nor last" + (assertEqual + [ 2 ] + (keep even [ 1, 2, 3 ]) + ) + , test + "keep strings" + (assertEqual + [ "zebra", "zombies", "zealot" ] + (keep (isFirstLetter "z") [ "apple", "zebra", "banana", "zombies", "cherimoya", "zealot" ]) + ) + , test + "empty discard" + (assertEqual + [] + (discard lessThanTen []) + ) + , test + "discard everything" + (assertEqual + [] + (discard lessThanTen [ 1, 2, 3 ]) + ) + , test + "discard first and last" + (assertEqual + [ 2 ] + (discard odd [ 1, 2, 3 ]) + ) + , test + "discard nothing" + (assertEqual + [ 1, 3, 5, 7 ] + (discard even [ 1, 3, 5, 7 ]) + ) + , test + "discard neither first nor last" + (assertEqual + [ 1, 3 ] + (discard even [ 1, 2, 3 ]) + ) + , test + "discard strings" + (assertEqual + [ "apple", "banana", "cherimoya" ] + (discard (isFirstLetter "z") [ "apple", "zebra", "banana", "zombies", "cherimoya", "zealot" ]) + ) + ] + + +port runner : Signal (Task.Task x ()) +port runner = + Console.run (consoleRunner tests) diff --git a/exercises/strain/elm-package.json b/exercises/strain/elm-package.json new file mode 100644 index 0000000..d93a035 --- /dev/null +++ b/exercises/strain/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" +} diff --git a/exercises/sublist/Sublist.elm b/exercises/sublist/Sublist.elm new file mode 100644 index 0000000..53ce299 --- /dev/null +++ b/exercises/sublist/Sublist.elm @@ -0,0 +1 @@ +module Sublist (..) where diff --git a/exercises/sublist/Sublist.example b/exercises/sublist/Sublist.example new file mode 100644 index 0000000..8cea41b --- /dev/null +++ b/exercises/sublist/Sublist.example @@ -0,0 +1,35 @@ +module Sublist (..) where + +import List exposing (..) +import String + + +sublist : List a -> List a -> String +sublist alist blist = + if alist == blist then + "Equal" + else if inList alist blist then + "Superlist" + else if inList blist alist then + "Sublist" + else + "Unequal" + + +inList : List a -> List a -> Bool +inList alist blist = + let + getLastInList sublist = + case (List.tail sublist) of + Just list -> + list + + Nothing -> + [] + in + if (List.length alist) < (List.length blist) then + False + else if (List.take (List.length blist) alist) == blist then + True + else + inList (getLastInList alist) blist diff --git a/exercises/sublist/SublistTests.elm b/exercises/sublist/SublistTests.elm new file mode 100644 index 0000000..aba6f6b --- /dev/null +++ b/exercises/sublist/SublistTests.elm @@ -0,0 +1,72 @@ +module Main (..) where + +import Task +import Console +import ElmTest exposing (..) +import Sublist exposing (sublist) + + +tests : Test +tests = + suite + "Sublist" + [ test + "empty equals empty" + (assertEqual "Equal" (sublist [] [])) + , test + "empty is a sublist of anything" + (assertEqual "Sublist" (sublist [] [ 1, 2 ])) + , test + "anything is a superlist of empty" + (assertEqual "Superlist" (sublist [ 1, 2 ] [])) + , test + "1 is not 2" + (assertEqual "Unequal" (sublist [ 1 ] [ 2 ])) + , test + "compare larger equal lists" + (assertEqual "Equal" (sublist [ 1, 1, 1 ] [ 1, 1, 1 ])) + , test + "sublist at start" + (assertEqual "Sublist" (sublist [ 1, 2, 3 ] [ 1, 2, 3, 4, 5 ])) + , test + "sublist in the middle" + (assertEqual "Sublist" (sublist [ 4, 3, 2 ] [ 5, 4, 3, 2, 1 ])) + , test + "sublist at end" + (assertEqual "Sublist" (sublist [ 3, 4, 5 ] [ 1, 2, 3, 4, 5 ])) + , test + "partially matching sublist at start" + (assertEqual "Sublist" (sublist [ 1, 1, 2 ] [ 1, 1, 1, 2 ])) + , test + "sublist early in huge list" + (assertEqual "Sublist" (sublist [ 3, 4, 5 ] [1..100000])) + , test + "huge sublist not in list" + (assertEqual "Unequal" (sublist [10..100001] [1..100000])) + , test + "superlist at start" + (assertEqual "Superlist" (sublist [ 1, 2, 3, 4, 5 ] [ 1, 2, 3 ])) + , test + "superlist in middle" + (assertEqual "Superlist" (sublist [ 5, 4, 3, 2, 1 ] [ 4, 3, 2 ])) + , test + "superlist at end" + (assertEqual "Superlist" (sublist [ 1, 2, 3, 4, 5 ] [ 3, 4, 5 ])) + , test + "partially matching superlist at start" + (assertEqual "Superlist" (sublist [ 1, 1, 1, 2 ] [ 1, 1, 2 ])) + , test + "superlist early in huge list" + (assertEqual "Superlist" (sublist [1..100000] [ 3, 4, 5 ])) + , test + "recurring values sublist" + (assertEqual "Sublist" (sublist [ 1, 2, 1, 2, 3 ] [ 1, 2, 3, 1, 2, 1, 2, 3, 2, 1 ])) + , test + "recurring values unequal" + (assertEqual "Unequal" (sublist [ 1, 2, 1, 2, 3 ] [ 1, 2, 3, 1, 2, 3, 2, 3, 2, 1 ])) + ] + + +port runner : Signal (Task.Task x ()) +port runner = + Console.run (consoleRunner tests) diff --git a/exercises/sublist/elm-package.json b/exercises/sublist/elm-package.json new file mode 100644 index 0000000..d93a035 --- /dev/null +++ b/exercises/sublist/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" +} diff --git a/exercises/sum-of-multiples/SumOfMultiples.elm b/exercises/sum-of-multiples/SumOfMultiples.elm new file mode 100644 index 0000000..c4c1dbd --- /dev/null +++ b/exercises/sum-of-multiples/SumOfMultiples.elm @@ -0,0 +1 @@ +module SumOfMultiples (..) where diff --git a/exercises/sum-of-multiples/SumOfMultiples.example b/exercises/sum-of-multiples/SumOfMultiples.example new file mode 100644 index 0000000..00cf585 --- /dev/null +++ b/exercises/sum-of-multiples/SumOfMultiples.example @@ -0,0 +1,11 @@ +module SumOfMultiples (..) where + + +sumOfMultiples : List Int -> Int -> Int +sumOfMultiples multiples limit = + List.sum (List.filter (inMultiples multiples) [1..(limit - 1)]) + + +inMultiples : List Int -> Int -> Bool +inMultiples multiples candidate = + List.any (\factor -> candidate % factor == 0) multiples diff --git a/exercises/sum-of-multiples/SumOfMultiplesTests.elm b/exercises/sum-of-multiples/SumOfMultiplesTests.elm new file mode 100644 index 0000000..35a6860 --- /dev/null +++ b/exercises/sum-of-multiples/SumOfMultiplesTests.elm @@ -0,0 +1,24 @@ +module Main (..) where + +import Task +import Console +import ElmTest exposing (..) +import SumOfMultiples exposing (sumOfMultiples) + + +tests : Test +tests = + suite + "Sum Of Multiples" + [ test "[3, 5] 15" (assertEqual 45 (sumOfMultiples [ 3, 5 ] 15)) + , test "[7, 13, 17] 20" (assertEqual 51 (sumOfMultiples [ 7, 13, 17 ] 20)) + , test "[4, 6] 15" (assertEqual 30 (sumOfMultiples [ 4, 6 ] 15)) + , test "[5, 6, 8] 150" (assertEqual 4419 (sumOfMultiples [ 5, 6, 8 ] 150)) + , test "[43, 47] 10000" (assertEqual 2203160 (sumOfMultiples [ 43, 47 ] 10000)) + , test "[5, 25] 51" (assertEqual 275 (sumOfMultiples [ 5, 25 ] 51)) + ] + + +port runner : Signal (Task.Task x ()) +port runner = + Console.run (consoleRunner tests) diff --git a/exercises/sum-of-multiples/elm-package.json b/exercises/sum-of-multiples/elm-package.json new file mode 100644 index 0000000..d93a035 --- /dev/null +++ b/exercises/sum-of-multiples/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" +}