mirror of
https://github.com/correl/elm.git
synced 2024-12-23 03:00:08 +00:00
Add grains exercise
This commit is contained in:
parent
dcc2c05ed8
commit
b98c4dbacb
6 changed files with 84 additions and 0 deletions
|
@ -153,6 +153,11 @@
|
||||||
"slug": "gigasecond",
|
"slug": "gigasecond",
|
||||||
"difficulty": 1,
|
"difficulty": 1,
|
||||||
"topics": []
|
"topics": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"slug": "grains",
|
||||||
|
"difficulty": 1,
|
||||||
|
"topics": []
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"deprecated": [],
|
"deprecated": [],
|
||||||
|
|
2
exercises/grains/Grains.elm
Normal file
2
exercises/grains/Grains.elm
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
module Grains exposing (..)
|
||||||
|
|
9
exercises/grains/Grains.example.elm
Normal file
9
exercises/grains/Grains.example.elm
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
module Grains exposing (..)
|
||||||
|
|
||||||
|
|
||||||
|
square : Int -> Maybe Int
|
||||||
|
square n =
|
||||||
|
if n < 1 then
|
||||||
|
Nothing
|
||||||
|
else
|
||||||
|
Just <| 2 ^ (n - 1)
|
39
exercises/grains/Tests.elm
Normal file
39
exercises/grains/Tests.elm
Normal file
|
@ -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
|
16
exercises/grains/elm-package.json
Normal file
16
exercises/grains/elm-package.json
Normal file
|
@ -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"
|
||||||
|
}
|
13
exercises/grains/package.json
Normal file
13
exercises/grains/package.json
Normal file
|
@ -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"
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue