From b98c4dbacb6d2d886aaf4bc50f7139c6ae83e596 Mon Sep 17 00:00:00 2001 From: Erik Schierboom Date: Sun, 25 Dec 2016 10:57:15 +0100 Subject: [PATCH 1/3] Add grains exercise --- config.json | 5 ++++ exercises/grains/Grains.elm | 2 ++ exercises/grains/Grains.example.elm | 9 +++++++ exercises/grains/Tests.elm | 39 +++++++++++++++++++++++++++++ exercises/grains/elm-package.json | 16 ++++++++++++ exercises/grains/package.json | 13 ++++++++++ 6 files changed, 84 insertions(+) create mode 100644 exercises/grains/Grains.elm create mode 100644 exercises/grains/Grains.example.elm create mode 100644 exercises/grains/Tests.elm create mode 100644 exercises/grains/elm-package.json create mode 100644 exercises/grains/package.json diff --git a/config.json b/config.json index 087da15..6250e62 100644 --- a/config.json +++ b/config.json @@ -153,6 +153,11 @@ "slug": "gigasecond", "difficulty": 1, "topics": [] + }, + { + "slug": "grains", + "difficulty": 1, + "topics": [] } ], "deprecated": [], diff --git a/exercises/grains/Grains.elm b/exercises/grains/Grains.elm new file mode 100644 index 0000000..b79650d --- /dev/null +++ b/exercises/grains/Grains.elm @@ -0,0 +1,2 @@ +module Grains exposing (..) + diff --git a/exercises/grains/Grains.example.elm b/exercises/grains/Grains.example.elm new file mode 100644 index 0000000..44b946f --- /dev/null +++ b/exercises/grains/Grains.example.elm @@ -0,0 +1,9 @@ +module Grains exposing (..) + + +square : Int -> Maybe Int +square n = + if n < 1 then + Nothing + else + Just <| 2 ^ (n - 1) diff --git a/exercises/grains/Tests.elm b/exercises/grains/Tests.elm new file mode 100644 index 0000000..212220d --- /dev/null +++ b/exercises/grains/Tests.elm @@ -0,0 +1,39 @@ +port module Main exposing (..) + +import Test.Runner.Node exposing (run, TestProgram) +import Json.Encode exposing (Value) +import Test exposing (..) +import Expect +import Grains exposing (square) + + +tests : Test +tests = + describe "Grains" + [ describe "square" + [ test "of 1" <| + \() -> Expect.equal (Just 1) (square 1) + , test "of 2" <| + \() -> Expect.equal (Just 2) (square 2) + , test "of 3" <| + \() -> Expect.equal (Just 4) (square 3) + , test "of 4" <| + \() -> Expect.equal (Just 8) (square 4) + , test "of 16" <| + \() -> Expect.equal (Just 32768) (square 16) + , test "of 32" <| + \() -> Expect.equal (Just 2147483648) (square 32) + , test "square 0 raises an exception" <| + \() -> Expect.equal Nothing (square 0) + , test "negative square raises an exception" <| + \() -> Expect.equal Nothing (square -1) + ] + ] + + +main : TestProgram +main = + run emit tests + + +port emit : ( String, Value ) -> Cmd msg diff --git a/exercises/grains/elm-package.json b/exercises/grains/elm-package.json new file mode 100644 index 0000000..8939a5d --- /dev/null +++ b/exercises/grains/elm-package.json @@ -0,0 +1,16 @@ +{ + "version": "3.0.0", + "summary": "Exercism problems in Elm.", + "repository": "https://github.com/exercism/xelm.git", + "license": "BSD3", + "source-directories": [ + "." + ], + "exposed-modules": [], + "dependencies": { + "elm-lang/core": "5.0.0 <= v < 6.0.0", + "elm-community/elm-test": "3.0.0 <= v < 4.0.0", + "rtfeldman/node-test-runner": "3.0.0 <= v < 4.0.0" + }, + "elm-version": "0.18.0 <= v < 0.19.0" +} diff --git a/exercises/grains/package.json b/exercises/grains/package.json new file mode 100644 index 0000000..68d7329 --- /dev/null +++ b/exercises/grains/package.json @@ -0,0 +1,13 @@ +{ + "description": "Exercism/Elm", + "repository": "https://github.com/exercism/xelm.git", + "license": "MIT", + "scripts": { + "postinstall": "elm-package install -y", + "test": "elm-test Tests.elm" + }, + "dependencies": { + "elm": "^0.18.0", + "elm-test": "^0.18.0" + } +} From e3ef09ce99b5834b20ef9151a90294c814b82cea Mon Sep 17 00:00:00 2001 From: Erik Simmler Date: Sun, 28 May 2017 14:50:15 -0400 Subject: [PATCH 2/3] Update grains for elm-test 0.18.3 compatibility --- exercises/grains/elm-package.json | 4 +--- exercises/grains/package.json | 6 +++--- exercises/grains/{ => tests}/Tests.elm | 15 +++------------ exercises/grains/tests/elm-package.json | 16 ++++++++++++++++ 4 files changed, 23 insertions(+), 18 deletions(-) rename exercises/grains/{ => tests}/Tests.elm (84%) create mode 100644 exercises/grains/tests/elm-package.json diff --git a/exercises/grains/elm-package.json b/exercises/grains/elm-package.json index 8939a5d..894b41f 100644 --- a/exercises/grains/elm-package.json +++ b/exercises/grains/elm-package.json @@ -8,9 +8,7 @@ ], "exposed-modules": [], "dependencies": { - "elm-lang/core": "5.0.0 <= v < 6.0.0", - "elm-community/elm-test": "3.0.0 <= v < 4.0.0", - "rtfeldman/node-test-runner": "3.0.0 <= v < 4.0.0" + "elm-lang/core": "5.0.0 <= v < 6.0.0" }, "elm-version": "0.18.0 <= v < 0.19.0" } diff --git a/exercises/grains/package.json b/exercises/grains/package.json index 68d7329..479082f 100644 --- a/exercises/grains/package.json +++ b/exercises/grains/package.json @@ -4,10 +4,10 @@ "license": "MIT", "scripts": { "postinstall": "elm-package install -y", - "test": "elm-test Tests.elm" + "test": "elm-test" }, "dependencies": { - "elm": "^0.18.0", - "elm-test": "^0.18.0" + "elm": "0.18.0", + "elm-test": "0.18.3" } } diff --git a/exercises/grains/Tests.elm b/exercises/grains/tests/Tests.elm similarity index 84% rename from exercises/grains/Tests.elm rename to exercises/grains/tests/Tests.elm index 212220d..436464e 100644 --- a/exercises/grains/Tests.elm +++ b/exercises/grains/tests/Tests.elm @@ -1,10 +1,9 @@ -port module Main exposing (..) +module Tests exposing (..) -import Test.Runner.Node exposing (run, TestProgram) -import Json.Encode exposing (Value) -import Test exposing (..) import Expect import Grains exposing (square) +import Json.Encode exposing (Value) +import Test exposing (..) tests : Test @@ -29,11 +28,3 @@ tests = \() -> Expect.equal Nothing (square -1) ] ] - - -main : TestProgram -main = - run emit tests - - -port emit : ( String, Value ) -> Cmd msg diff --git a/exercises/grains/tests/elm-package.json b/exercises/grains/tests/elm-package.json new file mode 100644 index 0000000..2e70ae6 --- /dev/null +++ b/exercises/grains/tests/elm-package.json @@ -0,0 +1,16 @@ +{ + "version": "3.0.0", + "summary": "Exercism problems in Elm.", + "repository": "https://github.com/exercism/xelm.git", + "license": "BSD3", + "source-directories": [ + ".", + ".." + ], + "exposed-modules": [], + "dependencies": { + "elm-lang/core": "5.0.0 <= v < 6.0.0", + "elm-community/elm-test": "4.0.0 <= v < 5.0.0" + }, + "elm-version": "0.18.0 <= v < 0.19.0" +} From e908e0dd7a59de3c74e70e96dded9108522b2523 Mon Sep 17 00:00:00 2001 From: Erik Simmler Date: Sun, 28 May 2017 14:56:36 -0400 Subject: [PATCH 3/3] Add a note about the missing high value grains test cases --- exercises/grains/tests/Tests.elm | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/exercises/grains/tests/Tests.elm b/exercises/grains/tests/Tests.elm index 436464e..6fbc08e 100644 --- a/exercises/grains/tests/Tests.elm +++ b/exercises/grains/tests/Tests.elm @@ -26,5 +26,12 @@ tests = \() -> Expect.equal Nothing (square 0) , test "negative square raises an exception" <| \() -> Expect.equal Nothing (square -1) + {- + Where are the bigger test values?!? Because Javascript's numbers + can't represent values higher than `Number.MAX_SAFE_INTEGER` + (i.e. 9007199254740991), we chose to exclude these final values + to avoid the weirdness. A bit more information can be found + here: https://github.com/elm-lang/elm-compiler/issues/1246 + -} ] ]