From 6072ca7ff8d373c79642b0c79621317707c23400 Mon Sep 17 00:00:00 2001 From: Benjamin Watts Date: Sat, 12 Sep 2015 13:38:29 -0700 Subject: [PATCH 01/17] Accumulate --- Accumulate/AccumulateExample.elm | 7 +++++++ Accumulate/AccumulateTest.elm | 22 ++++++++++++++++++++++ config.json | 3 ++- elm-package.json | 4 +++- 4 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 Accumulate/AccumulateExample.elm create mode 100644 Accumulate/AccumulateTest.elm diff --git a/Accumulate/AccumulateExample.elm b/Accumulate/AccumulateExample.elm new file mode 100644 index 0000000..7e74982 --- /dev/null +++ b/Accumulate/AccumulateExample.elm @@ -0,0 +1,7 @@ +module AccumulateExample where + +accumulate : (a -> b) -> List a -> List b +accumulate func input = List.map func input + -- case input of + -- [] -> [] + -- otherwise -> diff --git a/Accumulate/AccumulateTest.elm b/Accumulate/AccumulateTest.elm new file mode 100644 index 0000000..ca4749f --- /dev/null +++ b/Accumulate/AccumulateTest.elm @@ -0,0 +1,22 @@ +module AccumulateTest where + +-- TODO - remove example inclusion once Problem sets are ready to go live or CI is set up. + +import AccumulateExample exposing (accumulate) +import ElmTest.Test exposing (test, Test, suite) +import ElmTest.Assertion exposing (assert, assertEqual) +import ElmTest.Runner.Element exposing (runDisplay) +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"])) + ] + +main = runDisplay tests diff --git a/config.json b/config.json index 8ed262c..f31c9c1 100644 --- a/config.json +++ b/config.json @@ -19,7 +19,8 @@ "run-length-encoding" ], "deprecated": [ - + "Leap", + "Accumulate" ], "ignored": [ "bin", diff --git a/elm-package.json b/elm-package.json index 3f469c1..5527a18 100644 --- a/elm-package.json +++ b/elm-package.json @@ -16,7 +16,9 @@ "./exercises/difference-of-squares", "./exercises/anagram", "./exercises/raindrops", - "./exercises/triangle" + "./exercises/triangle", + "Leap", + "Accumulate" ], "exposed-modules": [], "dependencies": { From 6917a05e8a5609efe0d4b519d0888656bccbd768 Mon Sep 17 00:00:00 2001 From: Claire Thompson and Gavin Morgan Date: Mon, 12 Oct 2015 09:46:15 -0700 Subject: [PATCH 02/17] Add Sublist example and test --- Sublist/SublistExample.elm | 23 +++++++++++++++++++++++ Sublist/SublistTest.elm | 33 +++++++++++++++++++++++++++++++++ elm-package.json | 3 ++- 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 Sublist/SublistExample.elm create mode 100644 Sublist/SublistTest.elm diff --git a/Sublist/SublistExample.elm b/Sublist/SublistExample.elm new file mode 100644 index 0000000..7e59cd3 --- /dev/null +++ b/Sublist/SublistExample.elm @@ -0,0 +1,23 @@ +module SublistExample where +import List exposing (..) +import String + +sublist : List a -> List a -> String +sublist alist blist = + if alist == blist then "Equal" else + if alist == [] then "Sublist" else + if blist == [] then "Superlist" 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/Sublist/SublistTest.elm b/Sublist/SublistTest.elm new file mode 100644 index 0000000..b18c342 --- /dev/null +++ b/Sublist/SublistTest.elm @@ -0,0 +1,33 @@ +module SublistTest where + +-- TODO - remove example inclusion once Problem sets are ready to go live or CI is set up. + +import ElmTest.Test exposing (test, Test, suite) +import ElmTest.Assertion exposing (assert, assertEqual) +import ElmTest.Runner.Element exposing (runDisplay) + +import SublistExample exposing (sublist) + +tests : Test +tests = suite "Sublist Test Suite" + [ 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])) + ] + +main = runDisplay tests diff --git a/elm-package.json b/elm-package.json index 5527a18..2d3817a 100644 --- a/elm-package.json +++ b/elm-package.json @@ -18,7 +18,8 @@ "./exercises/raindrops", "./exercises/triangle", "Leap", - "Accumulate" + "Accumulate", + "Sublist" ], "exposed-modules": [], "dependencies": { From 1cf5e3dd8475f09620d79823d62a1efae21f4c0f Mon Sep 17 00:00:00 2001 From: Claire Thompson and Tira Odhner Date: Tue, 13 Oct 2015 11:23:46 -0700 Subject: [PATCH 03/17] Add test and example for Sum of Multiples --- SumOfMultiples/SumOfMultiplesExample.elm | 9 +++++++++ SumOfMultiples/SumOfMultiplesTest.elm | 22 ++++++++++++++++++++++ elm-package.json | 5 ++++- 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 SumOfMultiples/SumOfMultiplesExample.elm create mode 100644 SumOfMultiples/SumOfMultiplesTest.elm diff --git a/SumOfMultiples/SumOfMultiplesExample.elm b/SumOfMultiples/SumOfMultiplesExample.elm new file mode 100644 index 0000000..c33a8a0 --- /dev/null +++ b/SumOfMultiples/SumOfMultiplesExample.elm @@ -0,0 +1,9 @@ +module SumOfMultiplesExample where + +sumOfMultiples : List Int -> Int -> Int +sumOfMultiples factors upperLimit = + List.sum (List.filter (isMultipleOfAnyFactor factors) [1 .. (upperLimit - 1)]) + +isMultipleOfAnyFactor : List Int -> Int -> Bool +isMultipleOfAnyFactor factors candidate = + List.any (\factor -> candidate % factor == 0) factors diff --git a/SumOfMultiples/SumOfMultiplesTest.elm b/SumOfMultiples/SumOfMultiplesTest.elm new file mode 100644 index 0000000..bfb962e --- /dev/null +++ b/SumOfMultiples/SumOfMultiplesTest.elm @@ -0,0 +1,22 @@ +module SumOfMultiplesTest where + +-- TODO - remove example inclusion once Problem sets are ready to go live or CI is set up. + +import ElmTest.Test exposing (test, Test, suite) +import ElmTest.Assertion exposing (assert, assertEqual) +import ElmTest.Runner.Element exposing (runDisplay) + +import SumOfMultiplesExample exposing (sumOfMultiples) + +tests : Test +tests = suite "Sum Of Multiples Test Suite" + [ 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)) + + ] + +main = runDisplay tests diff --git a/elm-package.json b/elm-package.json index 2d3817a..351b7dd 100644 --- a/elm-package.json +++ b/elm-package.json @@ -19,7 +19,10 @@ "./exercises/triangle", "Leap", "Accumulate", - "Sublist" + "RNATranscription", + "Sublist", + "Bob", + "sumOfMultiples" ], "exposed-modules": [], "dependencies": { From f4d9c99d7ab354bae99e8f22b7dac90c4ab32502 Mon Sep 17 00:00:00 2001 From: Claire Thompson and Tira Odhner Date: Tue, 13 Oct 2015 11:31:18 -0700 Subject: [PATCH 04/17] Remove unnecessary code from Sublist example --- Sublist/SublistExample.elm | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Sublist/SublistExample.elm b/Sublist/SublistExample.elm index 7e59cd3..f96f92a 100644 --- a/Sublist/SublistExample.elm +++ b/Sublist/SublistExample.elm @@ -5,10 +5,8 @@ import String sublist : List a -> List a -> String sublist alist blist = if alist == blist then "Equal" else - if alist == [] then "Sublist" else - if blist == [] then "Superlist" else - if inList alist blist then "Superlist" else - if inList blist alist then "Sublist" else "Unequal" + if inList alist blist then "Superlist" else + if inList blist alist then "Sublist" else "Unequal" inList : List a -> List a -> Bool inList alist blist = From 6f914735a47c2efab7343a81632a8cbcf77cc2dc Mon Sep 17 00:00:00 2001 From: Claire Thompson and Tira Odhner Date: Tue, 13 Oct 2015 11:56:46 -0700 Subject: [PATCH 05/17] Add test and example for Strain --- Strain/StrainExample.elm | 9 +++++++++ Strain/StrainTest.elm | 34 ++++++++++++++++++++++++++++++++++ elm-package.json | 3 ++- 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 Strain/StrainExample.elm create mode 100644 Strain/StrainTest.elm diff --git a/Strain/StrainExample.elm b/Strain/StrainExample.elm new file mode 100644 index 0000000..12454fa --- /dev/null +++ b/Strain/StrainExample.elm @@ -0,0 +1,9 @@ +module StrainExample where + +import List + +keep : (a -> Bool) -> List a -> List a +keep predicate list = List.filter predicate list + +discard : (a -> Bool) -> List a -> List a +discard predicate list = (keep (\val -> not (predicate val)) list) diff --git a/Strain/StrainTest.elm b/Strain/StrainTest.elm new file mode 100644 index 0000000..992581a --- /dev/null +++ b/Strain/StrainTest.elm @@ -0,0 +1,34 @@ +module StrainTest where + +-- TODO - remove example inclusion once Problem sets are ready to go live or CI is set up. + +import ElmTest.Test exposing (test, Test, suite) +import ElmTest.Assertion exposing (assert, assertEqual) +import ElmTest.Runner.Element exposing (runDisplay) + +import StrainExample exposing (keep, discard) + +import String + +even = \number -> number % 2 == 0 +odd = \number -> number % 2 == 1 +isFirstLetter = \letter-> \word -> (String.left 1 word) == letter +lessThanTen = \num -> num < 10 + +tests : Test +tests = suite "Strain Test Suite" + [ 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"])) + ] + +main = runDisplay tests diff --git a/elm-package.json b/elm-package.json index 351b7dd..6ef6088 100644 --- a/elm-package.json +++ b/elm-package.json @@ -22,7 +22,8 @@ "RNATranscription", "Sublist", "Bob", - "sumOfMultiples" + "SumOfMultiples", + "Strain" ], "exposed-modules": [], "dependencies": { From 556d32c4ecfe54a245ca371631b4e2e2403ddccb Mon Sep 17 00:00:00 2001 From: Claire Thompson Date: Wed, 16 Mar 2016 21:36:23 -0400 Subject: [PATCH 06/17] Add SpaceAge example and test --- SpaceAge/SpaceAgeExample.elm | 28 ++++++++++++++++++++++++++++ SpaceAge/SpaceAgeTest.elm | 25 +++++++++++++++++++++++++ elm-package.json | 3 ++- 3 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 SpaceAge/SpaceAgeExample.elm create mode 100644 SpaceAge/SpaceAgeTest.elm diff --git a/SpaceAge/SpaceAgeExample.elm b/SpaceAge/SpaceAgeExample.elm new file mode 100644 index 0000000..6e7fdd7 --- /dev/null +++ b/SpaceAge/SpaceAgeExample.elm @@ -0,0 +1,28 @@ +module SpaceAgeExample 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/SpaceAge/SpaceAgeTest.elm b/SpaceAge/SpaceAgeTest.elm new file mode 100644 index 0000000..6d60a45 --- /dev/null +++ b/SpaceAge/SpaceAgeTest.elm @@ -0,0 +1,25 @@ +module SpaceAgeTest where + +-- TODO - remove example inclusion once Problem sets are ready to go live or CI is set up. + +import ElmTest.Test exposing (test, Test, suite) +import ElmTest.Assertion exposing (assert, assertEqual) +import ElmTest.Runner.Element exposing (runDisplay) + +import SpaceAgeExample exposing (Planet(..), ageOn) + +tests : Test +tests = suite "SpaceAge Test Suite" + [ + 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))) + ] + + +main = runDisplay tests diff --git a/elm-package.json b/elm-package.json index 6ef6088..7b2b846 100644 --- a/elm-package.json +++ b/elm-package.json @@ -23,7 +23,8 @@ "Sublist", "Bob", "SumOfMultiples", - "Strain" + "Strain", + "SpaceAge" ], "exposed-modules": [], "dependencies": { From e6fbf7f8a800d08a238ecef90101976b41ca3824 Mon Sep 17 00:00:00 2001 From: Claire Thompson Date: Wed, 16 Mar 2016 21:36:38 -0400 Subject: [PATCH 07/17] Add NucleotideCount example and test --- NucleotideCount/NucleotideCountExample.elm | 15 +++++++++++++++ NucleotideCount/NucleotideCountTest.elm | 22 ++++++++++++++++++++++ elm-package.json | 4 +++- 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 NucleotideCount/NucleotideCountExample.elm create mode 100644 NucleotideCount/NucleotideCountTest.elm 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": { From 40a69d61d026ba1ba3241231e662fab08e4fe609 Mon Sep 17 00:00:00 2001 From: Claire Thompson Date: Tue, 13 Oct 2015 16:05:05 -0700 Subject: [PATCH 08/17] Add PhoneNumber example and test --- PhoneNumber/PhoneNumberExample.elm | 24 ++++++++++++++++++++++++ PhoneNumber/PhoneNumberTest.elm | 28 ++++++++++++++++++++++++++++ elm-package.json | 3 ++- 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 PhoneNumber/PhoneNumberExample.elm create mode 100644 PhoneNumber/PhoneNumberTest.elm diff --git a/PhoneNumber/PhoneNumberExample.elm b/PhoneNumber/PhoneNumberExample.elm new file mode 100644 index 0000000..c7a45d5 --- /dev/null +++ b/PhoneNumber/PhoneNumberExample.elm @@ -0,0 +1,24 @@ +module PhoneNumberExample where + +import String + +nums = ['1','2','3','4','5','6','7','8','9','0'] + +getNumber : String -> String +getNumber text = getValidNum (String.filter isDigit text) + +isDigit : Char -> Bool +isDigit char = List.any (\n -> n == char) nums + +getValidNum : String -> String +getValidNum num = + if String.length num == 10 then num else + if (String.length num == 11) && (String.left 1 num == "1") then String.dropLeft 1 num else + String.repeat 10 "0" + +printPretty : String -> String +printPretty input = 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/PhoneNumber/PhoneNumberTest.elm b/PhoneNumber/PhoneNumberTest.elm new file mode 100644 index 0000000..7657d38 --- /dev/null +++ b/PhoneNumber/PhoneNumberTest.elm @@ -0,0 +1,28 @@ +module PhoneNumberTest where + +-- TODO - remove example inclusion once Problem sets are ready to go live or CI is set up. + +import PhoneNumberExample exposing (getNumber, printPretty) + +import ElmTest.Test exposing (test, Test, suite) +import ElmTest.Assertion exposing (assert, assertEqual) +import ElmTest.Runner.Element exposing (runDisplay) + +tests : Test +tests = suite "PhoneNumber test suite" + [ + test "cleans number" (assertEqual "1234567890" (getNumber "(123) 456-7890")), + test "cleans number with dots" (assertEqual "1234567890" (getNumber "123.456.7890")), + test "valid when 11 digits and first is 1" (assertEqual "1234567890" (getNumber "11234567890")), + test "invalid when 11 digits" (assertEqual "0000000000" (getNumber "21234567890")), + test "invalid when 9 digits" (assertEqual "0000000000" (getNumber "123456789")), + test "invalid when 12 digits" (assertEqual "0000000000" (getNumber "123456789012")), + test "invalid when empty" (assertEqual "0000000000" (getNumber "")), + test "invalid when no digits present" (assertEqual "0000000000" (getNumber " (-) ")), + test "valid with leading characters" (assertEqual "1234567890" (getNumber "my number is 123 456 7890")), + test "valid with trailing characters" (assertEqual "1234567890" (getNumber "123 456 7890 - bob")), + test "pretty print" (assertEqual "(123) 456-7890" (printPretty "1234567890")), + test "pretty print with full us phone number" (assertEqual "(123) 456-7890" (printPretty "11234567890")) + ] + +main = runDisplay tests diff --git a/elm-package.json b/elm-package.json index 6eb0b95..0d6af7f 100644 --- a/elm-package.json +++ b/elm-package.json @@ -26,7 +26,8 @@ "Strain", "SpaceAge", "Anagram", - "NucleotideCount" + "NucleotideCount", + "PhoneNumber" ], "exposed-modules": [], "dependencies": { From 4b5ff7afb36a71bdf49098bab77b0f8cd51d5822 Mon Sep 17 00:00:00 2001 From: Claire Thompson Date: Wed, 14 Oct 2015 12:02:13 -0700 Subject: [PATCH 09/17] Add GradeSchool example and test --- GradeSchool/GradeSchoolExample.elm | 31 ++++++++++++++++++++++++++++++ GradeSchool/GradeSchoolTest.elm | 31 ++++++++++++++++++++++++++++++ elm-package.json | 3 ++- 3 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 GradeSchool/GradeSchoolExample.elm create mode 100644 GradeSchool/GradeSchoolTest.elm diff --git a/GradeSchool/GradeSchoolExample.elm b/GradeSchool/GradeSchoolExample.elm new file mode 100644 index 0000000..d71a261 --- /dev/null +++ b/GradeSchool/GradeSchoolExample.elm @@ -0,0 +1,31 @@ +module GradeSchoolExample where + +import Dict exposing (..) +import Result exposing (toMaybe) +-- TODO: implement these classes +-- type Grade = Int +-- type Student = String +-- type School = Dict Int List String + +schoolFromList : List (Int, String) -> Dict Int (List String) +schoolFromList schoolList = List.foldl (\tuple -> \dict -> addStudent (fst tuple) (snd tuple) dict) + newSchool schoolList + +schoolToList : Dict Int (List String) -> List (Int, List String) +schoolToList school = Dict.toList school + +newSchool : Dict Int (List String) +newSchool = Dict.empty + +addStudent : Int -> String -> Dict Int (List String) -> Dict Int (List String) +addStudent grade student school = + Dict.insert grade (List.sort (student :: (studentsInGrade grade school))) school + +gradeWithStudents : Int -> List String -> Dict Int (List String) +gradeWithStudents grade students = Dict.singleton grade (List.sort students) + +studentsInGrade : Int -> Dict Int (List String) -> List String +studentsInGrade grade school = + case (Dict.get grade school) of + Just list -> list + Nothing -> [] diff --git a/GradeSchool/GradeSchoolTest.elm b/GradeSchool/GradeSchoolTest.elm new file mode 100644 index 0000000..ad253bc --- /dev/null +++ b/GradeSchool/GradeSchoolTest.elm @@ -0,0 +1,31 @@ +module GradeSchoolTest where + +-- TODO - remove example inclusion once Problem sets are ready to go live or CI is set up. + +-- import GradeSchoolExample exposing (addStudent, +-- newSchool, gradeWithStudents, schoolFromList, +-- studentsInGrade, schoolToList) + +import GradeSchoolExample as S exposing (..) + +import ElmTest.Test exposing (test, Test, suite) +import ElmTest.Assertion exposing (assert, assertEqual) +import ElmTest.Runner.Element exposing (runDisplay) + +import Dict + +tests : Test +tests = suite "GradeSchool Test Suite" + [ + test "add student" (assertEqual [(2, ["Aimee"])] + (S.schoolToList (S.addStudent 2 "Aimee" S.newSchool))), + test "add more students in same class" (assertEqual [(2, ["Blair", "James", "Paul"])] + (S.schoolToList (S.gradeWithStudents 2 ["James", "Blair", "Paul"]))), + test "add students to different grades" (assertEqual [(3, ["Chelsea"]), (7, ["Logan"])] + (S.schoolToList (S.schoolFromList [(3, "Chelsea"), (7, "Logan")]))), + test "get students in a grade" (assertEqual ["Bradley", "Franklin"] + (S.studentsInGrade 5 (S.schoolFromList [(5, "Franklin"), (5, "Bradley"), (1, "Jeff")]))), + test "get students in a non-existent grade" (assertEqual [] (S.studentsInGrade 1 S.newSchool)) + ] + +main = runDisplay tests diff --git a/elm-package.json b/elm-package.json index 0d6af7f..f0c0019 100644 --- a/elm-package.json +++ b/elm-package.json @@ -27,7 +27,8 @@ "SpaceAge", "Anagram", "NucleotideCount", - "PhoneNumber" + "PhoneNumber", + "GradeSchool" ], "exposed-modules": [], "dependencies": { From 5bbeef52423bf535963807d99e95764e3960ee98 Mon Sep 17 00:00:00 2001 From: Erik Simmler Date: Wed, 16 Mar 2016 12:56:58 -0400 Subject: [PATCH 10/17] Align cherry picked exercises with the new directory structure --- .../accumulate/Accumulate.example | 0 .../accumulate/AccumulateTests.elm | 0 .../grade-school/GradeSchool.example | 0 .../grade-school/GradeSchoolTests.elm | 0 .../nucleotide-count/NucleotideCount.example | 0 .../nucleotide-count/NucleotideCountTests.elm | 0 .../phone-number/PhoneNumber.examples | 0 .../phone-number/PhoneNumberTests.elm | 0 .../SpaceAgeExample.elm => exercises/space-age/SpaceAge.example | 0 .../SpaceAgeTest.elm => exercises/space-age/SpaceAgeTests.elm | 0 Strain/StrainExample.elm => exercises/strain/Strain.example | 0 Strain/StrainTest.elm => exercises/strain/StrainTests.elm | 0 Sublist/SublistExample.elm => exercises/sublist/Sublist.example | 0 Sublist/SublistTest.elm => exercises/sublist/SublistTests.elm | 0 .../sum-of-multiples/SumOfMultiples.example | 0 .../sum-of-multiples/SumOfMultiplesTests.elm | 0 16 files changed, 0 insertions(+), 0 deletions(-) rename Accumulate/AccumulateExample.elm => exercises/accumulate/Accumulate.example (100%) rename Accumulate/AccumulateTest.elm => exercises/accumulate/AccumulateTests.elm (100%) rename GradeSchool/GradeSchoolExample.elm => exercises/grade-school/GradeSchool.example (100%) rename GradeSchool/GradeSchoolTest.elm => exercises/grade-school/GradeSchoolTests.elm (100%) rename NucleotideCount/NucleotideCountExample.elm => exercises/nucleotide-count/NucleotideCount.example (100%) rename NucleotideCount/NucleotideCountTest.elm => exercises/nucleotide-count/NucleotideCountTests.elm (100%) rename PhoneNumber/PhoneNumberExample.elm => exercises/phone-number/PhoneNumber.examples (100%) rename PhoneNumber/PhoneNumberTest.elm => exercises/phone-number/PhoneNumberTests.elm (100%) rename SpaceAge/SpaceAgeExample.elm => exercises/space-age/SpaceAge.example (100%) rename SpaceAge/SpaceAgeTest.elm => exercises/space-age/SpaceAgeTests.elm (100%) rename Strain/StrainExample.elm => exercises/strain/Strain.example (100%) rename Strain/StrainTest.elm => exercises/strain/StrainTests.elm (100%) rename Sublist/SublistExample.elm => exercises/sublist/Sublist.example (100%) rename Sublist/SublistTest.elm => exercises/sublist/SublistTests.elm (100%) rename SumOfMultiples/SumOfMultiplesExample.elm => exercises/sum-of-multiples/SumOfMultiples.example (100%) rename SumOfMultiples/SumOfMultiplesTest.elm => exercises/sum-of-multiples/SumOfMultiplesTests.elm (100%) diff --git a/Accumulate/AccumulateExample.elm b/exercises/accumulate/Accumulate.example similarity index 100% rename from Accumulate/AccumulateExample.elm rename to exercises/accumulate/Accumulate.example diff --git a/Accumulate/AccumulateTest.elm b/exercises/accumulate/AccumulateTests.elm similarity index 100% rename from Accumulate/AccumulateTest.elm rename to exercises/accumulate/AccumulateTests.elm diff --git a/GradeSchool/GradeSchoolExample.elm b/exercises/grade-school/GradeSchool.example similarity index 100% rename from GradeSchool/GradeSchoolExample.elm rename to exercises/grade-school/GradeSchool.example diff --git a/GradeSchool/GradeSchoolTest.elm b/exercises/grade-school/GradeSchoolTests.elm similarity index 100% rename from GradeSchool/GradeSchoolTest.elm rename to exercises/grade-school/GradeSchoolTests.elm diff --git a/NucleotideCount/NucleotideCountExample.elm b/exercises/nucleotide-count/NucleotideCount.example similarity index 100% rename from NucleotideCount/NucleotideCountExample.elm rename to exercises/nucleotide-count/NucleotideCount.example diff --git a/NucleotideCount/NucleotideCountTest.elm b/exercises/nucleotide-count/NucleotideCountTests.elm similarity index 100% rename from NucleotideCount/NucleotideCountTest.elm rename to exercises/nucleotide-count/NucleotideCountTests.elm diff --git a/PhoneNumber/PhoneNumberExample.elm b/exercises/phone-number/PhoneNumber.examples similarity index 100% rename from PhoneNumber/PhoneNumberExample.elm rename to exercises/phone-number/PhoneNumber.examples diff --git a/PhoneNumber/PhoneNumberTest.elm b/exercises/phone-number/PhoneNumberTests.elm similarity index 100% rename from PhoneNumber/PhoneNumberTest.elm rename to exercises/phone-number/PhoneNumberTests.elm diff --git a/SpaceAge/SpaceAgeExample.elm b/exercises/space-age/SpaceAge.example similarity index 100% rename from SpaceAge/SpaceAgeExample.elm rename to exercises/space-age/SpaceAge.example diff --git a/SpaceAge/SpaceAgeTest.elm b/exercises/space-age/SpaceAgeTests.elm similarity index 100% rename from SpaceAge/SpaceAgeTest.elm rename to exercises/space-age/SpaceAgeTests.elm diff --git a/Strain/StrainExample.elm b/exercises/strain/Strain.example similarity index 100% rename from Strain/StrainExample.elm rename to exercises/strain/Strain.example diff --git a/Strain/StrainTest.elm b/exercises/strain/StrainTests.elm similarity index 100% rename from Strain/StrainTest.elm rename to exercises/strain/StrainTests.elm diff --git a/Sublist/SublistExample.elm b/exercises/sublist/Sublist.example similarity index 100% rename from Sublist/SublistExample.elm rename to exercises/sublist/Sublist.example diff --git a/Sublist/SublistTest.elm b/exercises/sublist/SublistTests.elm similarity index 100% rename from Sublist/SublistTest.elm rename to exercises/sublist/SublistTests.elm diff --git a/SumOfMultiples/SumOfMultiplesExample.elm b/exercises/sum-of-multiples/SumOfMultiples.example similarity index 100% rename from SumOfMultiples/SumOfMultiplesExample.elm rename to exercises/sum-of-multiples/SumOfMultiples.example diff --git a/SumOfMultiples/SumOfMultiplesTest.elm b/exercises/sum-of-multiples/SumOfMultiplesTests.elm similarity index 100% rename from SumOfMultiples/SumOfMultiplesTest.elm rename to exercises/sum-of-multiples/SumOfMultiplesTests.elm From 5b8970a2db92b18b94730e66d4e9b1a052c27f1e Mon Sep 17 00:00:00 2001 From: Erik Simmler Date: Wed, 16 Mar 2016 21:38:35 -0400 Subject: [PATCH 11/17] Align cherry picked exercises with the new test format --- config.json | 36 +++++++++++-------- elm-package.json | 20 +++++------ exercises/accumulate/Accumulate.elm | 1 + exercises/accumulate/Accumulate.example | 9 +++-- exercises/accumulate/AccumulateTests.elm | 15 ++++---- exercises/accumulate/elm-package.json | 16 +++++++++ exercises/grade-school/GradeSchool.elm | 2 ++ exercises/grade-school/GradeSchool.example | 2 +- exercises/grade-school/GradeSchoolTests.elm | 21 +++++------ exercises/grade-school/elm-package.json | 16 +++++++++ .../nucleotide-count/NucleotideCount.elm | 1 + .../nucleotide-count/NucleotideCount.example | 2 +- .../nucleotide-count/NucleotideCountTests.elm | 16 ++++----- exercises/nucleotide-count/elm-package.json | 16 +++++++++ exercises/phone-number/PhoneNumber.elm | 1 + ...oneNumber.examples => PhoneNumber.example} | 2 +- exercises/phone-number/PhoneNumberTests.elm | 17 ++++----- exercises/phone-number/elm-package.json | 16 +++++++++ exercises/space-age/SpaceAge.elm | 1 + exercises/space-age/SpaceAge.example | 2 +- exercises/space-age/SpaceAgeTests.elm | 17 ++++----- exercises/space-age/elm-package.json | 16 +++++++++ exercises/strain/Strain.elm | 1 + exercises/strain/Strain.example | 2 +- exercises/strain/StrainTests.elm | 17 ++++----- exercises/strain/elm-package.json | 16 +++++++++ exercises/sublist/Sublist.elm | 1 + exercises/sublist/Sublist.example | 2 +- exercises/sublist/SublistTests.elm | 17 ++++----- exercises/sublist/elm-package.json | 16 +++++++++ exercises/sum-of-multiples/SumOfMultiples.elm | 1 + .../sum-of-multiples/SumOfMultiples.example | 2 +- .../sum-of-multiples/SumOfMultiplesTests.elm | 17 ++++----- exercises/sum-of-multiples/elm-package.json | 16 +++++++++ 34 files changed, 247 insertions(+), 106 deletions(-) create mode 100644 exercises/accumulate/Accumulate.elm create mode 100644 exercises/accumulate/elm-package.json create mode 100644 exercises/grade-school/GradeSchool.elm create mode 100644 exercises/grade-school/elm-package.json create mode 100644 exercises/nucleotide-count/NucleotideCount.elm create mode 100644 exercises/nucleotide-count/elm-package.json create mode 100644 exercises/phone-number/PhoneNumber.elm rename exercises/phone-number/{PhoneNumber.examples => PhoneNumber.example} (95%) create mode 100644 exercises/phone-number/elm-package.json create mode 100644 exercises/space-age/SpaceAge.elm create mode 100644 exercises/space-age/elm-package.json create mode 100644 exercises/strain/Strain.elm create mode 100644 exercises/strain/elm-package.json create mode 100644 exercises/sublist/Sublist.elm create mode 100644 exercises/sublist/elm-package.json create mode 100644 exercises/sum-of-multiples/SumOfMultiples.elm create mode 100644 exercises/sum-of-multiples/elm-package.json diff --git a/config.json b/config.json index f31c9c1..2b68954 100644 --- a/config.json +++ b/config.json @@ -5,22 +5,29 @@ "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": [ - "Leap", - "Accumulate" + ], "ignored": [ "bin", @@ -29,6 +36,5 @@ "docs" ], "foregone": [ - ] } diff --git a/elm-package.json b/elm-package.json index f0c0019..e6a166d 100644 --- a/elm-package.json +++ b/elm-package.json @@ -17,18 +17,14 @@ "./exercises/anagram", "./exercises/raindrops", "./exercises/triangle", - "Leap", - "Accumulate", - "RNATranscription", - "Sublist", - "Bob", - "SumOfMultiples", - "Strain", - "SpaceAge", - "Anagram", - "NucleotideCount", - "PhoneNumber", - "GradeSchool" + "./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 index 7e74982..7d39e27 100644 --- a/exercises/accumulate/Accumulate.example +++ b/exercises/accumulate/Accumulate.example @@ -1,7 +1,6 @@ -module AccumulateExample where +module Accumulate (..) where + accumulate : (a -> b) -> List a -> List b -accumulate func input = List.map func input - -- case input of - -- [] -> [] - -- otherwise -> +accumulate func input = + List.map func input diff --git a/exercises/accumulate/AccumulateTests.elm b/exercises/accumulate/AccumulateTests.elm index ca4749f..bdc482d 100644 --- a/exercises/accumulate/AccumulateTests.elm +++ b/exercises/accumulate/AccumulateTests.elm @@ -1,11 +1,10 @@ -module AccumulateTest where +module Main (..) where --- TODO - remove example inclusion once Problem sets are ready to go live or CI is set up. +import Task +import Console +import ElmTest exposing (..) +import Accumulate exposing (accumulate) -import AccumulateExample exposing (accumulate) -import ElmTest.Test exposing (test, Test, suite) -import ElmTest.Assertion exposing (assert, assertEqual) -import ElmTest.Runner.Element exposing (runDisplay) import String square : Int -> Int @@ -19,4 +18,6 @@ tests = suite "Accumulate" test "reverse Accumulate" (assertEqual ["olleh","dlrow"] (accumulate String.reverse ["hello" , "world"])) ] -main = runDisplay tests +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 index d71a261..62b2b07 100644 --- a/exercises/grade-school/GradeSchool.example +++ b/exercises/grade-school/GradeSchool.example @@ -1,4 +1,4 @@ -module GradeSchoolExample where +module GradeSchool (..) where import Dict exposing (..) import Result exposing (toMaybe) diff --git a/exercises/grade-school/GradeSchoolTests.elm b/exercises/grade-school/GradeSchoolTests.elm index ad253bc..5b7b266 100644 --- a/exercises/grade-school/GradeSchoolTests.elm +++ b/exercises/grade-school/GradeSchoolTests.elm @@ -1,16 +1,10 @@ -module GradeSchoolTest where +module Main (..) where --- TODO - remove example inclusion once Problem sets are ready to go live or CI is set up. +import Task +import Console +import ElmTest exposing (..) --- import GradeSchoolExample exposing (addStudent, --- newSchool, gradeWithStudents, schoolFromList, --- studentsInGrade, schoolToList) - -import GradeSchoolExample as S exposing (..) - -import ElmTest.Test exposing (test, Test, suite) -import ElmTest.Assertion exposing (assert, assertEqual) -import ElmTest.Runner.Element exposing (runDisplay) +import GradeSchool as S exposing (..) import Dict @@ -28,4 +22,7 @@ tests = suite "GradeSchool Test Suite" test "get students in a non-existent grade" (assertEqual [] (S.studentsInGrade 1 S.newSchool)) ] -main = runDisplay tests + +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/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 index 3d706df..09a5f18 100644 --- a/exercises/nucleotide-count/NucleotideCount.example +++ b/exercises/nucleotide-count/NucleotideCount.example @@ -1,4 +1,4 @@ -module NucleotideCountExample where +module NucleotideCount (..) where import String import List diff --git a/exercises/nucleotide-count/NucleotideCountTests.elm b/exercises/nucleotide-count/NucleotideCountTests.elm index 6a64bf9..af5816b 100644 --- a/exercises/nucleotide-count/NucleotideCountTests.elm +++ b/exercises/nucleotide-count/NucleotideCountTests.elm @@ -1,12 +1,10 @@ -module NucleotideCountTest where +module Main (..) where --- TODO - remove example inclusion once Problem sets are ready to go live or CI is set up. +import Task +import Console +import ElmTest exposing (..) -import NucleotideCountExample exposing (nucleotideCounts) - -import ElmTest.Test exposing (test, Test, suite) -import ElmTest.Assertion exposing (assert, assertEqual) -import ElmTest.Runner.Element exposing (runDisplay) +import NucleotideCount exposing (nucleotideCounts) tests : Test tests = suite "NucleotideCount test suite" @@ -19,4 +17,6 @@ tests = suite "NucleotideCount test suite" (nucleotideCounts "AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC")) ] -main = runDisplay tests +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.examples b/exercises/phone-number/PhoneNumber.example similarity index 95% rename from exercises/phone-number/PhoneNumber.examples rename to exercises/phone-number/PhoneNumber.example index c7a45d5..df545b5 100644 --- a/exercises/phone-number/PhoneNumber.examples +++ b/exercises/phone-number/PhoneNumber.example @@ -1,4 +1,4 @@ -module PhoneNumberExample where +module PhoneNumber (..) where import String diff --git a/exercises/phone-number/PhoneNumberTests.elm b/exercises/phone-number/PhoneNumberTests.elm index 7657d38..bcf349c 100644 --- a/exercises/phone-number/PhoneNumberTests.elm +++ b/exercises/phone-number/PhoneNumberTests.elm @@ -1,12 +1,10 @@ -module PhoneNumberTest where +module Main (..) where --- TODO - remove example inclusion once Problem sets are ready to go live or CI is set up. +import Task +import Console +import ElmTest exposing (..) -import PhoneNumberExample exposing (getNumber, printPretty) - -import ElmTest.Test exposing (test, Test, suite) -import ElmTest.Assertion exposing (assert, assertEqual) -import ElmTest.Runner.Element exposing (runDisplay) +import PhoneNumber exposing (getNumber, printPretty) tests : Test tests = suite "PhoneNumber test suite" @@ -25,4 +23,7 @@ tests = suite "PhoneNumber test suite" test "pretty print with full us phone number" (assertEqual "(123) 456-7890" (printPretty "11234567890")) ] -main = runDisplay tests +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..bb7abc5 --- /dev/null +++ b/exercises/space-age/SpaceAge.elm @@ -0,0 +1 @@ +module SpaceAge (..) where diff --git a/exercises/space-age/SpaceAge.example b/exercises/space-age/SpaceAge.example index 6e7fdd7..bb20926 100644 --- a/exercises/space-age/SpaceAge.example +++ b/exercises/space-age/SpaceAge.example @@ -1,4 +1,4 @@ -module SpaceAgeExample where +module SpaceAge (..) where type Planet = Mercury | Venus diff --git a/exercises/space-age/SpaceAgeTests.elm b/exercises/space-age/SpaceAgeTests.elm index 6d60a45..5b5f09e 100644 --- a/exercises/space-age/SpaceAgeTests.elm +++ b/exercises/space-age/SpaceAgeTests.elm @@ -1,12 +1,10 @@ -module SpaceAgeTest where +module Main (..) where --- TODO - remove example inclusion once Problem sets are ready to go live or CI is set up. +import Task +import Console +import ElmTest exposing (..) -import ElmTest.Test exposing (test, Test, suite) -import ElmTest.Assertion exposing (assert, assertEqual) -import ElmTest.Runner.Element exposing (runDisplay) - -import SpaceAgeExample exposing (Planet(..), ageOn) +import SpaceAge exposing (Planet(..), ageOn) tests : Test tests = suite "SpaceAge Test Suite" @@ -22,4 +20,7 @@ tests = suite "SpaceAge Test Suite" ] -main = runDisplay tests +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 index 12454fa..2ca47bb 100644 --- a/exercises/strain/Strain.example +++ b/exercises/strain/Strain.example @@ -1,4 +1,4 @@ -module StrainExample where +module Strain (..) where import List diff --git a/exercises/strain/StrainTests.elm b/exercises/strain/StrainTests.elm index 992581a..ca04c3b 100644 --- a/exercises/strain/StrainTests.elm +++ b/exercises/strain/StrainTests.elm @@ -1,12 +1,10 @@ -module StrainTest where +module Main (..) where --- TODO - remove example inclusion once Problem sets are ready to go live or CI is set up. +import Task +import Console +import ElmTest exposing (..) -import ElmTest.Test exposing (test, Test, suite) -import ElmTest.Assertion exposing (assert, assertEqual) -import ElmTest.Runner.Element exposing (runDisplay) - -import StrainExample exposing (keep, discard) +import Strain exposing (keep, discard) import String @@ -31,4 +29,7 @@ tests = suite "Strain Test Suite" test "discard strings" (assertEqual ["apple", "banana", "cherimoya"] (discard (isFirstLetter "z") ["apple", "zebra", "banana", "zombies", "cherimoya", "zealot"])) ] -main = runDisplay tests +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 index f96f92a..e253e80 100644 --- a/exercises/sublist/Sublist.example +++ b/exercises/sublist/Sublist.example @@ -1,4 +1,4 @@ -module SublistExample where +module Sublist (..) where import List exposing (..) import String diff --git a/exercises/sublist/SublistTests.elm b/exercises/sublist/SublistTests.elm index b18c342..2e59d28 100644 --- a/exercises/sublist/SublistTests.elm +++ b/exercises/sublist/SublistTests.elm @@ -1,12 +1,10 @@ -module SublistTest where +module Main (..) where --- TODO - remove example inclusion once Problem sets are ready to go live or CI is set up. +import Task +import Console +import ElmTest exposing (..) -import ElmTest.Test exposing (test, Test, suite) -import ElmTest.Assertion exposing (assert, assertEqual) -import ElmTest.Runner.Element exposing (runDisplay) - -import SublistExample exposing (sublist) +import Sublist exposing (sublist) tests : Test tests = suite "Sublist Test Suite" @@ -30,4 +28,7 @@ tests = suite "Sublist Test Suite" test "recurring values unequal" (assertEqual "Unequal" (sublist [1,2,1,2,3] [1,2,3,1,2,3,2,3,2,1])) ] -main = runDisplay tests +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 index c33a8a0..08bb6ac 100644 --- a/exercises/sum-of-multiples/SumOfMultiples.example +++ b/exercises/sum-of-multiples/SumOfMultiples.example @@ -1,4 +1,4 @@ -module SumOfMultiplesExample where +module SumOfMultiples (..) where sumOfMultiples : List Int -> Int -> Int sumOfMultiples factors upperLimit = diff --git a/exercises/sum-of-multiples/SumOfMultiplesTests.elm b/exercises/sum-of-multiples/SumOfMultiplesTests.elm index bfb962e..f4deef3 100644 --- a/exercises/sum-of-multiples/SumOfMultiplesTests.elm +++ b/exercises/sum-of-multiples/SumOfMultiplesTests.elm @@ -1,12 +1,10 @@ -module SumOfMultiplesTest where +module Main (..) where --- TODO - remove example inclusion once Problem sets are ready to go live or CI is set up. +import Task +import Console +import ElmTest exposing (..) -import ElmTest.Test exposing (test, Test, suite) -import ElmTest.Assertion exposing (assert, assertEqual) -import ElmTest.Runner.Element exposing (runDisplay) - -import SumOfMultiplesExample exposing (sumOfMultiples) +import SumOfMultiples exposing (sumOfMultiples) tests : Test tests = suite "Sum Of Multiples Test Suite" @@ -19,4 +17,7 @@ tests = suite "Sum Of Multiples Test Suite" ] -main = runDisplay tests +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" +} From 6e036afc7d9e20efd970f7d92a40ee28c45a146c Mon Sep 17 00:00:00 2001 From: Erik Simmler Date: Wed, 16 Mar 2016 21:38:51 -0400 Subject: [PATCH 12/17] Run elm-format over cherry picked exercises --- exercises/accumulate/AccumulateTests.elm | 29 +++++-- exercises/grade-school/GradeSchool.example | 35 ++++++-- exercises/grade-school/GradeSchoolTests.elm | 46 +++++++---- exercises/hello-world/HelloWorld.example | 3 +- .../nucleotide-count/NucleotideCount.example | 19 +++-- .../nucleotide-count/NucleotideCountTests.elm | 34 +++++--- exercises/phone-number/PhoneNumberTests.elm | 59 +++++++++---- exercises/space-age/SpaceAge.example | 60 +++++++++----- exercises/space-age/SpaceAgeTests.elm | 26 +++--- exercises/strain/Strain.example | 10 ++- exercises/strain/StrainTests.elm | 81 +++++++++++++----- exercises/sublist/Sublist.example | 34 +++++--- exercises/sublist/SublistTests.elm | 82 ++++++++++++++----- .../sum-of-multiples/SumOfMultiples.example | 14 ++-- .../sum-of-multiples/SumOfMultiplesTests.elm | 23 +++--- 15 files changed, 383 insertions(+), 172 deletions(-) diff --git a/exercises/accumulate/AccumulateTests.elm b/exercises/accumulate/AccumulateTests.elm index bdc482d..52932a5 100644 --- a/exercises/accumulate/AccumulateTests.elm +++ b/exercises/accumulate/AccumulateTests.elm @@ -4,19 +4,32 @@ import Task import Console import ElmTest exposing (..) import Accumulate exposing (accumulate) - import String + square : Int -> Int -square x = x * x +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"])) - ] +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 = diff --git a/exercises/grade-school/GradeSchool.example b/exercises/grade-school/GradeSchool.example index 62b2b07..7f2d201 100644 --- a/exercises/grade-school/GradeSchool.example +++ b/exercises/grade-school/GradeSchool.example @@ -2,30 +2,47 @@ module GradeSchool (..) where import Dict exposing (..) import Result exposing (toMaybe) + + -- TODO: implement these classes -- type Grade = Int -- type Student = String -- type School = Dict Int List String -schoolFromList : List (Int, String) -> Dict Int (List String) -schoolFromList schoolList = List.foldl (\tuple -> \dict -> addStudent (fst tuple) (snd tuple) dict) - newSchool schoolList -schoolToList : Dict Int (List String) -> List (Int, List String) -schoolToList school = Dict.toList school +schoolFromList : List ( Int, String ) -> Dict Int (List String) +schoolFromList schoolList = + List.foldl + (\tuple -> \dict -> addStudent (fst tuple) (snd tuple) dict) + newSchool + schoolList + + +schoolToList : Dict Int (List String) -> List ( Int, List String ) +schoolToList school = + Dict.toList school + newSchool : Dict Int (List String) -newSchool = Dict.empty +newSchool = + Dict.empty + addStudent : Int -> String -> Dict Int (List String) -> Dict Int (List String) addStudent grade student school = Dict.insert grade (List.sort (student :: (studentsInGrade grade school))) school + gradeWithStudents : Int -> List String -> Dict Int (List String) -gradeWithStudents grade students = Dict.singleton grade (List.sort students) +gradeWithStudents grade students = + Dict.singleton grade (List.sort students) + studentsInGrade : Int -> Dict Int (List String) -> List String studentsInGrade grade school = case (Dict.get grade school) of - Just list -> list - Nothing -> [] + Just list -> + list + + Nothing -> + [] diff --git a/exercises/grade-school/GradeSchoolTests.elm b/exercises/grade-school/GradeSchoolTests.elm index 5b7b266..3a5ec39 100644 --- a/exercises/grade-school/GradeSchoolTests.elm +++ b/exercises/grade-school/GradeSchoolTests.elm @@ -3,24 +3,42 @@ module Main (..) where import Task import Console import ElmTest exposing (..) - import GradeSchool as S exposing (..) - import Dict + tests : Test -tests = suite "GradeSchool Test Suite" - [ - test "add student" (assertEqual [(2, ["Aimee"])] - (S.schoolToList (S.addStudent 2 "Aimee" S.newSchool))), - test "add more students in same class" (assertEqual [(2, ["Blair", "James", "Paul"])] - (S.schoolToList (S.gradeWithStudents 2 ["James", "Blair", "Paul"]))), - test "add students to different grades" (assertEqual [(3, ["Chelsea"]), (7, ["Logan"])] - (S.schoolToList (S.schoolFromList [(3, "Chelsea"), (7, "Logan")]))), - test "get students in a grade" (assertEqual ["Bradley", "Franklin"] - (S.studentsInGrade 5 (S.schoolFromList [(5, "Franklin"), (5, "Bradley"), (1, "Jeff")]))), - test "get students in a non-existent grade" (assertEqual [] (S.studentsInGrade 1 S.newSchool)) - ] +tests = + suite + "GradeSchool" + [ test + "add student" + (assertEqual + [ ( 2, [ "Aimee" ] ) ] + (S.schoolToList (S.addStudent 2 "Aimee" S.newSchool)) + ) + , test + "add more students in same class" + (assertEqual + [ ( 2, [ "Blair", "James", "Paul" ] ) ] + (S.schoolToList (S.gradeWithStudents 2 [ "James", "Blair", "Paul" ])) + ) + , test + "add students to different grades" + (assertEqual + [ ( 3, [ "Chelsea" ] ), ( 7, [ "Logan" ] ) ] + (S.schoolToList (S.schoolFromList [ ( 3, "Chelsea" ), ( 7, "Logan" ) ])) + ) + , test + "get students in a grade" + (assertEqual + [ "Bradley", "Franklin" ] + (S.studentsInGrade 5 (S.schoolFromList [ ( 5, "Franklin" ), ( 5, "Bradley" ), ( 1, "Jeff" ) ])) + ) + , test + "get students in a non-existent grade" + (assertEqual [] (S.studentsInGrade 1 S.newSchool)) + ] port runner : Signal (Task.Task x ()) 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.example b/exercises/nucleotide-count/NucleotideCount.example index 09a5f18..7f6b88c 100644 --- a/exercises/nucleotide-count/NucleotideCount.example +++ b/exercises/nucleotide-count/NucleotideCount.example @@ -3,13 +3,16 @@ 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) + +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) + +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 index af5816b..4ab66c4 100644 --- a/exercises/nucleotide-count/NucleotideCountTests.elm +++ b/exercises/nucleotide-count/NucleotideCountTests.elm @@ -3,19 +3,33 @@ module Main (..) where import Task import Console import ElmTest exposing (..) - import NucleotideCount exposing (nucleotideCounts) + 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")) - ] +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 = diff --git a/exercises/phone-number/PhoneNumberTests.elm b/exercises/phone-number/PhoneNumberTests.elm index bcf349c..c0af62b 100644 --- a/exercises/phone-number/PhoneNumberTests.elm +++ b/exercises/phone-number/PhoneNumberTests.elm @@ -3,27 +3,52 @@ module Main (..) where import Task import Console import ElmTest exposing (..) - import PhoneNumber exposing (getNumber, printPretty) + tests : Test -tests = suite "PhoneNumber test suite" - [ - test "cleans number" (assertEqual "1234567890" (getNumber "(123) 456-7890")), - test "cleans number with dots" (assertEqual "1234567890" (getNumber "123.456.7890")), - test "valid when 11 digits and first is 1" (assertEqual "1234567890" (getNumber "11234567890")), - test "invalid when 11 digits" (assertEqual "0000000000" (getNumber "21234567890")), - test "invalid when 9 digits" (assertEqual "0000000000" (getNumber "123456789")), - test "invalid when 12 digits" (assertEqual "0000000000" (getNumber "123456789012")), - test "invalid when empty" (assertEqual "0000000000" (getNumber "")), - test "invalid when no digits present" (assertEqual "0000000000" (getNumber " (-) ")), - test "valid with leading characters" (assertEqual "1234567890" (getNumber "my number is 123 456 7890")), - test "valid with trailing characters" (assertEqual "1234567890" (getNumber "123 456 7890 - bob")), - test "pretty print" (assertEqual "(123) 456-7890" (printPretty "1234567890")), - test "pretty print with full us phone number" (assertEqual "(123) 456-7890" (printPretty "11234567890")) - ] +tests = + suite + "PhoneNumber" + [ test + "cleans number" + (assertEqual "1234567890" (getNumber "(123) 456-7890")) + , test + "cleans number with dots" + (assertEqual "1234567890" (getNumber "123.456.7890")) + , test + "valid when 11 digits and first is 1" + (assertEqual "1234567890" (getNumber "11234567890")) + , test + "invalid when 11 digits" + (assertEqual "0000000000" (getNumber "21234567890")) + , test + "invalid when 9 digits" + (assertEqual "0000000000" (getNumber "123456789")) + , test + "invalid when 12 digits" + (assertEqual "0000000000" (getNumber "123456789012")) + , test + "invalid when empty" + (assertEqual "0000000000" (getNumber "")) + , test + "invalid when no digits present" + (assertEqual "0000000000" (getNumber " (-) ")) + , test + "valid with leading characters" + (assertEqual "1234567890" (getNumber "my number is 123 456 7890")) + , test + "valid with trailing characters" + (assertEqual "1234567890" (getNumber "123 456 7890 - bob")) + , test + "pretty print" + (assertEqual "(123) 456-7890" (printPretty "1234567890")) + , test + "pretty print with full us phone number" + (assertEqual "(123) 456-7890" (printPretty "11234567890")) + ] + port runner : Signal (Task.Task x ()) port runner = Console.run (consoleRunner tests) - diff --git a/exercises/space-age/SpaceAge.example b/exercises/space-age/SpaceAge.example index bb20926..89241e0 100644 --- a/exercises/space-age/SpaceAge.example +++ b/exercises/space-age/SpaceAge.example @@ -1,28 +1,50 @@ module SpaceAge (..) where -type Planet = Mercury - | Venus - | Earth - | Mars - | Jupiter - | Saturn - | Uranus - | Neptune + +type Planet + = Mercury + | Venus + | Earth + | Mars + | Jupiter + | Saturn + | Uranus + | Neptune -earthYearInSeconds = 365.25 * 24 * 60 * 60 +earthYearInSeconds = + 365.25 * 24 * 60 * 60 + ageOn : Planet -> Float -> Float -ageOn planet seconds = seconds / (secondsPerYear planet) +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 + 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 index 5b5f09e..53114ab 100644 --- a/exercises/space-age/SpaceAgeTests.elm +++ b/exercises/space-age/SpaceAgeTests.elm @@ -3,24 +3,24 @@ module Main (..) where import Task import Console import ElmTest exposing (..) - import SpaceAge exposing (Planet(..), ageOn) + tests : Test -tests = suite "SpaceAge Test Suite" - [ - 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))) - ] +tests = + suite + "SpaceAge Test Suite" + [ 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/strain/Strain.example b/exercises/strain/Strain.example index 2ca47bb..3463040 100644 --- a/exercises/strain/Strain.example +++ b/exercises/strain/Strain.example @@ -2,8 +2,12 @@ module Strain (..) where import List -keep : (a -> Bool) -> List a -> List a -keep predicate list = List.filter predicate list + +keep : (a -> Bool) -> List a -> List a +keep predicate list = + List.filter predicate list + discard : (a -> Bool) -> List a -> List a -discard predicate list = (keep (\val -> not (predicate val)) list) +discard predicate list = + (keep (\val -> not (predicate val)) list) diff --git a/exercises/strain/StrainTests.elm b/exercises/strain/StrainTests.elm index ca04c3b..6695e9b 100644 --- a/exercises/strain/StrainTests.elm +++ b/exercises/strain/StrainTests.elm @@ -3,33 +3,72 @@ module Main (..) where import Task import Console import ElmTest exposing (..) - import Strain exposing (keep, discard) - import String -even = \number -> number % 2 == 0 -odd = \number -> number % 2 == 1 -isFirstLetter = \letter-> \word -> (String.left 1 word) == letter -lessThanTen = \num -> num < 10 + +even = + \number -> number % 2 == 0 + + +odd = + \number -> number % 2 == 1 + + +isFirstLetter = + \letter -> \word -> (String.left 1 word) == letter + + +lessThanTen = + \num -> num < 10 + tests : Test -tests = suite "Strain Test Suite" - [ 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"])) - ] +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/sublist/Sublist.example b/exercises/sublist/Sublist.example index e253e80..8cea41b 100644 --- a/exercises/sublist/Sublist.example +++ b/exercises/sublist/Sublist.example @@ -1,21 +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" + 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 -> [] + 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 + 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 index 2e59d28..aba6f6b 100644 --- a/exercises/sublist/SublistTests.elm +++ b/exercises/sublist/SublistTests.elm @@ -3,32 +3,70 @@ module Main (..) where import Task import Console import ElmTest exposing (..) - import Sublist exposing (sublist) + tests : Test -tests = suite "Sublist Test Suite" - [ 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])) - ] +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/sum-of-multiples/SumOfMultiples.example b/exercises/sum-of-multiples/SumOfMultiples.example index 08bb6ac..00cf585 100644 --- a/exercises/sum-of-multiples/SumOfMultiples.example +++ b/exercises/sum-of-multiples/SumOfMultiples.example @@ -1,9 +1,11 @@ module SumOfMultiples (..) where -sumOfMultiples : List Int -> Int -> Int -sumOfMultiples factors upperLimit = - List.sum (List.filter (isMultipleOfAnyFactor factors) [1 .. (upperLimit - 1)]) -isMultipleOfAnyFactor : List Int -> Int -> Bool -isMultipleOfAnyFactor factors candidate = - List.any (\factor -> candidate % factor == 0) factors +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 index f4deef3..35a6860 100644 --- a/exercises/sum-of-multiples/SumOfMultiplesTests.elm +++ b/exercises/sum-of-multiples/SumOfMultiplesTests.elm @@ -3,21 +3,22 @@ module Main (..) where import Task import Console import ElmTest exposing (..) - import SumOfMultiples exposing (sumOfMultiples) -tests : Test -tests = suite "Sum Of Multiples Test Suite" - [ 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)) - ] +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) - From 3b6ba9da5ac9b7d0957503199cf797bb8c4d2870 Mon Sep 17 00:00:00 2001 From: Erik Simmler Date: Wed, 16 Mar 2016 20:20:10 -0400 Subject: [PATCH 13/17] Revise accumulate example (the directions specifically forbid using map!) --- exercises/accumulate/Accumulate.example | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/accumulate/Accumulate.example b/exercises/accumulate/Accumulate.example index 7d39e27..b1630c3 100644 --- a/exercises/accumulate/Accumulate.example +++ b/exercises/accumulate/Accumulate.example @@ -3,4 +3,4 @@ module Accumulate (..) where accumulate : (a -> b) -> List a -> List b accumulate func input = - List.map func input + List.foldr (\v c -> func v :: c) [] input From 6b79102bac70dfa2f10475e3b8d036d1d41680c6 Mon Sep 17 00:00:00 2001 From: Erik Simmler Date: Wed, 16 Mar 2016 21:16:54 -0400 Subject: [PATCH 14/17] Revise grade-school to match up with the exercise description --- exercises/grade-school/GradeSchool.example | 38 ++++++--------- exercises/grade-school/GradeSchoolTests.elm | 51 +++++++++++++++++---- 2 files changed, 56 insertions(+), 33 deletions(-) diff --git a/exercises/grade-school/GradeSchool.example b/exercises/grade-school/GradeSchool.example index 7f2d201..11af7ec 100644 --- a/exercises/grade-school/GradeSchool.example +++ b/exercises/grade-school/GradeSchool.example @@ -1,44 +1,31 @@ module GradeSchool (..) where import Dict exposing (..) -import Result exposing (toMaybe) --- TODO: implement these classes --- type Grade = Int --- type Student = String --- type School = Dict Int List String +type alias Grade = + Int -schoolFromList : List ( Int, String ) -> Dict Int (List String) -schoolFromList schoolList = - List.foldl - (\tuple -> \dict -> addStudent (fst tuple) (snd tuple) dict) - newSchool - schoolList +type alias Student = + String -schoolToList : Dict Int (List String) -> List ( Int, List String ) -schoolToList school = - Dict.toList school +type alias School = + Dict Int (List Student) -newSchool : Dict Int (List String) -newSchool = +empty : School +empty = Dict.empty -addStudent : Int -> String -> Dict Int (List String) -> Dict Int (List String) +addStudent : Grade -> Student -> School -> School addStudent grade student school = Dict.insert grade (List.sort (student :: (studentsInGrade grade school))) school -gradeWithStudents : Int -> List String -> Dict Int (List String) -gradeWithStudents grade students = - Dict.singleton grade (List.sort students) - - -studentsInGrade : Int -> Dict Int (List String) -> List String +studentsInGrade : Grade -> School -> List Student studentsInGrade grade school = case (Dict.get grade school) of Just list -> @@ -46,3 +33,8 @@ studentsInGrade grade school = 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 index 3a5ec39..d5d37df 100644 --- a/exercises/grade-school/GradeSchoolTests.elm +++ b/exercises/grade-school/GradeSchoolTests.elm @@ -3,8 +3,7 @@ module Main (..) where import Task import Console import ElmTest exposing (..) -import GradeSchool as S exposing (..) -import Dict +import GradeSchool exposing (addStudent, studentsInGrade, allStudents) tests : Test @@ -14,30 +13,62 @@ tests = [ test "add student" (assertEqual - [ ( 2, [ "Aimee" ] ) ] - (S.schoolToList (S.addStudent 2 "Aimee" S.newSchool)) + [ "Aimee" ] + (GradeSchool.empty + |> addStudent 2 "Aimee" + |> studentsInGrade 2 + ) ) , test "add more students in same class" (assertEqual - [ ( 2, [ "Blair", "James", "Paul" ] ) ] - (S.schoolToList (S.gradeWithStudents 2 [ "James", "Blair", "Paul" ])) + [ "Blair", "James", "Paul" ] + (GradeSchool.empty + |> addStudent 2 "James" + |> addStudent 2 "Blair" + |> addStudent 2 "Paul" + |> studentsInGrade 2 + ) ) , test "add students to different grades" (assertEqual - [ ( 3, [ "Chelsea" ] ), ( 7, [ "Logan" ] ) ] - (S.schoolToList (S.schoolFromList [ ( 3, "Chelsea" ), ( 7, "Logan" ) ])) + [ [ "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" ] - (S.studentsInGrade 5 (S.schoolFromList [ ( 5, "Franklin" ), ( 5, "Bradley" ), ( 1, "Jeff" ) ])) + (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 [] (S.studentsInGrade 1 S.newSchool)) + (assertEqual [] (studentsInGrade 1 GradeSchool.empty)) ] From 90e7d8837461d9bb424114907d4d2a8ab110e5ae Mon Sep 17 00:00:00 2001 From: Erik Simmler Date: Wed, 16 Mar 2016 21:33:59 -0400 Subject: [PATCH 15/17] Revise phone-number to use Maybe --- exercises/phone-number/PhoneNumber.example | 42 +++++++++++++++------ exercises/phone-number/PhoneNumberTests.elm | 26 ++++++------- 2 files changed, 44 insertions(+), 24 deletions(-) diff --git a/exercises/phone-number/PhoneNumber.example b/exercises/phone-number/PhoneNumber.example index df545b5..c5271a3 100644 --- a/exercises/phone-number/PhoneNumber.example +++ b/exercises/phone-number/PhoneNumber.example @@ -2,23 +2,43 @@ module PhoneNumber (..) where import String -nums = ['1','2','3','4','5','6','7','8','9','0'] -getNumber : String -> String -getNumber text = getValidNum (String.filter isDigit text) +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 +isDigit char = + List.any (\n -> n == char) nums -getValidNum : String -> String + +getValidNum : String -> Maybe String getValidNum num = - if String.length num == 10 then num else - if (String.length num == 11) && (String.left 1 num == "1") then String.dropLeft 1 num else - String.repeat 10 "0" + 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 -printPretty : String -> String -printPretty input = formatNumber (getNumber input) + +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)] +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 index c0af62b..1a116dd 100644 --- a/exercises/phone-number/PhoneNumberTests.elm +++ b/exercises/phone-number/PhoneNumberTests.elm @@ -3,7 +3,7 @@ module Main (..) where import Task import Console import ElmTest exposing (..) -import PhoneNumber exposing (getNumber, printPretty) +import PhoneNumber exposing (getNumber, prettyPrint) tests : Test @@ -12,40 +12,40 @@ tests = "PhoneNumber" [ test "cleans number" - (assertEqual "1234567890" (getNumber "(123) 456-7890")) + (assertEqual (Just "1234567890") (getNumber "(123) 456-7890")) , test "cleans number with dots" - (assertEqual "1234567890" (getNumber "123.456.7890")) + (assertEqual (Just "1234567890") (getNumber "123.456.7890")) , test "valid when 11 digits and first is 1" - (assertEqual "1234567890" (getNumber "11234567890")) + (assertEqual (Just "1234567890") (getNumber "11234567890")) , test "invalid when 11 digits" - (assertEqual "0000000000" (getNumber "21234567890")) + (assertEqual Nothing (getNumber "21234567890")) , test "invalid when 9 digits" - (assertEqual "0000000000" (getNumber "123456789")) + (assertEqual Nothing (getNumber "123456789")) , test "invalid when 12 digits" - (assertEqual "0000000000" (getNumber "123456789012")) + (assertEqual Nothing (getNumber "123456789012")) , test "invalid when empty" - (assertEqual "0000000000" (getNumber "")) + (assertEqual Nothing (getNumber "")) , test "invalid when no digits present" - (assertEqual "0000000000" (getNumber " (-) ")) + (assertEqual Nothing (getNumber " (-) ")) , test "valid with leading characters" - (assertEqual "1234567890" (getNumber "my number is 123 456 7890")) + (assertEqual (Just "1234567890") (getNumber "my number is 123 456 7890")) , test "valid with trailing characters" - (assertEqual "1234567890" (getNumber "123 456 7890 - bob")) + (assertEqual (Just "1234567890") (getNumber "123 456 7890 - bob")) , test "pretty print" - (assertEqual "(123) 456-7890" (printPretty "1234567890")) + (assertEqual (Just "(123) 456-7890") (prettyPrint "1234567890")) , test "pretty print with full us phone number" - (assertEqual "(123) 456-7890" (printPretty "11234567890")) + (assertEqual (Just "(123) 456-7890") (prettyPrint "11234567890")) ] From c4e8aea66a59da012e0bb6fe7f5b40986f0730e7 Mon Sep 17 00:00:00 2001 From: Erik Simmler Date: Wed, 16 Mar 2016 21:44:54 -0400 Subject: [PATCH 16/17] Clarify the space-age test requirements --- exercises/space-age/SpaceAge.elm | 10 ++++++++ exercises/space-age/SpaceAgeTests.elm | 34 ++++++++++++++++++++------- 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/exercises/space-age/SpaceAge.elm b/exercises/space-age/SpaceAge.elm index bb7abc5..86aac4c 100644 --- a/exercises/space-age/SpaceAge.elm +++ b/exercises/space-age/SpaceAge.elm @@ -1 +1,11 @@ module SpaceAge (..) where + +type Planet + = Mercury + | Venus + | Earth + | Mars + | Jupiter + | Saturn + | Uranus + | Neptune diff --git a/exercises/space-age/SpaceAgeTests.elm b/exercises/space-age/SpaceAgeTests.elm index 53114ab..3734264 100644 --- a/exercises/space-age/SpaceAgeTests.elm +++ b/exercises/space-age/SpaceAgeTests.elm @@ -9,15 +9,31 @@ import SpaceAge exposing (Planet(..), ageOn) tests : Test tests = suite - "SpaceAge Test Suite" - [ 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))) + "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))) ] From 654a5b83bf9477a3a14286c3ebf4911f41120832 Mon Sep 17 00:00:00 2001 From: Erik Simmler Date: Wed, 16 Mar 2016 21:52:25 -0400 Subject: [PATCH 17/17] =?UTF-8?q?Revise=20strain=20exercise=E2=80=A6=20the?= =?UTF-8?q?=20description=20forbids=20using=20filter!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- exercises/strain/Strain.example | 12 ++++- exercises/strain/StrainTests.elm | 75 ++++++++++++++++++++++++-------- 2 files changed, 66 insertions(+), 21 deletions(-) diff --git a/exercises/strain/Strain.example b/exercises/strain/Strain.example index 3463040..3865e38 100644 --- a/exercises/strain/Strain.example +++ b/exercises/strain/Strain.example @@ -5,9 +5,17 @@ import List keep : (a -> Bool) -> List a -> List a keep predicate list = - List.filter predicate list + List.foldr (consIf predicate) [] list discard : (a -> Bool) -> List a -> List a discard predicate list = - (keep (\val -> not (predicate val)) 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 index 6695e9b..ebc0337 100644 --- a/exercises/strain/StrainTests.elm +++ b/exercises/strain/StrainTests.elm @@ -7,20 +7,24 @@ import Strain exposing (keep, discard) import String -even = - \number -> number % 2 == 0 +even : Int -> Bool +even number = + number % 2 == 0 -odd = - \number -> number % 2 == 1 +odd : Int -> Bool +odd number = + number % 2 == 1 -isFirstLetter = - \letter -> \word -> (String.left 1 word) == letter +isFirstLetter : String -> String -> Bool +isFirstLetter letter word = + (String.left 1 word) == letter -lessThanTen = - \num -> num < 10 +lessThanTen : number -> Bool +lessThanTen num = + num < 10 tests : Test @@ -29,19 +33,34 @@ tests = "Strain" [ test "empty keep" - (assertEqual [] (keep lessThanTen [])) + (assertEqual + [] + (keep lessThanTen []) + ) , test "keep everything" - (assertEqual [ 1, 2, 3 ] (keep lessThanTen [ 1, 2, 3 ])) + (assertEqual + [ 1, 2, 3 ] + (keep lessThanTen [ 1, 2, 3 ]) + ) , test "keep first and last" - (assertEqual [ 1, 3 ] (keep odd [ 1, 2, 3 ])) + (assertEqual + [ 1, 3 ] + (keep odd [ 1, 2, 3 ]) + ) , test "keep nothing" - (assertEqual [] (keep even [ 1, 3, 5, 7 ])) + (assertEqual + [] + (keep even [ 1, 3, 5, 7 ]) + ) , test "keep neither first nor last" - (assertEqual [ 2 ] (keep even [ 1, 2, 3 ])) + (assertEqual + [ 2 ] + (keep even [ 1, 2, 3 ]) + ) , test "keep strings" (assertEqual @@ -50,22 +69,40 @@ tests = ) , test "empty discard" - (assertEqual [] (discard lessThanTen [])) + (assertEqual + [] + (discard lessThanTen []) + ) , test "discard everything" - (assertEqual [] (discard lessThanTen [ 1, 2, 3 ])) + (assertEqual + [] + (discard lessThanTen [ 1, 2, 3 ]) + ) , test "discard first and last" - (assertEqual [ 2 ] (discard odd [ 1, 2, 3 ])) + (assertEqual + [ 2 ] + (discard odd [ 1, 2, 3 ]) + ) , test "discard nothing" - (assertEqual [ 1, 3, 5, 7 ] (discard even [ 1, 3, 5, 7 ])) + (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 ])) + (assertEqual + [ 1, 3 ] + (discard even [ 1, 2, 3 ]) + ) , test "discard strings" - (assertEqual [ "apple", "banana", "cherimoya" ] (discard (isFirstLetter "z") [ "apple", "zebra", "banana", "zombies", "cherimoya", "zealot" ])) + (assertEqual + [ "apple", "banana", "cherimoya" ] + (discard (isFirstLetter "z") [ "apple", "zebra", "banana", "zombies", "cherimoya", "zealot" ]) + ) ]