Update to elm-test 2.0 (#96)

* Update exercises to elm-test 2.0

* Update docs to mention `elm-test` again

* Update .travis.yml to the correct version of elm-test

* Conform to the `<| \() ->` convention
This commit is contained in:
Erik Simmler 2016-08-17 07:14:17 -04:00 committed by GitHub
parent 4999d42ab5
commit 54e3017815
118 changed files with 1441 additions and 1238 deletions

View file

@ -5,9 +5,9 @@ language: bash
sudo: false sudo: false
install: install:
- nvm install 0.12 - nvm install 6
- nvm use 0.12 - nvm use 6
- npm install -g elm@0.17.0 elm-test@0.16.1-alpha4 - npm install -g elm@0.17.1 elm-test@0.17.1
- elm package install -y - elm package install -y
script: script:

View file

@ -12,7 +12,8 @@ do
echo '-------------------------------------------------------' echo '-------------------------------------------------------'
echo "Testing $exercise" echo "Testing $exercise"
elm-make $exercise_dir/*Tests.elm --yes --output build.js && node build.js elm-package install
elm-test $exercise_dir/*Tests.elm
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
TEST_RESULT=1 TEST_RESULT=1

View file

@ -2,8 +2,8 @@
The simplest way to install Elm is via Node.js/NPM. The simplest way to install Elm is via Node.js/NPM.
If you don't already have Node.js installed on your computer, you can download it from [the official site](https://nodejs.org/). Once you have Node.js up and running, follow these steps to install the Elm platform. If you don't already have Node.js installed on your computer, you can download it from [the official site](https://nodejs.org/). Once you have Node.js up and running, follow these steps to install the Elm platform and `elm-test`.
```bash ```bash
$ npm install --global elm $ npm install --global elm elm-test
``` ```

View file

@ -1,8 +1,8 @@
Elm exercises within your exercism project directory can be run by changing to the exercise directory, and running `./runtests.sh` (or `runtests.bat` on Windows). The Elm exercise test suites may be run from the exercise directory.
```bash ```bash
$ cd exercism/project/directory/elm/hello-world $ cd exercism/project/directory/elm/hello-world
$ ./runtests.sh $ elm-test *Tests.elm
``` ```
## Hints and tips ## Hints and tips

View file

@ -36,8 +36,9 @@
], ],
"exposed-modules": [], "exposed-modules": [],
"dependencies": { "dependencies": {
"elm-community/elm-test": "1.0.0 <= v < 2.0.0", "elm-lang/core": "4.0.0 <= v < 5.0.0",
"elm-lang/core": "4.0.0 <= v < 5.0.0" "elm-community/elm-test": "2.0.0 <= v < 3.0.0",
"rtfeldman/node-test-runner": "1.0.0 <= v < 2.0.0"
}, },
"elm-version": "0.17.0 <= v < 0.18.0" "elm-version": "0.17.0 <= v < 0.18.0"
} }

View file

@ -1,6 +1,9 @@
module Main exposing (..) port module Main exposing (..)
import ElmTest exposing (..) import Test.Runner.Node exposing (run)
import Json.Encode exposing (Value)
import Test exposing (..)
import Expect
import Accumulate exposing (accumulate) import Accumulate exposing (accumulate)
import String import String
@ -12,18 +15,25 @@ square x =
tests : Test tests : Test
tests = tests =
suite "Accumulate" describe "Accumulate"
[ test "[]] Accumulate" [ test "[]] Accumulate" <|
(assertEqual [] (accumulate square [])) \() -> Expect.equal [] (accumulate square [])
, test "square Accumulate" , test "square Accumulate" <|
(assertEqual [ 1, 4, 9 ] (accumulate square [ 1, 2, 3 ])) \() -> Expect.equal [ 1, 4, 9 ] (accumulate square [ 1, 2, 3 ])
, test "toUpper Accumulate" , test "toUpper Accumulate" <|
(assertEqual [ "HELLO", "WORLD" ] (accumulate String.toUpper [ "hello", "world" ])) \() ->
, test "reverse Accumulate" Expect.equal [ "HELLO", "WORLD" ]
(assertEqual [ "olleh", "dlrow" ] (accumulate String.reverse [ "hello", "world" ])) (accumulate String.toUpper [ "hello", "world" ])
, test "reverse Accumulate" <|
\() ->
Expect.equal [ "olleh", "dlrow" ]
(accumulate String.reverse [ "hello", "world" ])
] ]
main : Program Never main : Program Never
main = main =
runSuite tests run emit tests
port emit : ( String, Value ) -> Cmd msg

View file

@ -1,5 +1,5 @@
{ {
"version": "2.0.0", "version": "3.0.0",
"summary": "Exercism problems in Elm.", "summary": "Exercism problems in Elm.",
"repository": "https://github.com/exercism/xelm.git", "repository": "https://github.com/exercism/xelm.git",
"license": "BSD3", "license": "BSD3",
@ -8,8 +8,9 @@
], ],
"exposed-modules": [], "exposed-modules": [],
"dependencies": { "dependencies": {
"elm-community/elm-test": "1.0.0 <= v < 2.0.0", "elm-lang/core": "4.0.0 <= v < 5.0.0",
"elm-lang/core": "4.0.0 <= v < 5.0.0" "elm-community/elm-test": "2.0.0 <= v < 3.0.0",
"rtfeldman/node-test-runner": "1.0.0 <= v < 2.0.0"
}, },
"elm-version": "0.17.0 <= v < 0.18.0" "elm-version": "0.17.0 <= v < 0.18.0"
} }

View file

@ -1,4 +0,0 @@
@echo off
for %%f in (*Tests.elm) do (
elm-make %%f --yes --output build.js && node build.js
)

View file

@ -1,2 +0,0 @@
#!/usr/bin/env bash
elm-make *Tests.elm --yes --output build.js && node build.js

View file

@ -1,52 +1,58 @@
module Main exposing (..) port module Main exposing (..)
import ElmTest exposing (..) import Test.Runner.Node exposing (run)
import Json.Encode exposing (Value)
import Test exposing (..)
import Expect
import Allergies exposing (isAllergicTo, toList) import Allergies exposing (isAllergicTo, toList)
import List import List
tests : Test tests : Test
tests = tests =
suite "Allergies" describe "Allergies"
[ suite "isAllergicTo" [ describe "isAllergicTo"
[ suite "no allergies means not allergic" [ describe "no allergies means not allergic"
[ test "peanuts" [ test "peanuts" <|
(assert (not (isAllergicTo "peanuts" 0))) \() -> Expect.equal False (isAllergicTo "peanuts" 0)
, test "cats" , test "cats" <|
(assert (not (isAllergicTo "cats" 0))) \() -> Expect.equal False (isAllergicTo "cats" 0)
, test "strawberries" , test "strawberries" <|
(assert (not (isAllergicTo "strawberries" 0))) \() -> Expect.equal False (isAllergicTo "strawberries" 0)
] ]
, test "is allergic to eggs" , test "is allergic to eggs" <|
(assert (isAllergicTo "eggs" 1)) \() -> Expect.equal True (isAllergicTo "eggs" 1)
, suite "has the right allergies" , describe "has the right allergies"
[ test "eggs" [ test "eggs" <|
(assert (isAllergicTo "eggs" 5)) \() -> Expect.equal True (isAllergicTo "eggs" 5)
, test "shellfish" , test "shellfish" <|
(assert (isAllergicTo "shellfish" 5)) \() -> Expect.equal True (isAllergicTo "shellfish" 5)
, test "strawberries" , test "strawberries" <|
(assert (not (isAllergicTo "strawberries" 5))) \() -> Expect.equal False (isAllergicTo "strawberries" 5)
] ]
] ]
, suite "toList" , describe "toList"
[ test "no allergies at all" [ test "no allergies at all" <|
(assertEqual [] (toList (0))) \() -> Expect.equal [] (toList (0))
, test "allergic to just peanuts" , test "allergic to just peanuts" <|
(assertEqual [ "peanuts" ] (toList (2))) \() -> Expect.equal [ "peanuts" ] (toList (2))
, test "allergic to everything" , test "allergic to everything" <|
(assertEqual (List.sort [ "eggs", "peanuts", "shellfish", "strawberries", "tomatoes", "chocolate", "pollen", "cats" ]) \() ->
(255 |> toList |> List.sort) Expect.equal (List.sort [ "eggs", "peanuts", "shellfish", "strawberries", "tomatoes", "chocolate", "pollen", "cats" ])
) (255 |> toList |> List.sort)
, test "ignore non allergen score parts" , test "ignore non allergen score parts" <|
(assertEqual [ "eggs" ] (toList 257)) \() -> Expect.equal [ "eggs" ] (toList 257)
, test "ignore non allergen score parts" , test "ignore non allergen score parts" <|
(assertEqual (List.sort [ "eggs", "shellfish", "strawberries", "tomatoes", "chocolate", "pollen", "cats" ]) \() ->
(509 |> toList |> List.sort) Expect.equal (List.sort [ "eggs", "shellfish", "strawberries", "tomatoes", "chocolate", "pollen", "cats" ])
) (509 |> toList |> List.sort)
] ]
] ]
main : Program Never main : Program Never
main = main =
runSuite tests run emit tests
port emit : ( String, Value ) -> Cmd msg

View file

@ -1,5 +1,5 @@
{ {
"version": "2.0.0", "version": "3.0.0",
"summary": "Exercism problems in Elm.", "summary": "Exercism problems in Elm.",
"repository": "https://github.com/exercism/xelm.git", "repository": "https://github.com/exercism/xelm.git",
"license": "BSD3", "license": "BSD3",
@ -8,8 +8,9 @@
], ],
"exposed-modules": [], "exposed-modules": [],
"dependencies": { "dependencies": {
"elm-community/elm-test": "1.0.0 <= v < 2.0.0", "elm-lang/core": "4.0.0 <= v < 5.0.0",
"elm-lang/core": "4.0.0 <= v < 5.0.0" "elm-community/elm-test": "2.0.0 <= v < 3.0.0",
"rtfeldman/node-test-runner": "1.0.0 <= v < 2.0.0"
}, },
"elm-version": "0.17.0 <= v < 0.18.0" "elm-version": "0.17.0 <= v < 0.18.0"
} }

View file

@ -1,4 +0,0 @@
@echo off
for %%f in (*Tests.elm) do (
elm-make %%f --yes --output build.js && node build.js
)

View file

@ -1,2 +0,0 @@
#!/usr/bin/env bash
elm-make *Tests.elm --yes --output build.js && node build.js

View file

@ -1,95 +1,101 @@
module Main exposing (..) port module Main exposing (..)
import ElmTest exposing (..) import Test.Runner.Node exposing (run)
import Json.Encode exposing (Value)
import Test exposing (..)
import Expect
import Anagram exposing (detect) import Anagram exposing (detect)
tests : Test tests : Test
tests = tests =
suite "Anagram" describe "Anagram"
[ test "no matches" [ test "no matches" <|
(assertEqual [] \() ->
(detect "diaper" [ "hello", "world", "zombies", "pants" ]) Expect.equal []
) (detect "diaper" [ "hello", "world", "zombies", "pants" ])
, test "detects simple anagram" , test "detects simple anagram" <|
(assertEqual [ "tan" ] \() ->
(detect "ant" [ "tan", "stand", "at" ]) Expect.equal [ "tan" ]
) (detect "ant" [ "tan", "stand", "at" ])
, test "does not detect false positives" , test "does not detect false positives" <|
(assertEqual [] \() ->
(detect "galea" [ "eagle" ]) Expect.equal []
) (detect "galea" [ "eagle" ])
, test "detects multiple anagrams" , test "detects multiple anagrams" <|
(assertEqual [ "stream", "maters" ] \() ->
(detect "master" [ "stream", "pigeon", "maters" ]) Expect.equal [ "stream", "maters" ]
) (detect "master" [ "stream", "pigeon", "maters" ])
, test "does not detect anagram subsets" , test "does not detect anagram subsets" <|
(assertEqual [] \() ->
(detect "good" [ "dog", "goody" ]) Expect.equal []
) (detect "good" [ "dog", "goody" ])
, test "detects anagram" , test "detects anagram" <|
(assertEqual [ "inlets" ] \() ->
(detect "listen" [ "enlists", "google", "inlets", "banana" ]) Expect.equal [ "inlets" ]
) (detect "listen" [ "enlists", "google", "inlets", "banana" ])
, test "detects multiple anagrams" , test "detects multiple anagrams" <|
(assertEqual [ "gallery", "regally", "largely" ] \() ->
(detect "allergy" [ "gallery", "ballerina", "regally", "clergy", "largely", "leading" ]) Expect.equal [ "gallery", "regally", "largely" ]
) (detect "allergy" [ "gallery", "ballerina", "regally", "clergy", "largely", "leading" ])
, test "does not detect indentical words" , test "does not detect indentical words" <|
(assertEqual [ "cron" ] \() ->
(detect "corn" [ "corn", "dark", "Corn", "rank", "CORN", "cron", "park" ]) Expect.equal [ "cron" ]
) (detect "corn" [ "corn", "dark", "Corn", "rank", "CORN", "cron", "park" ])
, test "does not detect non-anagrams with identical checksum" , test "does not detect non-anagrams with identical checksum" <|
(assertEqual [] \() ->
(detect "mass" [ "last" ]) Expect.equal []
) (detect "mass" [ "last" ])
, test "detects anagrams case-insensitively" , test "detects anagrams case-insensitively" <|
(assertEqual [ "Carthorse" ] \() ->
(detect "Orchestra" [ "cashregister", "Carthorse", "radishes" ]) Expect.equal [ "Carthorse" ]
) (detect "Orchestra" [ "cashregister", "Carthorse", "radishes" ])
, test "detects anagrams using case-insensitive subject" , test "detects anagrams using case-insensitive subject" <|
(assertEqual [ "carthorse" ] \() ->
(detect "Orchestra" [ "cashregister", "carthorse", "radishes" ]) Expect.equal [ "carthorse" ]
) (detect "Orchestra" [ "cashregister", "carthorse", "radishes" ])
, test "detects anagrams using case-insensitve possible matches" , test "detects anagrams using case-insensitve possible matches" <|
(assertEqual [ "Carthorse" ] \() ->
(detect "orchestra" [ "cashregister", "Carthorse", "radishes" ]) Expect.equal [ "Carthorse" ]
) (detect "orchestra" [ "cashregister", "Carthorse", "radishes" ])
, test "does not detect a word as its own anagram" , test "does not detect a word as its own anagram" <|
(assertEqual [] \() ->
(detect "banana" [ "Banana" ]) Expect.equal []
) (detect "banana" [ "Banana" ])
, test "does not detect a anagram if the original word is repeated" , test "does not detect a anagram if the original word is repeated" <|
(assertEqual [] \() ->
(detect "go" [ "go Go GO" ]) Expect.equal []
) (detect "go" [ "go Go GO" ])
, test "anagrams must use all letters exactly once" , test "anagrams must use all letters exactly once" <|
(assertEqual [] \() ->
(detect "tapper" [ "patter" ]) Expect.equal []
) (detect "tapper" [ "patter" ])
, test "eliminates anagrams with the same checksum" , test "eliminates anagrams with the same checksum" <|
(assertEqual [] \() ->
(detect "mass" [ "last" ]) Expect.equal []
) (detect "mass" [ "last" ])
, test "detects unicode anagrams" , test "detects unicode anagrams" <|
(assertEqual [ "ΒΓΑ", "γβα" ] \() ->
(detect "ΑΒΓ" [ "ΒΓΑ", "ΒΓΔ", "γβα" ]) Expect.equal [ "ΒΓΑ", "γβα" ]
) (detect "ΑΒΓ" [ "ΒΓΑ", "ΒΓΔ", "γβα" ])
, test "eliminates misleading unicode anagrams" , test "eliminates misleading unicode anagrams" <|
(assertEqual [] \() ->
(detect "ΑΒΓ" [ "ABΓ" ]) Expect.equal []
) (detect "ΑΒΓ" [ "ABΓ" ])
, test "capital word is not own anagram" , test "capital word is not own anagram" <|
(assertEqual [] \() ->
(detect "BANANA" [ "Banana" ]) Expect.equal []
) (detect "BANANA" [ "Banana" ])
, test "anagrams must use all letters exactly once" , test "anagrams must use all letters exactly once" <|
(assertEqual [] \() ->
(detect "patter" [ "tapper" ]) Expect.equal []
) (detect "patter" [ "tapper" ])
] ]
main : Program Never main : Program Never
main = main =
runSuite tests run emit tests
port emit : ( String, Value ) -> Cmd msg

View file

@ -1,5 +1,5 @@
{ {
"version": "2.0.0", "version": "3.0.0",
"summary": "Exercism problems in Elm.", "summary": "Exercism problems in Elm.",
"repository": "https://github.com/exercism/xelm.git", "repository": "https://github.com/exercism/xelm.git",
"license": "BSD3", "license": "BSD3",
@ -8,8 +8,9 @@
], ],
"exposed-modules": [], "exposed-modules": [],
"dependencies": { "dependencies": {
"elm-community/elm-test": "1.0.0 <= v < 2.0.0", "elm-lang/core": "4.0.0 <= v < 5.0.0",
"elm-lang/core": "4.0.0 <= v < 5.0.0" "elm-community/elm-test": "2.0.0 <= v < 3.0.0",
"rtfeldman/node-test-runner": "1.0.0 <= v < 2.0.0"
}, },
"elm-version": "0.17.0 <= v < 0.18.0" "elm-version": "0.17.0 <= v < 0.18.0"
} }

View file

@ -1,4 +0,0 @@
@echo off
for %%f in (*Tests.elm) do (
elm-make %%f --yes --output build.js && node build.js
)

View file

@ -1,2 +0,0 @@
#!/usr/bin/env bash
elm-make *Tests.elm --yes --output build.js && node build.js

View file

@ -1,39 +1,45 @@
module Main exposing (..) port module Main exposing (..)
import ElmTest exposing (..) import Test.Runner.Node exposing (run)
import Json.Encode exposing (Value)
import Test exposing (..)
import Expect
import AtbashCipher exposing (encode, decode) import AtbashCipher exposing (encode, decode)
tests : Test tests : Test
tests = tests =
suite "AtbashCipher" describe "AtbashCipher"
[ test "encode no" [ test "encode no" <|
(assertEqual "ml" (encode "no")) \() -> Expect.equal "ml" (encode "no")
, test "encode yes" , test "encode yes" <|
(assertEqual "bvh" (encode "yes")) \() -> Expect.equal "bvh" (encode "yes")
, test "encode OMG" , test "encode OMG" <|
(assertEqual "lnt" (encode "OMG")) \() -> Expect.equal "lnt" (encode "OMG")
, test "encode O M G" , test "encode O M G" <|
(assertEqual "lnt" (encode "O M G")) \() -> Expect.equal "lnt" (encode "O M G")
, test "encode long word" , test "encode long word" <|
(assertEqual "nrmwy oldrm tob" (encode "mindblowingly")) \() -> Expect.equal "nrmwy oldrm tob" (encode "mindblowingly")
, test "encode numbers" , test "encode numbers" <|
(assertEqual "gvhgr mt123 gvhgr mt" (encode "Testing, 1 2 3, testing.")) \() -> Expect.equal "gvhgr mt123 gvhgr mt" (encode "Testing, 1 2 3, testing.")
, test "encode sentence" , test "encode sentence" <|
(assertEqual "gifgs rhurx grlm" (encode "Truth is fiction.")) \() -> Expect.equal "gifgs rhurx grlm" (encode "Truth is fiction.")
, test "encode all things" , test "encode all things" <|
(assertEqual "gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt" \() ->
(encode "The quick brown fox jumps over the lazy dog.") Expect.equal "gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt"
) (encode "The quick brown fox jumps over the lazy dog.")
, test "decode word" , test "decode word" <|
(assertEqual "exercism" (decode "vcvix rhn")) \() -> Expect.equal "exercism" (decode "vcvix rhn")
, test "decode sentence" , test "decode sentence" <|
(assertEqual "anobstacleisoftenasteppingstone" \() ->
(decode "zmlyh gzxov rhlug vmzhg vkkrm thglm v") Expect.equal "anobstacleisoftenasteppingstone"
) (decode "zmlyh gzxov rhlug vmzhg vkkrm thglm v")
] ]
main : Program Never main : Program Never
main = main =
runSuite tests run emit tests
port emit : ( String, Value ) -> Cmd msg

View file

@ -1,5 +1,5 @@
{ {
"version": "2.0.0", "version": "3.0.0",
"summary": "Exercism problems in Elm.", "summary": "Exercism problems in Elm.",
"repository": "https://github.com/exercism/xelm.git", "repository": "https://github.com/exercism/xelm.git",
"license": "BSD3", "license": "BSD3",
@ -8,8 +8,9 @@
], ],
"exposed-modules": [], "exposed-modules": [],
"dependencies": { "dependencies": {
"elm-community/elm-test": "1.0.0 <= v < 2.0.0", "elm-lang/core": "4.0.0 <= v < 5.0.0",
"elm-lang/core": "4.0.0 <= v < 5.0.0" "elm-community/elm-test": "2.0.0 <= v < 3.0.0",
"rtfeldman/node-test-runner": "1.0.0 <= v < 2.0.0"
}, },
"elm-version": "0.17.0 <= v < 0.18.0" "elm-version": "0.17.0 <= v < 0.18.0"
} }

View file

@ -1,4 +0,0 @@
@echo off
for %%f in (*Tests.elm) do (
elm-make %%f --yes --output build.js && node build.js
)

View file

@ -1,2 +0,0 @@
#!/usr/bin/env bash
elm-make *Tests.elm --yes --output build.js && node build.js

View file

@ -1,6 +1,9 @@
module Main exposing (..) port module Main exposing (..)
import ElmTest exposing (..) import Test.Runner.Node exposing (run)
import Json.Encode exposing (Value)
import Test exposing (..)
import Expect
import String import String
import Char import Char
import Random import Random
@ -9,27 +12,106 @@ import Bob
tests : Test tests : Test
tests = tests =
suite "Bob" describe "Bob"
[ test "stating something" (assertEqual "Whatever." (Bob.hey "Tom-ay-to, tom-aaaah-to.")) [ test "stating something" <|
, test "shouting" (assertEqual "Whoa, chill out!" (Bob.hey "WATCH OUT!")) \() ->
, test "shouting gibberish" (assertEqual "Whoa, chill out!" (Bob.hey (uppercaseGibberish 10))) Expect.equal "Whatever."
, test "asking a question" (assertEqual "Sure." (Bob.hey "Does this cryogenic chamber make me look fat?")) (Bob.hey "Tom-ay-to, tom-aaaah-to.")
, test "asking a numeric question" (assertEqual "Sure." (Bob.hey "You are, what, like 15?")) , test "shouting" <|
, test "asking gibberish" (assertEqual "Sure." (Bob.hey (gibberishQuestion 20))) \() ->
, test "talking forcefully" (assertEqual "Whatever." (Bob.hey "Let's go make out behind the gym!")) Expect.equal
, test "using acronyms in regular speech" (assertEqual "Whatever." (Bob.hey "It's OK if you don't want to go to the DMV.")) "Whoa, chill out!"
, test "forceful questions" (assertEqual "Whoa, chill out!" (Bob.hey "WHAT THE HELL WERE YOU THINKING?")) (Bob.hey "WATCH OUT!")
, test "shouting numbers" (assertEqual "Whoa, chill out!" (Bob.hey "1, 2, 3 GO!")) , test "shouting gibberish" <|
, test "only numbers" (assertEqual "Whatever." (Bob.hey "1, 2, 3")) \() ->
, test "question with only numbers" (assertEqual "Sure." (Bob.hey "4?")) Expect.equal
, test "shouting with special characters" (assertEqual "Whoa, chill out!" (Bob.hey "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!)")) "Whoa, chill out!"
, test "shouting with no exclamation mark" (assertEqual "Whoa, chill out!" (Bob.hey "I HATE YOU")) (Bob.hey (uppercaseGibberish 10))
, test "statement containing a question mark" (assertEqual "Whatever." (Bob.hey "Ending with ? means a question.")) , test "asking a question" <|
, test "prattling on" (assertEqual "Sure." (Bob.hey "Wait! Hang on. Are you going to be OK?")) \() ->
, test "silence" (assertEqual "Fine. Be that way!" (Bob.hey "")) Expect.equal
, test "prolonged silence" (assertEqual "Fine. Be that way!" (Bob.hey " ")) "Sure."
, test "alternate silences" (assertEqual "Fine. Be that way!" (Bob.hey "\t \n \t ")) (Bob.hey "Does this cryogenic chamber make me look fat?")
, test "on multiple line questions" (assertEqual "Whatever." (Bob.hey "\nDoes this cryogenic chamber make me look fat?\nno")) , test "asking a numeric question" <|
\() ->
Expect.equal
"Sure."
(Bob.hey "You are, what, like 15?")
, test "asking gibberish" <|
\() ->
Expect.equal
"Sure."
(Bob.hey (gibberishQuestion 20))
, test "talking forcefully" <|
\() ->
Expect.equal
"Whatever."
(Bob.hey "Let's go make out behind the gym!")
, test "using acronyms in regular speech" <|
\() ->
Expect.equal
"Whatever."
(Bob.hey "It's OK if you don't want to go to the DMV.")
, test "forceful questions" <|
\() ->
Expect.equal
"Whoa, chill out!"
(Bob.hey "WHAT THE HELL WERE YOU THINKING?")
, test "shouting numbers" <|
\() ->
Expect.equal
"Whoa, chill out!"
(Bob.hey "1, 2, 3 GO!")
, test "only numbers" <|
\() ->
Expect.equal
"Whatever."
(Bob.hey "1, 2, 3")
, test "question with only numbers" <|
\() ->
Expect.equal
"Sure."
(Bob.hey "4?")
, test "shouting with special characters" <|
\() ->
Expect.equal
"Whoa, chill out!"
(Bob.hey "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!)")
, test "shouting with no exclamation mark" <|
\() ->
Expect.equal
"Whoa, chill out!"
(Bob.hey "I HATE YOU")
, test "statement containing a question mark" <|
\() ->
Expect.equal
"Whatever."
(Bob.hey "Ending with ? means a question.")
, test "prattling on" <|
\() ->
Expect.equal
"Sure."
(Bob.hey "Wait! Hang on. Are you going to be OK?")
, test "silence" <|
\() ->
Expect.equal
"Fine. Be that way!"
(Bob.hey "")
, test "prolonged silence" <|
\() ->
Expect.equal
"Fine. Be that way!"
(Bob.hey " ")
, test "alternate silences" <|
\() ->
Expect.equal
"Fine. Be that way!"
(Bob.hey "\t \n \t ")
, test "on multiple line questions" <|
\() ->
Expect.equal
"Whatever."
(Bob.hey "\nDoes this cryogenic chamber make me look fat?\nno")
] ]
@ -70,4 +152,7 @@ gibberishQuestion length =
main : Program Never main : Program Never
main = main =
runSuite tests run emit tests
port emit : ( String, Value ) -> Cmd msg

View file

@ -1,5 +1,5 @@
{ {
"version": "2.0.0", "version": "3.0.0",
"summary": "Exercism problems in Elm.", "summary": "Exercism problems in Elm.",
"repository": "https://github.com/exercism/xelm.git", "repository": "https://github.com/exercism/xelm.git",
"license": "BSD3", "license": "BSD3",
@ -8,8 +8,9 @@
], ],
"exposed-modules": [], "exposed-modules": [],
"dependencies": { "dependencies": {
"elm-community/elm-test": "1.0.0 <= v < 2.0.0", "elm-lang/core": "4.0.0 <= v < 5.0.0",
"elm-lang/core": "4.0.0 <= v < 5.0.0" "elm-community/elm-test": "2.0.0 <= v < 3.0.0",
"rtfeldman/node-test-runner": "1.0.0 <= v < 2.0.0"
}, },
"elm-version": "0.17.0 <= v < 0.18.0" "elm-version": "0.17.0 <= v < 0.18.0"
} }

View file

@ -1,4 +0,0 @@
@echo off
for %%f in (*Tests.elm) do (
elm-make %%f --yes --output build.js && node build.js
)

View file

@ -1,2 +0,0 @@
#!/usr/bin/env bash
elm-make *Tests.elm --yes --output build.js && node build.js

View file

@ -1,31 +1,47 @@
module Main exposing (..) port module Main exposing (..)
import ElmTest exposing (..) import Test.Runner.Node exposing (run)
import Json.Encode exposing (Value)
import Test exposing (..)
import Expect
import DifferenceOfSquares exposing (squareOfSum, sumOfSquares, difference) import DifferenceOfSquares exposing (squareOfSum, sumOfSquares, difference)
tests : Test tests : Test
tests = tests =
suite "DifferenceOfSquares" describe "DifferenceOfSquares"
[ suite "square the sum of the numbers up to the given number" [ describe "square the sum of the numbers up to the given number"
[ test "square of sum 5" (assertEqual 225 (squareOfSum 5)) [ test "square of sum 5" <|
, test "square of sum 10" (assertEqual 3025 (squareOfSum 10)) \() -> Expect.equal 225 (squareOfSum 5)
, test "square of sum 100" (assertEqual 25502500 (squareOfSum 100)) , test "square of sum 10" <|
\() -> Expect.equal 3025 (squareOfSum 10)
, test "square of sum 100" <|
\() -> Expect.equal 25502500 (squareOfSum 100)
] ]
, suite "sum the squares of the numbers up to the given number" , describe "sum the squares of the numbers up to the given number"
[ test "sum of squares 5" (assertEqual 55 (sumOfSquares 5)) [ test "sum of squares 5" <|
, test "sum of squares 10" (assertEqual 385 (sumOfSquares 10)) \() -> Expect.equal 55 (sumOfSquares 5)
, test "sum of squares 100" (assertEqual 338350 (sumOfSquares 100)) , test "sum of squares 10" <|
\() -> Expect.equal 385 (sumOfSquares 10)
, test "sum of squares 100" <|
\() -> Expect.equal 338350 (sumOfSquares 100)
] ]
, suite "subtract sum of squares from square of sums" , describe "subtract sum of squares from square of sums"
[ test "difference of squares 0" (assertEqual 0 (difference 0)) [ test "difference of squares 0" <|
, test "difference of squares 5" (assertEqual 170 (difference 5)) \() -> Expect.equal 0 (difference 0)
, test "difference of squares 10" (assertEqual 2640 (difference 10)) , test "difference of squares 5" <|
, test "difference of squares 100" (assertEqual 25164150 (difference 100)) \() -> Expect.equal 170 (difference 5)
, test "difference of squares 10" <|
\() -> Expect.equal 2640 (difference 10)
, test "difference of squares 100" <|
\() -> Expect.equal 25164150 (difference 100)
] ]
] ]
main : Program Never main : Program Never
main = main =
runSuite tests run emit tests
port emit : ( String, Value ) -> Cmd msg

View file

@ -1,5 +1,5 @@
{ {
"version": "2.0.0", "version": "3.0.0",
"summary": "Exercism problems in Elm.", "summary": "Exercism problems in Elm.",
"repository": "https://github.com/exercism/xelm.git", "repository": "https://github.com/exercism/xelm.git",
"license": "BSD3", "license": "BSD3",
@ -8,8 +8,9 @@
], ],
"exposed-modules": [], "exposed-modules": [],
"dependencies": { "dependencies": {
"elm-community/elm-test": "1.0.0 <= v < 2.0.0", "elm-lang/core": "4.0.0 <= v < 5.0.0",
"elm-lang/core": "4.0.0 <= v < 5.0.0" "elm-community/elm-test": "2.0.0 <= v < 3.0.0",
"rtfeldman/node-test-runner": "1.0.0 <= v < 2.0.0"
}, },
"elm-version": "0.17.0 <= v < 0.18.0" "elm-version": "0.17.0 <= v < 0.18.0"
} }

View file

@ -1,4 +0,0 @@
@echo off
for %%f in (*Tests.elm) do (
elm-make %%f --yes --output build.js && node build.js
)

View file

@ -1,2 +0,0 @@
#!/usr/bin/env bash
elm-make *Tests.elm --yes --output build.js && node build.js

View file

@ -1,63 +1,69 @@
module Main exposing (..) port module Main exposing (..)
import ElmTest exposing (..) import Test.Runner.Node exposing (run)
import Json.Encode exposing (Value)
import Test exposing (..)
import Expect
import GradeSchool exposing (addStudent, studentsInGrade, allStudents) import GradeSchool exposing (addStudent, studentsInGrade, allStudents)
tests : Test tests : Test
tests = tests =
suite "GradeSchool" describe "GradeSchool"
[ test "add student" [ test "add student" <|
(assertEqual [ "Aimee" ] \() ->
(GradeSchool.empty Expect.equal [ "Aimee" ]
|> addStudent 2 "Aimee" (GradeSchool.empty
|> studentsInGrade 2 |> addStudent 2 "Aimee"
) |> studentsInGrade 2
) )
, test "add more students in same class" , test "add more students in same class" <|
(assertEqual [ "Blair", "James", "Paul" ] \() ->
(GradeSchool.empty Expect.equal [ "Blair", "James", "Paul" ]
|> addStudent 2 "James" (GradeSchool.empty
|> addStudent 2 "Blair" |> addStudent 2 "James"
|> addStudent 2 "Paul" |> addStudent 2 "Blair"
|> studentsInGrade 2 |> addStudent 2 "Paul"
) |> studentsInGrade 2
) )
, test "add students to different grades" , test "add students to different grades" <|
(assertEqual [ [ "Chelsea" ], [ "Logan" ] ] \() ->
(let Expect.equal [ [ "Chelsea" ], [ "Logan" ] ]
school = (let
GradeSchool.empty school =
|> addStudent 3 "Chelsea" GradeSchool.empty
|> addStudent 7 "Logan" |> addStudent 3 "Chelsea"
in |> addStudent 7 "Logan"
[ studentsInGrade 3 school, studentsInGrade 7 school ] in
) [ studentsInGrade 3 school, studentsInGrade 7 school ]
) )
, test "get students in a grade" , test "get students in a grade" <|
(assertEqual [ "Bradley", "Franklin" ] \() ->
(GradeSchool.empty Expect.equal [ "Bradley", "Franklin" ]
|> addStudent 5 "Franklin" (GradeSchool.empty
|> addStudent 5 "Bradley" |> addStudent 5 "Franklin"
|> addStudent 1 "Jeff" |> addStudent 5 "Bradley"
|> studentsInGrade 5 |> addStudent 1 "Jeff"
) |> studentsInGrade 5
) )
, test "get all students in the school" , test "get all students in the school" <|
(assertEqual [ ( 3, [ "Kyle" ] ), ( 4, [ "Christopher", "Jennifer" ] ), ( 6, [ "Kareem" ] ) ] \() ->
(GradeSchool.empty Expect.equal [ ( 3, [ "Kyle" ] ), ( 4, [ "Christopher", "Jennifer" ] ), ( 6, [ "Kareem" ] ) ]
|> addStudent 4 "Jennifer" (GradeSchool.empty
|> addStudent 6 "Kareem" |> addStudent 4 "Jennifer"
|> addStudent 4 "Christopher" |> addStudent 6 "Kareem"
|> addStudent 3 "Kyle" |> addStudent 4 "Christopher"
|> allStudents |> addStudent 3 "Kyle"
) |> allStudents
) )
, test "get students in a non-existent grade" , test "get students in a non-existent grade" <|
(assertEqual [] (studentsInGrade 1 GradeSchool.empty)) \() -> Expect.equal [] (studentsInGrade 1 GradeSchool.empty)
] ]
main : Program Never main : Program Never
main = main =
runSuite tests run emit tests
port emit : ( String, Value ) -> Cmd msg

View file

@ -1,5 +1,5 @@
{ {
"version": "2.0.0", "version": "3.0.0",
"summary": "Exercism problems in Elm.", "summary": "Exercism problems in Elm.",
"repository": "https://github.com/exercism/xelm.git", "repository": "https://github.com/exercism/xelm.git",
"license": "BSD3", "license": "BSD3",
@ -8,8 +8,9 @@
], ],
"exposed-modules": [], "exposed-modules": [],
"dependencies": { "dependencies": {
"elm-community/elm-test": "1.0.0 <= v < 2.0.0", "elm-lang/core": "4.0.0 <= v < 5.0.0",
"elm-lang/core": "4.0.0 <= v < 5.0.0" "elm-community/elm-test": "2.0.0 <= v < 3.0.0",
"rtfeldman/node-test-runner": "1.0.0 <= v < 2.0.0"
}, },
"elm-version": "0.17.0 <= v < 0.18.0" "elm-version": "0.17.0 <= v < 0.18.0"
} }

View file

@ -1,4 +0,0 @@
@echo off
for %%f in (*Tests.elm) do (
elm-make %%f --yes --output build.js && node build.js
)

View file

@ -1,2 +0,0 @@
#!/usr/bin/env bash
elm-make *Tests.elm --yes --output build.js && node build.js

View file

@ -1,43 +1,49 @@
module Main exposing (..) port module Main exposing (..)
import ElmTest exposing (..) import Test.Runner.Node exposing (run)
import Json.Encode exposing (Value)
import Test exposing (..)
import Expect
import Hamming exposing (distance) import Hamming exposing (distance)
tests : Test tests : Test
tests = tests =
suite "Hamming" describe "Hamming"
[ test "identical strands" [ test "identical strands" <|
(assertEqual (Just 0) (distance "A" "A")) \() -> Expect.equal (Just 0) (distance "A" "A")
, test "long identical strands" , test "long identical strands" <|
(assertEqual (Just 0) (distance "GGACTGA" "GGACTGA")) \() -> Expect.equal (Just 0) (distance "GGACTGA" "GGACTGA")
, test "complete distance in single nucleotide strands" , test "complete distance in single nucleotide strands" <|
(assertEqual (Just 1) (distance "A" "G")) \() -> Expect.equal (Just 1) (distance "A" "G")
, test "complete distance in small strands" , test "complete distance in small strands" <|
(assertEqual (Just 2) (distance "AG" "CT")) \() -> Expect.equal (Just 2) (distance "AG" "CT")
, test "small distance in small strands" , test "small distance in small strands" <|
(assertEqual (Just 1) (distance "AT" "CT")) \() -> Expect.equal (Just 1) (distance "AT" "CT")
, test "small distance" , test "small distance" <|
(assertEqual (Just 1) (distance "GGACG" "GGTCG")) \() -> Expect.equal (Just 1) (distance "GGACG" "GGTCG")
, test "small distance in long strands" , test "small distance in long strands" <|
(assertEqual (Just 2) (distance "ACCAGGG" "ACTATGG")) \() -> Expect.equal (Just 2) (distance "ACCAGGG" "ACTATGG")
, test "non-unique character in first strand" , test "non-unique character in first strand" <|
(assertEqual (Just 1) (distance "AGA" "AGG")) \() -> Expect.equal (Just 1) (distance "AGA" "AGG")
, test "non-unique character in second strand" , test "non-unique character in second strand" <|
(assertEqual (Just 1) (distance "AGG" "AGA")) \() -> Expect.equal (Just 1) (distance "AGG" "AGA")
, test "large distance" , test "large distance" <|
(assertEqual (Just 4) (distance "GATACA" "GCATAA")) \() -> Expect.equal (Just 4) (distance "GATACA" "GCATAA")
, test "large distance in off-by-one strand" , test "large distance in off-by-one strand" <|
(assertEqual (Just 9) (distance "GGACGGATTCTG" "AGGACGGATTCT")) \() -> Expect.equal (Just 9) (distance "GGACGGATTCTG" "AGGACGGATTCT")
, test "empty strands" , test "empty strands" <|
(assertEqual (Just 0) (distance "" "")) \() -> Expect.equal (Just 0) (distance "" "")
, test "disallow first strand longer" , test "disallow first strand longer" <|
(assertEqual Nothing (distance "AATG" "AAA")) \() -> Expect.equal Nothing (distance "AATG" "AAA")
, test "disallow second strand longer" , test "disallow second strand longer" <|
(assertEqual Nothing (distance "ATA" "AGTG")) \() -> Expect.equal Nothing (distance "ATA" "AGTG")
] ]
main : Program Never main : Program Never
main = main =
runSuite tests run emit tests
port emit : ( String, Value ) -> Cmd msg

View file

@ -1,5 +1,5 @@
{ {
"version": "2.0.0", "version": "3.0.0",
"summary": "Exercism problems in Elm.", "summary": "Exercism problems in Elm.",
"repository": "https://github.com/exercism/xelm.git", "repository": "https://github.com/exercism/xelm.git",
"license": "BSD3", "license": "BSD3",
@ -8,8 +8,9 @@
], ],
"exposed-modules": [], "exposed-modules": [],
"dependencies": { "dependencies": {
"elm-community/elm-test": "1.0.0 <= v < 2.0.0", "elm-lang/core": "4.0.0 <= v < 5.0.0",
"elm-lang/core": "4.0.0 <= v < 5.0.0" "elm-community/elm-test": "2.0.0 <= v < 3.0.0",
"rtfeldman/node-test-runner": "1.0.0 <= v < 2.0.0"
}, },
"elm-version": "0.17.0 <= v < 0.18.0" "elm-version": "0.17.0 <= v < 0.18.0"
} }

View file

@ -1,4 +0,0 @@
@echo off
for %%f in (*Tests.elm) do (
elm-make %%f --yes --output build.js && node build.js
)

View file

@ -1,2 +0,0 @@
#!/usr/bin/env bash
elm-make *Tests.elm --yes --output build.js && node build.js

View file

@ -1,18 +1,30 @@
module Main exposing (..) port module Main exposing (..)
import ElmTest exposing (..) import Test.Runner.Node exposing (run)
import Json.Encode exposing (Value)
import Test exposing (..)
import Expect
import HelloWorld exposing (helloWorld) import HelloWorld exposing (helloWorld)
tests : Test tests : Test
tests = tests =
suite "Hello, World!" describe "Hello, World!"
[ test "Hello with no name" (assertEqual "Hello, World!" (helloWorld Nothing)) [ test "Hello with no name" <|
, test "Hello to a sample name" (assertEqual "Hello, Alice!" (helloWorld (Just "Alice"))) \() ->
, test "Hello to another sample name" (assertEqual "Hello, Bob!" (helloWorld (Just "Bob"))) Expect.equal "Hello, World!" (helloWorld Nothing)
, test "Hello to a sample name" <|
\() ->
Expect.equal "Hello, Alice!" (helloWorld (Just "Alice"))
, test "Hello to another sample name" <|
\() ->
Expect.equal "Hello, Bob!" (helloWorld (Just "Bob"))
] ]
main : Program Never main : Program Never
main = main =
runSuite tests run emit tests
port emit : ( String, Value ) -> Cmd msg

View file

@ -1,5 +1,5 @@
{ {
"version": "2.0.0", "version": "3.0.0",
"summary": "Exercism problems in Elm.", "summary": "Exercism problems in Elm.",
"repository": "https://github.com/exercism/xelm.git", "repository": "https://github.com/exercism/xelm.git",
"license": "BSD3", "license": "BSD3",
@ -8,8 +8,9 @@
], ],
"exposed-modules": [], "exposed-modules": [],
"dependencies": { "dependencies": {
"elm-community/elm-test": "1.0.0 <= v < 2.0.0", "elm-lang/core": "4.0.0 <= v < 5.0.0",
"elm-lang/core": "4.0.0 <= v < 5.0.0" "elm-community/elm-test": "2.0.0 <= v < 3.0.0",
"rtfeldman/node-test-runner": "1.0.0 <= v < 2.0.0"
}, },
"elm-version": "0.17.0 <= v < 0.18.0" "elm-version": "0.17.0 <= v < 0.18.0"
} }

View file

@ -1,4 +0,0 @@
@echo off
for %%f in (*Tests.elm) do (
elm-make %%f --yes --output build.js && node build.js
)

View file

@ -1,2 +0,0 @@
#!/usr/bin/env bash
elm-make *Tests.elm --yes --output build.js && node build.js

View file

@ -1,49 +1,55 @@
module Main exposing (..) port module Main exposing (..)
import ElmTest exposing (..) import Test.Runner.Node exposing (run)
import Json.Encode exposing (Value)
import Test exposing (..)
import Expect
import LargestSeriesProduct exposing (largestProduct) import LargestSeriesProduct exposing (largestProduct)
tests : Test tests : Test
tests = tests =
suite "largestProduct" describe "largestProduct"
[ test "can find the largest product of 2 with numbers in order" [ test "can find the largest product of 2 with numbers in order" <|
(assertEqual (Just 72) (largestProduct 2 "0123456789")) \() -> Expect.equal (Just 72) (largestProduct 2 "0123456789")
, test "can find the largest product of 2" , test "can find the largest product of 2" <|
(assertEqual (Just 48) (largestProduct 2 "576802143")) \() -> Expect.equal (Just 48) (largestProduct 2 "576802143")
, test "finds the largest product if span equals length" , test "finds the largest product if span equals length" <|
(assertEqual (Just 18) (largestProduct 2 "29")) \() -> Expect.equal (Just 18) (largestProduct 2 "29")
, test "can find the largest product of 3 with numbers in order" , test "can find the largest product of 3 with numbers in order" <|
(assertEqual (Just 504) (largestProduct 3 "0123456789")) \() -> Expect.equal (Just 504) (largestProduct 3 "0123456789")
, test "can find the largest product of 3" , test "can find the largest product of 3" <|
(assertEqual (Just 270) (largestProduct 3 "1027839564")) \() -> Expect.equal (Just 270) (largestProduct 3 "1027839564")
, test "can find the largest product of 5 with numbers in order" , test "can find the largest product of 5 with numbers in order" <|
(assertEqual (Just 15120) (largestProduct 5 "0123456789")) \() -> Expect.equal (Just 15120) (largestProduct 5 "0123456789")
, test "can get the largest product of a big number" , test "can get the largest product of a big number" <|
(assertEqual (Just 23520) (largestProduct 6 "73167176531330624919225119674426574742355349194934")) \() -> Expect.equal (Just 23520) (largestProduct 6 "73167176531330624919225119674426574742355349194934")
, test "can get the largest product of a big number II" , test "can get the largest product of a big number II" <|
(assertEqual (Just 28350) (largestProduct 6 "52677741234314237566414902593461595376319419139427")) \() -> Expect.equal (Just 28350) (largestProduct 6 "52677741234314237566414902593461595376319419139427")
, test "can get the largest product of a big number (Project Euler)" , test "can get the largest product of a big number (Project Euler)" <|
(assertEqual (Just 23514624000) (largestProduct 13 "7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450")) \() -> Expect.equal (Just 23514624000) (largestProduct 13 "7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450")
, test "reports zero if the only digits are zero" , test "reports zero if the only digits are zero" <|
(assertEqual (Just 0) (largestProduct 2 "0000")) \() -> Expect.equal (Just 0) (largestProduct 2 "0000")
, test "reports zero if all spans include zero" , test "reports zero if all spans include zero" <|
(assertEqual (Just 0) (largestProduct 3 "99099")) \() -> Expect.equal (Just 0) (largestProduct 3 "99099")
, test "rejects span longer than string length" , test "rejects span longer than string length" <|
(assertEqual Nothing (largestProduct 4 "123")) \() -> Expect.equal Nothing (largestProduct 4 "123")
, test "reports 1 for empty string and empty product (0 span)" , test "reports 1 for empty string and empty product (0 span)" <|
(assertEqual (Just 1) (largestProduct 0 "")) \() -> Expect.equal (Just 1) (largestProduct 0 "")
, test "reports 1 for nonempty string and empty product (0 span)" , test "reports 1 for nonempty string and empty product (0 span)" <|
(assertEqual (Just 1) (largestProduct 0 "123")) \() -> Expect.equal (Just 1) (largestProduct 0 "123")
, test "rejects empty string and nonzero span" , test "rejects empty string and nonzero span" <|
(assertEqual Nothing (largestProduct 1 "")) \() -> Expect.equal Nothing (largestProduct 1 "")
, test "rejects invalid character in digits" , test "rejects invalid character in digits" <|
(assertEqual Nothing (largestProduct 2 "1234a5")) \() -> Expect.equal Nothing (largestProduct 2 "1234a5")
, test "rejects negative span" , test "rejects negative span" <|
(assertEqual Nothing (largestProduct -1 "12345")) \() -> Expect.equal Nothing (largestProduct -1 "12345")
] ]
main : Program Never main : Program Never
main = main =
runSuite tests run emit tests
port emit : ( String, Value ) -> Cmd msg

View file

@ -1,5 +1,5 @@
{ {
"version": "2.0.0", "version": "3.0.0",
"summary": "Exercism problems in Elm.", "summary": "Exercism problems in Elm.",
"repository": "https://github.com/exercism/xelm.git", "repository": "https://github.com/exercism/xelm.git",
"license": "BSD3", "license": "BSD3",
@ -8,8 +8,9 @@
], ],
"exposed-modules": [], "exposed-modules": [],
"dependencies": { "dependencies": {
"elm-community/elm-test": "1.0.0 <= v < 2.0.0", "elm-lang/core": "4.0.0 <= v < 5.0.0",
"elm-lang/core": "4.0.0 <= v < 5.0.0" "elm-community/elm-test": "2.0.0 <= v < 3.0.0",
"rtfeldman/node-test-runner": "1.0.0 <= v < 2.0.0"
}, },
"elm-version": "0.17.0 <= v < 0.18.0" "elm-version": "0.17.0 <= v < 0.18.0"
} }

View file

@ -1,4 +0,0 @@
@echo off
for %%f in (*Tests.elm) do (
elm-make %%f --yes --output build.js && node build.js
)

View file

@ -1,2 +0,0 @@
#!/usr/bin/env bash
elm-make *Tests.elm --yes --output build.js && node build.js

View file

@ -1,22 +1,35 @@
module Main exposing (..) port module Main exposing (..)
import ElmTest exposing (..) import Test.Runner.Node exposing (run)
import Json.Encode exposing (Value)
import Test exposing (..)
import Expect
import Leap import Leap
tests : Test tests : Test
tests = tests =
suite "Leap" describe "Leap"
[ test "leap year" (assertEqual True (Leap.isLeapYear 1996)) [ test "leap year" <|
, test "non-leap year" (assertEqual False (Leap.isLeapYear 1997)) \() -> Expect.equal True (Leap.isLeapYear 1996)
, test "non-leap even year" (assertEqual False (Leap.isLeapYear 1998)) , test "non-leap year" <|
, test "century" (assertEqual False (Leap.isLeapYear 1900)) \() -> Expect.equal False (Leap.isLeapYear 1997)
, test "second century" (assertEqual False (Leap.isLeapYear 1800)) , test "non-leap even year" <|
, test "fourth century" (assertEqual True (Leap.isLeapYear 2400)) \() -> Expect.equal False (Leap.isLeapYear 1998)
, test "y2k" (assertEqual True (Leap.isLeapYear 2000)) , test "century" <|
\() -> Expect.equal False (Leap.isLeapYear 1900)
, test "second century" <|
\() -> Expect.equal False (Leap.isLeapYear 1800)
, test "fourth century" <|
\() -> Expect.equal True (Leap.isLeapYear 2400)
, test "y2k" <|
\() -> Expect.equal True (Leap.isLeapYear 2000)
] ]
main : Program Never main : Program Never
main = main =
runSuite tests run emit tests
port emit : ( String, Value ) -> Cmd msg

View file

@ -1,5 +1,5 @@
{ {
"version": "2.0.0", "version": "3.0.0",
"summary": "Exercism problems in Elm.", "summary": "Exercism problems in Elm.",
"repository": "https://github.com/exercism/xelm.git", "repository": "https://github.com/exercism/xelm.git",
"license": "BSD3", "license": "BSD3",
@ -8,8 +8,9 @@
], ],
"exposed-modules": [], "exposed-modules": [],
"dependencies": { "dependencies": {
"elm-community/elm-test": "1.0.0 <= v < 2.0.0", "elm-lang/core": "4.0.0 <= v < 5.0.0",
"elm-lang/core": "4.0.0 <= v < 5.0.0" "elm-community/elm-test": "2.0.0 <= v < 3.0.0",
"rtfeldman/node-test-runner": "1.0.0 <= v < 2.0.0"
}, },
"elm-version": "0.17.0 <= v < 0.18.0" "elm-version": "0.17.0 <= v < 0.18.0"
} }

View file

@ -1,4 +0,0 @@
@echo off
for %%f in (*Tests.elm) do (
elm-make %%f --yes --output build.js && node build.js
)

View file

@ -1,2 +0,0 @@
#!/usr/bin/env bash
elm-make *Tests.elm --yes --output build.js && node build.js

View file

@ -1,55 +1,77 @@
module Main exposing (..) port module Main exposing (..)
import ElmTest exposing (..) import Test.Runner.Node exposing (run)
import Json.Encode exposing (Value)
import Test exposing (..)
import Expect
import ListOps exposing (..) import ListOps exposing (..)
tests : Test tests : Test
tests = tests =
suite "List Ops" describe "List Ops"
[ suite "length" [ describe "length"
[ test "empty list" (assertEqual 0 (length [])) [ test "empty list" <|
, test "non-empty list" (assertEqual 4 (length [1..4])) \() -> Expect.equal 0 (ListOps.length [])
, test "non-empty list" <|
\() -> Expect.equal 4 (ListOps.length [1..4])
] ]
, suite "reverse" , describe "reverse"
[ test "empty list" (assertEqual [] (reverse [])) [ test "empty list" <|
, test "non-empty list" (assertEqual [ 4, 3, 2, 1 ] (reverse [1..4])) \() -> Expect.equal [] (ListOps.reverse [])
, test "non-empty list" <|
\() -> Expect.equal [ 4, 3, 2, 1 ] (ListOps.reverse [1..4])
] ]
, suite "map" , describe "map"
[ test "empty list" (assertEqual [] (map ((+) 1) [])) [ test "empty list" <|
, test "non-empty list" (assertEqual [2..5] (map ((+) 1) [1..4])) \() -> Expect.equal [] (ListOps.map ((+) 1) [])
, test "non-empty list" <|
\() -> Expect.equal [2..5] (ListOps.map ((+) 1) [1..4])
] ]
, suite "filter" , describe "filter"
[ test "empty list" (assertEqual [] (filter (\_ -> True) [])) [ test "empty list" <|
, test "non-empty list" \() -> Expect.equal [] (ListOps.filter (\_ -> True) [])
(assertEqual [ 2, 4 ] (filter (\x -> x % 2 == 0) [1..4])) , test "non-empty list" <|
\() -> Expect.equal [ 2, 4 ] (ListOps.filter (\x -> x % 2 == 0) [1..4])
] ]
, suite "foldl" , describe "foldl"
[ test "empty list" (assertEqual 0 (foldl (+) 0 [])) [ test "empty list" <|
, test "non-empty list" (assertEqual 10 (foldl (+) 0 [1..4])) \() -> Expect.equal 0 (ListOps.foldl (+) 0 [])
, test "direction" (assertEqual [4,3,2,1] (foldl (::) [] [1..4])) , test "non-empty list" <|
\() -> Expect.equal 10 (ListOps.foldl (+) 0 [1..4])
, test "direction" <|
\() -> Expect.equal [ 4, 3, 2, 1 ] (ListOps.foldl (::) [] [1..4])
] ]
, suite "foldr" , describe "foldr"
[ test "empty list" (assertEqual 0 (foldr (+) 0 [])) [ test "empty list" <|
, test "non-empty list" (assertEqual 10 (foldr (+) 0 [1..4])) \() -> Expect.equal 0 (ListOps.foldr (+) 0 [])
, test "direction" (assertEqual [1..4] (foldr (::) [] [1..4])) , test "non-empty list" <|
\() -> Expect.equal 10 (ListOps.foldr (+) 0 [1..4])
, test "direction" <|
\() -> Expect.equal [1..4] (ListOps.foldr (::) [] [1..4])
] ]
, suite "append" , describe "append"
[ test "empty lists" (assertEqual [] (append [] [])) [ test "empty lists" <|
, test "empty and non-empty lists" \() -> Expect.equal [] (ListOps.append [] [])
(assertEqual [1..4] (append [] [1..4])) , test "empty and non-empty lists" <|
, test "non-empty and empty lists" \() -> Expect.equal [1..4] (ListOps.append [] [1..4])
(assertEqual [1..4] (append [1..4] [])) , test "non-empty and empty lists" <|
, test "non-empty lists" (assertEqual [1..8] (append [1..4] [5..8])) \() -> Expect.equal [1..4] (ListOps.append [1..4] [])
, test "non-empty lists" <|
\() -> Expect.equal [1..8] (ListOps.append [1..4] [5..8])
] ]
, suite "concat" , describe "concat"
[ test "empty list" (assertEqual [] (concat [])) [ test "empty list" <|
, test "list of lists" \() -> Expect.equal [] (ListOps.concat [])
(assertEqual [1..10] (concat [ [1..3], [], [4..7], [8..10] ])) , test "list of lists" <|
\() -> Expect.equal [1..10] (ListOps.concat [ [1..3], [], [4..7], [8..10] ])
] ]
] ]
main : Program Never main : Program Never
main = main =
runSuite tests run emit tests
port emit : ( String, Value ) -> Cmd msg

View file

@ -1,5 +1,5 @@
{ {
"version": "2.0.0", "version": "3.0.0",
"summary": "Exercism problems in Elm.", "summary": "Exercism problems in Elm.",
"repository": "https://github.com/exercism/xelm.git", "repository": "https://github.com/exercism/xelm.git",
"license": "BSD3", "license": "BSD3",
@ -8,8 +8,9 @@
], ],
"exposed-modules": [], "exposed-modules": [],
"dependencies": { "dependencies": {
"elm-community/elm-test": "1.0.0 <= v < 2.0.0", "elm-lang/core": "4.0.0 <= v < 5.0.0",
"elm-lang/core": "4.0.0 <= v < 5.0.0" "elm-community/elm-test": "2.0.0 <= v < 3.0.0",
"rtfeldman/node-test-runner": "1.0.0 <= v < 2.0.0"
}, },
"elm-version": "0.17.0 <= v < 0.18.0" "elm-version": "0.17.0 <= v < 0.18.0"
} }

View file

@ -1,4 +0,0 @@
@echo off
for %%f in (*Tests.elm) do (
elm-make %%f --yes --output build.js && node build.js
)

View file

@ -1,2 +0,0 @@
#!/usr/bin/env bash
elm-make *Tests.elm --yes --output build.js && node build.js

View file

@ -1,29 +1,35 @@
module Main exposing (..) port module Main exposing (..)
import ElmTest exposing (..) import Test.Runner.Node exposing (run)
import Json.Encode exposing (Value)
import Test exposing (..)
import Expect
import NucleotideCount exposing (nucleotideCounts, version) import NucleotideCount exposing (nucleotideCounts, version)
tests : Test tests : Test
tests = tests =
suite "NucleotideCount" describe "NucleotideCount"
[ test "the solution is for the correct version of the test" [ test "the solution is for the correct version of the test" <|
(assertEqual 2 version) \() -> Expect.equal 2 version
, test "empty dna strand has no nucleotides" , test "empty dna strand has no nucleotides" <|
(assertEqual { a = 0, t = 0, c = 0, g = 0 } \() ->
(nucleotideCounts "") Expect.equal { a = 0, t = 0, c = 0, g = 0 }
) (nucleotideCounts "")
, test "repetitive-sequence-has-only-guanosine" , test "repetitive-sequence-has-only-guanosine" <|
(assertEqual { a = 0, t = 0, c = 0, g = 8 } \() ->
(nucleotideCounts "GGGGGGGG") Expect.equal { a = 0, t = 0, c = 0, g = 8 }
) (nucleotideCounts "GGGGGGGG")
, test "counts all nucleotides" , test "counts all nucleotides" <|
(assertEqual { a = 20, t = 21, c = 12, g = 17 } \() ->
(nucleotideCounts "AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC") Expect.equal { a = 20, t = 21, c = 12, g = 17 }
) (nucleotideCounts "AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC")
] ]
main : Program Never main : Program Never
main = main =
runSuite tests run emit tests
port emit : ( String, Value ) -> Cmd msg

View file

@ -1,5 +1,5 @@
{ {
"version": "2.0.0", "version": "3.0.0",
"summary": "Exercism problems in Elm.", "summary": "Exercism problems in Elm.",
"repository": "https://github.com/exercism/xelm.git", "repository": "https://github.com/exercism/xelm.git",
"license": "BSD3", "license": "BSD3",
@ -8,8 +8,9 @@
], ],
"exposed-modules": [], "exposed-modules": [],
"dependencies": { "dependencies": {
"elm-community/elm-test": "1.0.0 <= v < 2.0.0", "elm-lang/core": "4.0.0 <= v < 5.0.0",
"elm-lang/core": "4.0.0 <= v < 5.0.0" "elm-community/elm-test": "2.0.0 <= v < 3.0.0",
"rtfeldman/node-test-runner": "1.0.0 <= v < 2.0.0"
}, },
"elm-version": "0.17.0 <= v < 0.18.0" "elm-version": "0.17.0 <= v < 0.18.0"
} }

View file

@ -1,4 +0,0 @@
@echo off
for %%f in (*Tests.elm) do (
elm-make %%f --yes --output build.js && node build.js
)

View file

@ -1,2 +0,0 @@
#!/usr/bin/env bash
elm-make *Tests.elm --yes --output build.js && node build.js

View file

@ -1,51 +1,57 @@
module Main exposing (..) port module Main exposing (..)
import ElmTest exposing (..) import Test.Runner.Node exposing (run)
import Json.Encode exposing (Value)
import Test exposing (..)
import Expect
import Pangram exposing (isPangram) import Pangram exposing (isPangram)
tests : Test tests : Test
tests = tests =
suite "Pangram" describe "Pangram"
[ test "sentence empty" [ test "sentence empty" <|
(assertEqual False \() ->
(isPangram "") Expect.equal False
) (isPangram "")
, test "pangram with only lower case" , test "pangram with only lower case" <|
(assertEqual True \() ->
(isPangram "the quick brown fox jumps over the lazy dog") Expect.equal True
) (isPangram "the quick brown fox jumps over the lazy dog")
, test "missing character 'x'" , test "missing character 'x'" <|
(assertEqual False \() ->
(isPangram "a quick movement of the enemy will jeopardize five gunboats") Expect.equal False
) (isPangram "a quick movement of the enemy will jeopardize five gunboats")
, test "another missing character 'x'" , test "another missing character 'x'" <|
(assertEqual False \() ->
(isPangram "the quick brown fish jumps over the lazy dog") Expect.equal False
) (isPangram "the quick brown fish jumps over the lazy dog")
, test "pangram with underscores" , test "pangram with underscores" <|
(assertEqual True \() ->
(isPangram "the_quick_brown_fox_jumps_over_the_lazy_dog") Expect.equal True
) (isPangram "the_quick_brown_fox_jumps_over_the_lazy_dog")
, test "pangram with numbers" , test "pangram with numbers" <|
(assertEqual True \() ->
(isPangram "the 1 quick brown fox jumps over the 2 lazy dogs") Expect.equal True
) (isPangram "the 1 quick brown fox jumps over the 2 lazy dogs")
, test "missing letters replaced by numbers" , test "missing letters replaced by numbers" <|
(assertEqual False \() ->
(isPangram "7h3 qu1ck brown fox jumps ov3r 7h3 lazy dog") Expect.equal False
) (isPangram "7h3 qu1ck brown fox jumps ov3r 7h3 lazy dog")
, test "pangram with mixed case and punctuation" , test "pangram with mixed case and punctuation" <|
(assertEqual True \() ->
(isPangram "\"Five quacking Zephyrs jolt my wax bed.\"") Expect.equal True
) (isPangram "\"Five quacking Zephyrs jolt my wax bed.\"")
, test "pangram with non ascii characters" , test "pangram with non ascii characters" <|
(assertEqual True \() ->
(isPangram "Victor jagt zwölf Boxkämpfer quer über den großen Sylter Deich.") Expect.equal True
) (isPangram "Victor jagt zwölf Boxkämpfer quer über den großen Sylter Deich.")
] ]
main : Program Never main : Program Never
main = main =
runSuite tests run emit tests
port emit : ( String, Value ) -> Cmd msg

View file

@ -1,5 +1,5 @@
{ {
"version": "2.0.0", "version": "3.0.0",
"summary": "Exercism problems in Elm.", "summary": "Exercism problems in Elm.",
"repository": "https://github.com/exercism/xelm.git", "repository": "https://github.com/exercism/xelm.git",
"license": "BSD3", "license": "BSD3",
@ -8,8 +8,9 @@
], ],
"exposed-modules": [], "exposed-modules": [],
"dependencies": { "dependencies": {
"elm-community/elm-test": "1.0.0 <= v < 2.0.0", "elm-lang/core": "4.0.0 <= v < 5.0.0",
"elm-lang/core": "4.0.0 <= v < 5.0.0" "elm-community/elm-test": "2.0.0 <= v < 3.0.0",
"rtfeldman/node-test-runner": "1.0.0 <= v < 2.0.0"
}, },
"elm-version": "0.17.0 <= v < 0.18.0" "elm-version": "0.17.0 <= v < 0.18.0"
} }

View file

@ -1,4 +0,0 @@
@echo off
for %%f in (*Tests.elm) do (
elm-make %%f --yes --output build.js && node build.js
)

View file

@ -1,2 +0,0 @@
#!/usr/bin/env bash
elm-make *Tests.elm --yes --output build.js && node build.js

View file

@ -1,39 +1,45 @@
module Main exposing (..) port module Main exposing (..)
import ElmTest exposing (..) import Test.Runner.Node exposing (run)
import Json.Encode exposing (Value)
import Test exposing (..)
import Expect
import PhoneNumber exposing (getNumber, prettyPrint) import PhoneNumber exposing (getNumber, prettyPrint)
tests : Test tests : Test
tests = tests =
suite "PhoneNumber" describe "PhoneNumber"
[ test "cleans number" [ test "cleans number" <|
(assertEqual (Just "1234567890") (getNumber "(123) 456-7890")) \() -> Expect.equal (Just "1234567890") (getNumber "(123) 456-7890")
, test "cleans number with dots" , test "cleans number with dots" <|
(assertEqual (Just "1234567890") (getNumber "123.456.7890")) \() -> Expect.equal (Just "1234567890") (getNumber "123.456.7890")
, test "valid when 11 digits and first is 1" , test "valid when 11 digits and first is 1" <|
(assertEqual (Just "1234567890") (getNumber "11234567890")) \() -> Expect.equal (Just "1234567890") (getNumber "11234567890")
, test "invalid when 11 digits" , test "invalid when 11 digits" <|
(assertEqual Nothing (getNumber "21234567890")) \() -> Expect.equal Nothing (getNumber "21234567890")
, test "invalid when 9 digits" , test "invalid when 9 digits" <|
(assertEqual Nothing (getNumber "123456789")) \() -> Expect.equal Nothing (getNumber "123456789")
, test "invalid when 12 digits" , test "invalid when 12 digits" <|
(assertEqual Nothing (getNumber "123456789012")) \() -> Expect.equal Nothing (getNumber "123456789012")
, test "invalid when empty" , test "invalid when empty" <|
(assertEqual Nothing (getNumber "")) \() -> Expect.equal Nothing (getNumber "")
, test "invalid when no digits present" , test "invalid when no digits present" <|
(assertEqual Nothing (getNumber " (-) ")) \() -> Expect.equal Nothing (getNumber " (-) ")
, test "valid with leading characters" , test "valid with leading characters" <|
(assertEqual (Just "1234567890") (getNumber "my number is 123 456 7890")) \() -> Expect.equal (Just "1234567890") (getNumber "my number is 123 456 7890")
, test "valid with trailing characters" , test "valid with trailing characters" <|
(assertEqual (Just "1234567890") (getNumber "123 456 7890 - bob")) \() -> Expect.equal (Just "1234567890") (getNumber "123 456 7890 - bob")
, test "pretty print" , test "pretty print" <|
(assertEqual (Just "(123) 456-7890") (prettyPrint "1234567890")) \() -> Expect.equal (Just "(123) 456-7890") (prettyPrint "1234567890")
, test "pretty print with full us phone number" , test "pretty print with full us phone number" <|
(assertEqual (Just "(123) 456-7890") (prettyPrint "11234567890")) \() -> Expect.equal (Just "(123) 456-7890") (prettyPrint "11234567890")
] ]
main : Program Never main : Program Never
main = main =
runSuite tests run emit tests
port emit : ( String, Value ) -> Cmd msg

View file

@ -1,5 +1,5 @@
{ {
"version": "2.0.0", "version": "3.0.0",
"summary": "Exercism problems in Elm.", "summary": "Exercism problems in Elm.",
"repository": "https://github.com/exercism/xelm.git", "repository": "https://github.com/exercism/xelm.git",
"license": "BSD3", "license": "BSD3",
@ -8,8 +8,9 @@
], ],
"exposed-modules": [], "exposed-modules": [],
"dependencies": { "dependencies": {
"elm-community/elm-test": "1.0.0 <= v < 2.0.0", "elm-lang/core": "4.0.0 <= v < 5.0.0",
"elm-lang/core": "4.0.0 <= v < 5.0.0" "elm-community/elm-test": "2.0.0 <= v < 3.0.0",
"rtfeldman/node-test-runner": "1.0.0 <= v < 2.0.0"
}, },
"elm-version": "0.17.0 <= v < 0.18.0" "elm-version": "0.17.0 <= v < 0.18.0"
} }

View file

@ -1,4 +0,0 @@
@echo off
for %%f in (*Tests.elm) do (
elm-make %%f --yes --output build.js && node build.js
)

View file

@ -1,2 +0,0 @@
#!/usr/bin/env bash
elm-make *Tests.elm --yes --output build.js && node build.js

View file

@ -1,30 +1,51 @@
module Main exposing (..) port module Main exposing (..)
import ElmTest exposing (..) import Test.Runner.Node exposing (run)
import Json.Encode exposing (Value)
import Test exposing (..)
import Expect
import Raindrops exposing (raindrops) import Raindrops exposing (raindrops)
tests : Test tests : Test
tests = tests =
suite "Raindrops" describe "Raindrops"
[ test "1" (assertEqual "1" (raindrops 1)) [ test "1" <|
, test "3" (assertEqual "Pling" (raindrops 3)) \() -> Expect.equal "1" (raindrops 1)
, test "5" (assertEqual "Plang" (raindrops 5)) , test "3" <|
, test "7" (assertEqual "Plong" (raindrops 7)) \() -> Expect.equal "Pling" (raindrops 3)
, test "6" (assertEqual "Pling" (raindrops 6)) , test "5" <|
, test "9" (assertEqual "Pling" (raindrops 9)) \() -> Expect.equal "Plang" (raindrops 5)
, test "10" (assertEqual "Plang" (raindrops 10)) , test "7" <|
, test "14" (assertEqual "Plong" (raindrops 14)) \() -> Expect.equal "Plong" (raindrops 7)
, test "15" (assertEqual "PlingPlang" (raindrops 15)) , test "6" <|
, test "21" (assertEqual "PlingPlong" (raindrops 21)) \() -> Expect.equal "Pling" (raindrops 6)
, test "25" (assertEqual "Plang" (raindrops 25)) , test "9" <|
, test "35" (assertEqual "PlangPlong" (raindrops 35)) \() -> Expect.equal "Pling" (raindrops 9)
, test "49" (assertEqual "Plong" (raindrops 49)) , test "10" <|
, test "52" (assertEqual "52" (raindrops 52)) \() -> Expect.equal "Plang" (raindrops 10)
, test "105" (assertEqual "PlingPlangPlong" (raindrops 105)) , test "14" <|
\() -> Expect.equal "Plong" (raindrops 14)
, test "15" <|
\() -> Expect.equal "PlingPlang" (raindrops 15)
, test "21" <|
\() -> Expect.equal "PlingPlong" (raindrops 21)
, test "25" <|
\() -> Expect.equal "Plang" (raindrops 25)
, test "35" <|
\() -> Expect.equal "PlangPlong" (raindrops 35)
, test "49" <|
\() -> Expect.equal "Plong" (raindrops 49)
, test "52" <|
\() -> Expect.equal "52" (raindrops 52)
, test "105" <|
\() -> Expect.equal "PlingPlangPlong" (raindrops 105)
] ]
main : Program Never main : Program Never
main = main =
runSuite tests run emit tests
port emit : ( String, Value ) -> Cmd msg

View file

@ -1,5 +1,5 @@
{ {
"version": "2.0.0", "version": "3.0.0",
"summary": "Exercism problems in Elm.", "summary": "Exercism problems in Elm.",
"repository": "https://github.com/exercism/xelm.git", "repository": "https://github.com/exercism/xelm.git",
"license": "BSD3", "license": "BSD3",
@ -8,8 +8,9 @@
], ],
"exposed-modules": [], "exposed-modules": [],
"dependencies": { "dependencies": {
"elm-community/elm-test": "1.0.0 <= v < 2.0.0", "elm-lang/core": "4.0.0 <= v < 5.0.0",
"elm-lang/core": "4.0.0 <= v < 5.0.0" "elm-community/elm-test": "2.0.0 <= v < 3.0.0",
"rtfeldman/node-test-runner": "1.0.0 <= v < 2.0.0"
}, },
"elm-version": "0.17.0 <= v < 0.18.0" "elm-version": "0.17.0 <= v < 0.18.0"
} }

View file

@ -1,4 +0,0 @@
@echo off
for %%f in (*Tests.elm) do (
elm-make %%f --yes --output build.js && node build.js
)

View file

@ -1,2 +0,0 @@
#!/usr/bin/env bash
elm-make *Tests.elm --yes --output build.js && node build.js

View file

@ -1,29 +1,35 @@
module Main exposing (..) port module Main exposing (..)
import ElmTest exposing (..) import Test.Runner.Node exposing (run)
import Json.Encode exposing (Value)
import Test exposing (..)
import Expect
import RNATranscription exposing (toRNA) import RNATranscription exposing (toRNA)
tests : Test tests : Test
tests = tests =
suite "RNATranscription" describe "RNATranscription"
[ test "complement of cytosine is guanine" [ test "complement of cytosine is guanine" <|
(assertEqual (Ok "G") (toRNA "C")) \() -> Expect.equal (Ok "G") (toRNA "C")
, test "complement of guanine is cytosine" , test "complement of guanine is cytosine" <|
(assertEqual (Ok "C") (toRNA "G")) \() -> Expect.equal (Ok "C") (toRNA "G")
, test "complement of thymine is adenine" , test "complement of thymine is adenine" <|
(assertEqual (Ok "A") (toRNA "T")) \() -> Expect.equal (Ok "A") (toRNA "T")
, test "complement of adenine is uracil" , test "complement of adenine is uracil" <|
(assertEqual (Ok "U") (toRNA "A")) \() -> Expect.equal (Ok "U") (toRNA "A")
, test "complement" , test "complement" <|
(assertEqual (Ok "UGCACCAGAAUU") (toRNA "ACGTGGTCTTAA")) \() -> Expect.equal (Ok "UGCACCAGAAUU") (toRNA "ACGTGGTCTTAA")
, test "correctly handles completely invalid input" , test "correctly handles completely invalid input" <|
(assertEqual (Err 'X') (toRNA "XXX")) \() -> Expect.equal (Err 'X') (toRNA "XXX")
, test "correctly handles partially invalid input" , test "correctly handles partially invalid input" <|
(assertEqual (Err 'U') (toRNA "UGAAXXXGACAUG")) \() -> Expect.equal (Err 'U') (toRNA "UGAAXXXGACAUG")
] ]
main : Program Never main : Program Never
main = main =
runSuite tests run emit tests
port emit : ( String, Value ) -> Cmd msg

View file

@ -1,5 +1,5 @@
{ {
"version": "2.0.0", "version": "3.0.0",
"summary": "Exercism problems in Elm.", "summary": "Exercism problems in Elm.",
"repository": "https://github.com/exercism/xelm.git", "repository": "https://github.com/exercism/xelm.git",
"license": "BSD3", "license": "BSD3",
@ -8,8 +8,9 @@
], ],
"exposed-modules": [], "exposed-modules": [],
"dependencies": { "dependencies": {
"elm-community/elm-test": "1.0.0 <= v < 2.0.0", "elm-lang/core": "4.0.0 <= v < 5.0.0",
"elm-lang/core": "4.0.0 <= v < 5.0.0" "elm-community/elm-test": "2.0.0 <= v < 3.0.0",
"rtfeldman/node-test-runner": "1.0.0 <= v < 2.0.0"
}, },
"elm-version": "0.17.0 <= v < 0.18.0" "elm-version": "0.17.0 <= v < 0.18.0"
} }

View file

@ -1,4 +0,0 @@
@echo off
for %%f in (*Tests.elm) do (
elm-make %%f --yes --output build.js && node build.js
)

View file

@ -1,2 +0,0 @@
#!/usr/bin/env bash
elm-make *Tests.elm --yes --output build.js && node build.js

View file

@ -1,117 +1,150 @@
module Main exposing (..) port module Main exposing (..)
import ElmTest exposing (..) import Test.Runner.Node exposing (run)
import Json.Encode exposing (Value)
import Test exposing (..)
import Expect
import RobotSimulator exposing (defaultRobot, Robot, Bearing(North, East, West, South), turnRight, turnLeft, advance, simulate) import RobotSimulator exposing (defaultRobot, Robot, Bearing(North, East, West, South), turnRight, turnLeft, advance, simulate)
tests : Test tests : Test
tests = tests =
suite "RobotSimulator" describe "RobotSimulator"
[ suite "init" [ describe "init"
(let (let
robot = robot =
defaultRobot defaultRobot
in in
[ test "coordinates" (assertEqual { x = 0, y = 0 } robot.coordinates) [ test "coordinates" <|
, test "bearing" (assertEqual North robot.bearing) \() -> Expect.equal { x = 0, y = 0 } robot.coordinates
, test "bearing" <|
\() -> Expect.equal North robot.bearing
] ]
) )
, suite "setup" , describe "setup"
(let (let
robot = robot =
Robot South { x = -1, y = 1 } Robot South { x = -1, y = 1 }
in in
[ test "coordinates" (assertEqual { x = -1, y = 1 } robot.coordinates) [ test "coordinates" <|
, test "bearing" (assertEqual South robot.bearing) \() -> Expect.equal { x = -1, y = 1 } robot.coordinates
, test "bearing" <|
\() -> Expect.equal South robot.bearing
] ]
) )
, suite "turn right" , describe "turn right"
([1..3] ([1..3]
|> List.scanl (\_ r -> turnRight r) defaultRobot |> List.scanl (\_ r -> turnRight r) defaultRobot
|> List.map .bearing |> List.map .bearing
|> assertionList [ North, East, South, West ] |> assertionList [ North, East, South, West ]
|> List.map defaultTest |> List.indexedMap (\i e -> test ("step " ++ toString i) (\() -> e))
) )
, suite "turn left" , describe
"turn left"
([1..3] ([1..3]
|> List.scanl (\_ r -> turnLeft r) defaultRobot |> List.scanl (\_ r -> turnLeft r) defaultRobot
|> List.map .bearing |> List.map .bearing
|> assertionList [ North, West, South, East ] |> assertionList [ North, West, South, East ]
|> List.map defaultTest |> List.indexedMap (\i e -> test ("step " ++ toString i) (\() -> e))
) )
, suite "advance positive north" , describe "advance positive north"
(let (let
robot = robot =
Robot North { x = 0, y = 0 } Robot North { x = 0, y = 0 }
|> advance |> advance
in in
[ test "coordinates" (assertEqual { x = 0, y = 1 } robot.coordinates) [ test "coordinates" <|
, test "bearing" (assertEqual North robot.bearing) \() -> Expect.equal { x = 0, y = 1 } robot.coordinates
, test "bearing" <|
\() -> Expect.equal North robot.bearing
] ]
) )
, suite "advance positive east" , describe "advance positive east"
(let (let
robot = robot =
Robot East { x = 0, y = 0 } Robot East { x = 0, y = 0 }
|> advance |> advance
in in
[ test "coordinates" (assertEqual { x = 1, y = 0 } robot.coordinates) [ test "coordinates" <|
, test "bearing" (assertEqual East robot.bearing) \() -> Expect.equal { x = 1, y = 0 } robot.coordinates
, test "bearing" <|
\() -> Expect.equal East robot.bearing
] ]
) )
, suite "advance negative south" , describe "advance negative south"
(let (let
robot = robot =
Robot South { x = 0, y = 0 } Robot South { x = 0, y = 0 }
|> advance |> advance
in in
[ test "coordinates" (assertEqual { x = 0, y = -1 } robot.coordinates) [ test "coordinates" <|
, test "bearing" (assertEqual South robot.bearing) \() -> Expect.equal { x = 0, y = -1 } robot.coordinates
, test "bearing" <|
\() -> Expect.equal South robot.bearing
] ]
) )
, suite "advance positive west" , describe "advance positive west"
(let (let
robot = robot =
Robot West { x = 0, y = 0 } Robot West { x = 0, y = 0 }
|> advance |> advance
in in
[ test "coordinates" (assertEqual { x = -1, y = 0 } robot.coordinates) [ test "coordinates" <|
, test "bearing" (assertEqual West robot.bearing) \() -> Expect.equal { x = -1, y = 0 } robot.coordinates
, test "bearing" <|
\() -> Expect.equal West robot.bearing
] ]
) )
, suite "simulate prog 1" , describe "simulate prog 1"
(let (let
robot = robot =
Robot North { x = 0, y = 0 } Robot North { x = 0, y = 0 }
|> simulate "LAAARALA" |> simulate "LAAARALA"
in in
[ test "coordinates" (assertEqual { x = -4, y = 1 } robot.coordinates) [ test "coordinates" <|
, test "bearing" (assertEqual West robot.bearing) \() -> Expect.equal { x = -4, y = 1 } robot.coordinates
, test "bearing" <|
\() -> Expect.equal West robot.bearing
] ]
) )
, suite "simulate prog 2" , describe "simulate prog 2"
(let (let
robot = robot =
Robot East { x = 2, y = -7 } Robot East { x = 2, y = -7 }
|> simulate "RRAAAAALA" |> simulate "RRAAAAALA"
in in
[ test "coordinates" (assertEqual { x = -3, y = -8 } robot.coordinates) [ test "coordinates" <|
, test "bearing" (assertEqual South robot.bearing) \() -> Expect.equal { x = -3, y = -8 } robot.coordinates
, test "bearing" <|
\() -> Expect.equal South robot.bearing
] ]
) )
, suite "simulate prog 3" , describe "simulate prog 3"
(let (let
robot = robot =
Robot South { x = 8, y = 4 } Robot South { x = 8, y = 4 }
|> simulate "LAAARRRALLLL" |> simulate "LAAARRRALLLL"
in in
[ test "coordinates" (assertEqual { x = 11, y = 5 } robot.coordinates) [ test "coordinates" <|
, test "bearing" (assertEqual North robot.bearing) \() -> Expect.equal { x = 11, y = 5 } robot.coordinates
, test "bearing" <|
\() -> Expect.equal North robot.bearing
] ]
) )
] ]
{-| Given a list of values and another list of expected values,
generate a list of Assert Equal assertions.
-}
assertionList : List a -> List a -> List Expect.Expectation
assertionList xs ys =
List.map2 Expect.equal xs ys
main : Program Never main : Program Never
main = main =
runSuite tests run emit tests
port emit : ( String, Value ) -> Cmd msg

View file

@ -1,5 +1,5 @@
{ {
"version": "2.0.0", "version": "3.0.0",
"summary": "Exercism problems in Elm.", "summary": "Exercism problems in Elm.",
"repository": "https://github.com/exercism/xelm.git", "repository": "https://github.com/exercism/xelm.git",
"license": "BSD3", "license": "BSD3",
@ -8,8 +8,9 @@
], ],
"exposed-modules": [], "exposed-modules": [],
"dependencies": { "dependencies": {
"elm-community/elm-test": "1.0.0 <= v < 2.0.0", "elm-lang/core": "4.0.0 <= v < 5.0.0",
"elm-lang/core": "4.0.0 <= v < 5.0.0" "elm-community/elm-test": "2.0.0 <= v < 3.0.0",
"rtfeldman/node-test-runner": "1.0.0 <= v < 2.0.0"
}, },
"elm-version": "0.17.0 <= v < 0.18.0" "elm-version": "0.17.0 <= v < 0.18.0"
} }

View file

@ -1,4 +0,0 @@
@echo off
for %%f in (*Tests.elm) do (
elm-make %%f --yes --output build.js && node build.js
)

View file

@ -1,2 +0,0 @@
#!/usr/bin/env bash
elm-make *Tests.elm --yes --output build.js && node build.js

View file

@ -6,41 +6,45 @@ import Maybe
toRoman : Int -> String toRoman : Int -> String
toRoman number = toRoman number =
if number == 0 then if number == 0 then
"" ""
else else
let let
part = largestFactor number part =
letter = largestFactor number
numerals
|> Dict.get part letter =
|> Maybe.withDefault "" numerals
in |> Dict.get part
letter ++ (toRoman (number - part)) |> Maybe.withDefault ""
in
letter ++ (toRoman (number - part))
largestFactor : Int -> Int largestFactor : Int -> Int
largestFactor number = largestFactor number =
numerals numerals
|> Dict.keys |> Dict.keys
|> List.filter (\p -> p <= number) |> List.filter (\p -> p <= number)
|> List.reverse |> List.reverse
|> List.head |> List.head
|> Maybe.withDefault 0 |> Maybe.withDefault 0
numerals : Dict.Dict Int String numerals : Dict.Dict Int String
numerals = Dict.fromList [ numerals =
(1000, "M"), Dict.fromList
( 900, "CM"), [ ( 1000, "M" )
( 500, "D"), , ( 900, "CM" )
( 400, "CD"), , ( 500, "D" )
( 100, "C"), , ( 400, "CD" )
( 90, "XC"), , ( 100, "C" )
( 50, "L"), , ( 90, "XC" )
( 40, "XL"), , ( 50, "L" )
( 10, "X"), , ( 40, "XL" )
( 9, "IX"), , ( 10, "X" )
( 5, "V"), , ( 9, "IX" )
( 4, "IV"), , ( 5, "V" )
( 1, "I") , ( 4, "IV" )
] , ( 1, "I" )
]

View file

@ -1,86 +1,93 @@
module Main exposing (..) port module Main exposing (..)
import ElmTest exposing (..) import Test.Runner.Node exposing (run)
import Json.Encode exposing (Value)
import Test exposing (..)
import Expect
import RomanNumerals exposing (toRoman) import RomanNumerals exposing (toRoman)
tests : Test tests : Test
tests = tests =
suite "Roman Numerals" describe "Roman Numerals"
[ test "1" [ test "1" <|
(assertEqual ("I") \() ->
(toRoman 1) Expect.equal ("I")
) (toRoman 1)
, test "2" , test "2" <|
(assertEqual ("II") \() ->
(toRoman 2) Expect.equal ("II")
) (toRoman 2)
, test "3" , test "3" <|
(assertEqual ("III") \() ->
(toRoman 3) Expect.equal ("III")
) (toRoman 3)
, test "4" , test "4" <|
(assertEqual ("IV") \() ->
(toRoman 4) Expect.equal ("IV")
) (toRoman 4)
, test "5" , test "5" <|
(assertEqual ("V") \() ->
(toRoman 5) Expect.equal ("V")
) (toRoman 5)
, test "6" , test "6" <|
(assertEqual ("VI") \() ->
(toRoman 6) Expect.equal ("VI")
) (toRoman 6)
, test "9" , test "9" <|
(assertEqual ("IX") \() ->
(toRoman 9) Expect.equal ("IX")
) (toRoman 9)
, test "27" , test "27" <|
(assertEqual ("XXVII") \() ->
(toRoman 27) Expect.equal ("XXVII")
) (toRoman 27)
, test "48" , test "48" <|
(assertEqual ("XLVIII") \() ->
(toRoman 48) Expect.equal ("XLVIII")
) (toRoman 48)
, test "59" , test "59" <|
(assertEqual ("LIX") \() ->
(toRoman 59) Expect.equal ("LIX")
) (toRoman 59)
, test "93" , test "93" <|
(assertEqual ("XCIII") \() ->
(toRoman 93) Expect.equal ("XCIII")
) (toRoman 93)
, test "141" , test "141" <|
(assertEqual ("CXLI") \() ->
(toRoman 141) Expect.equal ("CXLI")
) (toRoman 141)
, test "163" , test "163" <|
(assertEqual ("CLXIII") \() ->
(toRoman 163) Expect.equal ("CLXIII")
) (toRoman 163)
, test "402" , test "402" <|
(assertEqual ("CDII") \() ->
(toRoman 402) Expect.equal ("CDII")
) (toRoman 402)
, test "575" , test "575" <|
(assertEqual ("DLXXV") \() ->
(toRoman 575) Expect.equal ("DLXXV")
) (toRoman 575)
, test "911" , test "911" <|
(assertEqual ("CMXI") \() ->
(toRoman 911) Expect.equal ("CMXI")
) (toRoman 911)
, test "1024" , test "1024" <|
(assertEqual ("MXXIV") \() ->
(toRoman 1024) Expect.equal ("MXXIV")
) (toRoman 1024)
, test "3000" , test "3000" <|
(assertEqual ("MMM") \() ->
(toRoman 3000) Expect.equal ("MMM")
) (toRoman 3000)
] ]
main : Program Never main : Program Never
main = main =
runSuite tests run emit tests
port emit : ( String, Value ) -> Cmd msg

View file

@ -1,5 +1,5 @@
{ {
"version": "2.0.0", "version": "3.0.0",
"summary": "Exercism problems in Elm.", "summary": "Exercism problems in Elm.",
"repository": "https://github.com/exercism/xelm.git", "repository": "https://github.com/exercism/xelm.git",
"license": "BSD3", "license": "BSD3",
@ -8,8 +8,9 @@
], ],
"exposed-modules": [], "exposed-modules": [],
"dependencies": { "dependencies": {
"elm-community/elm-test": "1.0.0 <= v < 2.0.0", "elm-lang/core": "4.0.0 <= v < 5.0.0",
"elm-lang/core": "4.0.0 <= v < 5.0.0" "elm-community/elm-test": "2.0.0 <= v < 3.0.0",
"rtfeldman/node-test-runner": "1.0.0 <= v < 2.0.0"
}, },
"elm-version": "0.17.0 <= v < 0.18.0" "elm-version": "0.17.0 <= v < 0.18.0"
} }

View file

@ -1,4 +0,0 @@
@echo off
for %%f in (*Tests.elm) do (
elm-make %%f --yes --output build.js && node build.js
)

View file

@ -1,2 +0,0 @@
#!/usr/bin/env bash
elm-make *Tests.elm --yes --output build.js && node build.js

View file

@ -1,41 +1,47 @@
module Main exposing (..) port module Main exposing (..)
import ElmTest exposing (..) import Test.Runner.Node exposing (run)
import Json.Encode exposing (Value)
import Test exposing (..)
import Expect
import RunLengthEncoding exposing (version, decode, encode) import RunLengthEncoding exposing (version, decode, encode)
tests : Test tests : Test
tests = tests =
suite "RunLengthEncoding" describe "RunLengthEncoding"
[ test "the solution is for the correct version of the test" [ test "the solution is for the correct version of the test" <|
(assertEqual 2 version) \() -> Expect.equal 2 version
, test "encode simple" , test "encode simple" <|
(assertEqual "2A3B4C" (encode "AABBBCCCC")) \() -> Expect.equal "2A3B4C" (encode "AABBBCCCC")
, test "decode simple" , test "decode simple" <|
(assertEqual "AABBBCCCC" (decode "2A3B4C")) \() -> Expect.equal "AABBBCCCC" (decode "2A3B4C")
, test "encode with single values" , test "encode with single values" <|
(assertEqual "12WB12W3B24WB" \() ->
(encode "WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB") Expect.equal "12WB12W3B24WB"
) (encode "WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB")
, test "decode with single values" , test "decode with single values" <|
(assertEqual "WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB" \() ->
(decode "12WB12W3B24WB") Expect.equal "WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB"
) (decode "12WB12W3B24WB")
, test "(decode (encode (...)) combination" , test "(decode (encode (...)) combination" <|
(assertEqual "zzz ZZ zZ" \() ->
(decode (encode "zzz ZZ zZ")) Expect.equal "zzz ZZ zZ"
) (decode (encode "zzz ZZ zZ"))
, test "decode with a x10 value" , test "decode with a x10 value" <|
(assertEqual "WWWWWWWWWW" \() ->
(decode "10W") Expect.equal "WWWWWWWWWW"
) (decode "10W")
, test "encode unicode" , test "encode unicode" <|
(assertEqual "32" (encode "")) \() -> Expect.equal "32" (encode "")
, test "decode unicode" , test "decode unicode" <|
(assertEqual "" (decode "32")) \() -> Expect.equal "" (decode "32")
] ]
main : Program Never main : Program Never
main = main =
runSuite tests run emit tests
port emit : ( String, Value ) -> Cmd msg

View file

@ -1,5 +1,5 @@
{ {
"version": "2.0.0", "version": "3.0.0",
"summary": "Exercism problems in Elm.", "summary": "Exercism problems in Elm.",
"repository": "https://github.com/exercism/xelm.git", "repository": "https://github.com/exercism/xelm.git",
"license": "BSD3", "license": "BSD3",
@ -8,8 +8,9 @@
], ],
"exposed-modules": [], "exposed-modules": [],
"dependencies": { "dependencies": {
"elm-community/elm-test": "1.0.0 <= v < 2.0.0", "elm-lang/core": "4.0.0 <= v < 5.0.0",
"elm-lang/core": "4.0.0 <= v < 5.0.0" "elm-community/elm-test": "2.0.0 <= v < 3.0.0",
"rtfeldman/node-test-runner": "1.0.0 <= v < 2.0.0"
}, },
"elm-version": "0.17.0 <= v < 0.18.0" "elm-version": "0.17.0 <= v < 0.18.0"
} }

View file

@ -1,4 +0,0 @@
@echo off
for %%f in (*Tests.elm) do (
elm-make %%f --yes --output build.js && node build.js
)

View file

@ -1,2 +0,0 @@
#!/usr/bin/env bash
elm-make *Tests.elm --yes --output build.js && node build.js

View file

@ -1,90 +1,96 @@
module Main exposing (..) port module Main exposing (..)
import ElmTest exposing (..) import Test.Runner.Node exposing (run)
import Json.Encode exposing (Value)
import Test exposing (..)
import Expect
import Say exposing (say, SayError(Negative, TooLarge)) import Say exposing (say, SayError(Negative, TooLarge))
tests : Test tests : Test
tests = tests =
suite "Series" describe "Series"
[ test "one" [ test "one" <|
(assertEqual (Ok "one") \() ->
(say 1) Expect.equal (Ok "one")
) (say 1)
, test "fourteen" , test "fourteen" <|
(assertEqual (Ok "fourteen") \() ->
(say 14) Expect.equal (Ok "fourteen")
) (say 14)
, test "twenty" , test "twenty" <|
(assertEqual (Ok "twenty") \() ->
(say 20) Expect.equal (Ok "twenty")
) (say 20)
, test "twenty-two" , test "twenty-two" <|
(assertEqual (Ok "twenty-two") \() ->
(say 22) Expect.equal (Ok "twenty-two")
) (say 22)
, test "one hundred" , test "one hundred" <|
(assertEqual (Ok "one hundred") \() ->
(say 100) Expect.equal (Ok "one hundred")
) (say 100)
, test "one hundred twenty" , test "one hundred twenty" <|
(assertEqual (Ok "one hundred and twenty") \() ->
(say 120) Expect.equal (Ok "one hundred and twenty")
) (say 120)
, test "one hundred twenty-three" , test "one hundred twenty-three" <|
(assertEqual (Ok "one hundred and twenty-three") \() ->
(say 123) Expect.equal (Ok "one hundred and twenty-three")
) (say 123)
, test "one thousand" , test "one thousand" <|
(assertEqual (Ok "one thousand") \() ->
(say 1000) Expect.equal (Ok "one thousand")
) (say 1000)
, test "one thousand two hundred thirty-four" , test "one thousand two hundred thirty-four" <|
(assertEqual (Ok "one thousand two hundred and thirty-four") \() ->
(say 1234) Expect.equal (Ok "one thousand two hundred and thirty-four")
) (say 1234)
, test "one million" , test "one million" <|
(assertEqual (Ok "one million") \() ->
(say 1000000) Expect.equal (Ok "one million")
) (say 1000000)
, test "one million two" , test "one million two" <|
(assertEqual (Ok "one million and two") \() ->
(say 1000002) Expect.equal (Ok "one million and two")
) (say 1000002)
, test "1002345" , test "1002345" <|
(assertEqual (Ok "one million two thousand three hundred and forty-five") \() ->
(say 1002345) Expect.equal (Ok "one million two thousand three hundred and forty-five")
) (say 1002345)
, test "one billion" , test "one billion" <|
(assertEqual (Ok "one billion") \() ->
(say 1000000000) Expect.equal (Ok "one billion")
) (say 1000000000)
, test "number too large" , test "number too large" <|
(assertEqual (Err TooLarge) \() ->
(say 10000000000000000) Expect.equal (Err TooLarge)
) (say 10000000000000000)
, test "negative number" , test "negative number" <|
(assertEqual (Err Negative) \() ->
(say -42) Expect.equal (Err Negative)
) (say -42)
, test "zero" , test "zero" <|
(assertEqual (Ok "zero") \() ->
(say 0) Expect.equal (Ok "zero")
) (say 0)
, test "987654321123" , test "987654321123" <|
(assertEqual \() ->
(Ok Expect.equal
("nine hundred and eighty-seven billion " (Ok
++ "six hundred and fifty-four million " ("nine hundred and eighty-seven billion "
++ "three hundred and twenty-one thousand " ++ "six hundred and fifty-four million "
++ "one hundred and twenty-three" ++ "three hundred and twenty-one thousand "
++ "one hundred and twenty-three"
)
) )
) (say 987654321123)
(say 987654321123)
)
] ]
main : Program Never main : Program Never
main = main =
runSuite tests run emit tests
port emit : ( String, Value ) -> Cmd msg

View file

@ -1,5 +1,5 @@
{ {
"version": "2.0.0", "version": "3.0.0",
"summary": "Exercism problems in Elm.", "summary": "Exercism problems in Elm.",
"repository": "https://github.com/exercism/xelm.git", "repository": "https://github.com/exercism/xelm.git",
"license": "BSD3", "license": "BSD3",
@ -8,8 +8,9 @@
], ],
"exposed-modules": [], "exposed-modules": [],
"dependencies": { "dependencies": {
"elm-community/elm-test": "1.0.0 <= v < 2.0.0", "elm-lang/core": "4.0.0 <= v < 5.0.0",
"elm-lang/core": "4.0.0 <= v < 5.0.0" "elm-community/elm-test": "2.0.0 <= v < 3.0.0",
"rtfeldman/node-test-runner": "1.0.0 <= v < 2.0.0"
}, },
"elm-version": "0.17.0 <= v < 0.18.0" "elm-version": "0.17.0 <= v < 0.18.0"
} }

View file

@ -1,4 +0,0 @@
@echo off
for %%f in (*Tests.elm) do (
elm-make %%f --yes --output build.js && node build.js
)

View file

@ -1,2 +0,0 @@
#!/usr/bin/env bash
elm-make *Tests.elm --yes --output build.js && node build.js

View file

@ -1,47 +1,53 @@
module Main exposing (..) port module Main exposing (..)
import ElmTest exposing (..) import Test.Runner.Node exposing (run)
import Json.Encode exposing (Value)
import Test exposing (..)
import Expect
import Series exposing (slices) import Series exposing (slices)
tests : Test tests : Test
tests = tests =
suite "Series" describe "Series"
[ test "slices of one" [ test "slices of one" <|
(assertEqual (Ok [ [ 0 ], [ 1 ], [ 2 ], [ 3 ], [ 4 ] ]) \() ->
(slices 1 "01234") Expect.equal (Ok [ [ 0 ], [ 1 ], [ 2 ], [ 3 ], [ 4 ] ])
) (slices 1 "01234")
, test "slices of two" , test "slices of two" <|
(assertEqual (Ok [ [ 9, 7 ], [ 7, 8 ], [ 8, 6 ], [ 6, 7 ], [ 7, 5 ], [ 5, 6 ], [ 6, 4 ] ]) \() ->
(slices 2 "97867564") Expect.equal (Ok [ [ 9, 7 ], [ 7, 8 ], [ 8, 6 ], [ 6, 7 ], [ 7, 5 ], [ 5, 6 ], [ 6, 4 ] ])
) (slices 2 "97867564")
, test "slices of three" , test "slices of three" <|
(assertEqual (Ok [ [ 9, 7, 8 ], [ 7, 8, 6 ], [ 8, 6, 7 ], [ 6, 7, 5 ], [ 7, 5, 6 ], [ 5, 6, 4 ] ]) \() ->
(slices 3 "97867564") Expect.equal (Ok [ [ 9, 7, 8 ], [ 7, 8, 6 ], [ 8, 6, 7 ], [ 6, 7, 5 ], [ 7, 5, 6 ], [ 5, 6, 4 ] ])
) (slices 3 "97867564")
, test "slices of four" , test "slices of four" <|
(assertEqual (Ok [ [ 0, 1, 2, 3 ], [ 1, 2, 3, 4 ] ]) \() ->
(slices 4 "01234") Expect.equal (Ok [ [ 0, 1, 2, 3 ], [ 1, 2, 3, 4 ] ])
) (slices 4 "01234")
, test "slices of five" , test "slices of five" <|
(assertEqual (Ok [ [ 0, 1, 2, 3, 4 ] ]) \() ->
(slices 5 "01234") Expect.equal (Ok [ [ 0, 1, 2, 3, 4 ] ])
) (slices 5 "01234")
, test "overly long slice" , test "overly long slice" <|
(assertEqual (Ok []) \() ->
(slices 4 "012") Expect.equal (Ok [])
) (slices 4 "012")
, test "overly short slice" , test "overly short slice" <|
(assertEqual (Err ("Invalid size: 0")) \() ->
(slices 0 "01234") Expect.equal (Err ("Invalid size: 0"))
) (slices 0 "01234")
, test "input has non numbers" , test "input has non numbers" <|
(assertEqual (Err "could not convert string 'a' to an Int") \() ->
(slices 2 "0123abc") Expect.equal (Err "could not convert string 'a' to an Int")
) (slices 2 "0123abc")
] ]
main : Program Never main : Program Never
main = main =
runSuite tests run emit tests
port emit : ( String, Value ) -> Cmd msg

View file

@ -1,5 +1,5 @@
{ {
"version": "2.0.0", "version": "3.0.0",
"summary": "Exercism problems in Elm.", "summary": "Exercism problems in Elm.",
"repository": "https://github.com/exercism/xelm.git", "repository": "https://github.com/exercism/xelm.git",
"license": "BSD3", "license": "BSD3",
@ -8,8 +8,9 @@
], ],
"exposed-modules": [], "exposed-modules": [],
"dependencies": { "dependencies": {
"elm-community/elm-test": "1.0.0 <= v < 2.0.0", "elm-lang/core": "4.0.0 <= v < 5.0.0",
"elm-lang/core": "4.0.0 <= v < 5.0.0" "elm-community/elm-test": "2.0.0 <= v < 3.0.0",
"rtfeldman/node-test-runner": "1.0.0 <= v < 2.0.0"
}, },
"elm-version": "0.17.0 <= v < 0.18.0" "elm-version": "0.17.0 <= v < 0.18.0"
} }

View file

@ -1,4 +0,0 @@
@echo off
for %%f in (*Tests.elm) do (
elm-make %%f --yes --output build.js && node build.js
)

View file

@ -1,2 +0,0 @@
#!/usr/bin/env bash
elm-make *Tests.elm --yes --output build.js && node build.js

View file

@ -1,31 +1,37 @@
module Main exposing (..) port module Main exposing (..)
import ElmTest exposing (..) import Test.Runner.Node exposing (run)
import Json.Encode exposing (Value)
import Test exposing (..)
import Expect
import SpaceAge exposing (Planet(..), ageOn) import SpaceAge exposing (Planet(..), ageOn)
tests : Test tests : Test
tests = tests =
suite "SpaceAge" describe "SpaceAge"
[ test "age in earth years" [ test "age in earth years" <|
(assertEqual 32 (round (ageOn Earth 1000000000))) \() -> Expect.equal 32 (round (ageOn Earth 1000000000))
, test "age in mercury years" , test "age in mercury years" <|
(assertEqual 281 (round (ageOn Mercury 2134835688))) \() -> Expect.equal 281 (round (ageOn Mercury 2134835688))
, test "age in venus years" , test "age in venus years" <|
(assertEqual 10 (round (ageOn Venus 189839836))) \() -> Expect.equal 10 (round (ageOn Venus 189839836))
, test "age on mars" , test "age on mars" <|
(assertEqual 39 (round (ageOn Mars 2329871239))) \() -> Expect.equal 39 (round (ageOn Mars 2329871239))
, test "age on jupiter" , test "age on jupiter" <|
(assertEqual 2 (round (ageOn Jupiter 901876382))) \() -> Expect.equal 2 (round (ageOn Jupiter 901876382))
, test "age on saturn" , test "age on saturn" <|
(assertEqual 3 (round (ageOn Saturn 3000000000))) \() -> Expect.equal 3 (round (ageOn Saturn 3000000000))
, test "age on uranus" , test "age on uranus" <|
(assertEqual 1 (round (ageOn Uranus 3210123456))) \() -> Expect.equal 1 (round (ageOn Uranus 3210123456))
, test "age on neptune" , test "age on neptune" <|
(assertEqual 2 (round (ageOn Neptune 8210123456))) \() -> Expect.equal 2 (round (ageOn Neptune 8210123456))
] ]
main : Program Never main : Program Never
main = main =
runSuite tests run emit tests
port emit : ( String, Value ) -> Cmd msg

View file

@ -1,5 +1,5 @@
{ {
"version": "2.0.0", "version": "3.0.0",
"summary": "Exercism problems in Elm.", "summary": "Exercism problems in Elm.",
"repository": "https://github.com/exercism/xelm.git", "repository": "https://github.com/exercism/xelm.git",
"license": "BSD3", "license": "BSD3",
@ -8,8 +8,9 @@
], ],
"exposed-modules": [], "exposed-modules": [],
"dependencies": { "dependencies": {
"elm-community/elm-test": "1.0.0 <= v < 2.0.0", "elm-lang/core": "4.0.0 <= v < 5.0.0",
"elm-lang/core": "4.0.0 <= v < 5.0.0" "elm-community/elm-test": "2.0.0 <= v < 3.0.0",
"rtfeldman/node-test-runner": "1.0.0 <= v < 2.0.0"
}, },
"elm-version": "0.17.0 <= v < 0.18.0" "elm-version": "0.17.0 <= v < 0.18.0"
} }

View file

@ -1,4 +0,0 @@
@echo off
for %%f in (*Tests.elm) do (
elm-make %%f --yes --output build.js && node build.js
)

View file

@ -1,2 +0,0 @@
#!/usr/bin/env bash
elm-make *Tests.elm --yes --output build.js && node build.js

View file

@ -1,6 +1,9 @@
module Main exposing (..) port module Main exposing (..)
import ElmTest exposing (..) import Test.Runner.Node exposing (run)
import Json.Encode exposing (Value)
import Test exposing (..)
import Expect
import Strain exposing (keep, discard) import Strain exposing (keep, discard)
import String import String
@ -27,58 +30,61 @@ lessThanTen num =
tests : Test tests : Test
tests = tests =
suite "Strain" describe "Strain"
[ test "empty keep" [ test "empty keep" <|
(assertEqual [] \() ->
(keep lessThanTen []) Expect.equal []
) (keep lessThanTen [])
, test "keep everything" , test "keep everything" <|
(assertEqual [ 1, 2, 3 ] \() ->
(keep lessThanTen [ 1, 2, 3 ]) Expect.equal [ 1, 2, 3 ]
) (keep lessThanTen [ 1, 2, 3 ])
, test "keep first and last" , test "keep first and last" <|
(assertEqual [ 1, 3 ] \() ->
(keep odd [ 1, 2, 3 ]) Expect.equal [ 1, 3 ]
) (keep odd [ 1, 2, 3 ])
, test "keep nothing" , test "keep nothing" <|
(assertEqual [] \() ->
(keep even [ 1, 3, 5, 7 ]) Expect.equal []
) (keep even [ 1, 3, 5, 7 ])
, test "keep neither first nor last" , test "keep neither first nor last" <|
(assertEqual [ 2 ] \() ->
(keep even [ 1, 2, 3 ]) Expect.equal [ 2 ]
) (keep even [ 1, 2, 3 ])
, test "keep strings" , test "keep strings" <|
(assertEqual [ "zebra", "zombies", "zealot" ] \() ->
(keep (isFirstLetter "z") [ "apple", "zebra", "banana", "zombies", "cherimoya", "zealot" ]) Expect.equal [ "zebra", "zombies", "zealot" ]
) (keep (isFirstLetter "z") [ "apple", "zebra", "banana", "zombies", "cherimoya", "zealot" ])
, test "empty discard" , test "empty discard" <|
(assertEqual [] \() ->
(discard lessThanTen []) Expect.equal []
) (discard lessThanTen [])
, test "discard everything" , test "discard everything" <|
(assertEqual [] \() ->
(discard lessThanTen [ 1, 2, 3 ]) Expect.equal []
) (discard lessThanTen [ 1, 2, 3 ])
, test "discard first and last" , test "discard first and last" <|
(assertEqual [ 2 ] \() ->
(discard odd [ 1, 2, 3 ]) Expect.equal [ 2 ]
) (discard odd [ 1, 2, 3 ])
, test "discard nothing" , test "discard nothing" <|
(assertEqual [ 1, 3, 5, 7 ] \() ->
(discard even [ 1, 3, 5, 7 ]) Expect.equal [ 1, 3, 5, 7 ]
) (discard even [ 1, 3, 5, 7 ])
, test "discard neither first nor last" , test "discard neither first nor last" <|
(assertEqual [ 1, 3 ] \() ->
(discard even [ 1, 2, 3 ]) Expect.equal [ 1, 3 ]
) (discard even [ 1, 2, 3 ])
, test "discard strings" , test "discard strings" <|
(assertEqual [ "apple", "banana", "cherimoya" ] \() ->
(discard (isFirstLetter "z") [ "apple", "zebra", "banana", "zombies", "cherimoya", "zealot" ]) Expect.equal [ "apple", "banana", "cherimoya" ]
) (discard (isFirstLetter "z") [ "apple", "zebra", "banana", "zombies", "cherimoya", "zealot" ])
] ]
main : Program Never main : Program Never
main = main =
runSuite tests run emit tests
port emit : ( String, Value ) -> Cmd msg

View file

@ -1,5 +1,5 @@
{ {
"version": "2.0.0", "version": "3.0.0",
"summary": "Exercism problems in Elm.", "summary": "Exercism problems in Elm.",
"repository": "https://github.com/exercism/xelm.git", "repository": "https://github.com/exercism/xelm.git",
"license": "BSD3", "license": "BSD3",
@ -8,8 +8,9 @@
], ],
"exposed-modules": [], "exposed-modules": [],
"dependencies": { "dependencies": {
"elm-community/elm-test": "1.0.0 <= v < 2.0.0", "elm-lang/core": "4.0.0 <= v < 5.0.0",
"elm-lang/core": "4.0.0 <= v < 5.0.0" "elm-community/elm-test": "2.0.0 <= v < 3.0.0",
"rtfeldman/node-test-runner": "1.0.0 <= v < 2.0.0"
}, },
"elm-version": "0.17.0 <= v < 0.18.0" "elm-version": "0.17.0 <= v < 0.18.0"
} }

Some files were not shown because too many files have changed in this diff Show more