mirror of
https://github.com/correl/elm.git
synced 2024-12-18 11:06:17 +00:00
Add raindrops exercise (closes #11)
This commit is contained in:
parent
e5d8f76941
commit
14cf73ed94
6 changed files with 74 additions and 2 deletions
|
@ -14,7 +14,8 @@
|
|||
"bob",
|
||||
"run-length-encoding",
|
||||
"difference-of-squares",
|
||||
"anagram"
|
||||
"anagram",
|
||||
"raindrops"
|
||||
],
|
||||
"deprecated": [
|
||||
|
||||
|
|
|
@ -14,7 +14,8 @@
|
|||
"./exercises/bob",
|
||||
"./exercises/run-length-encoding",
|
||||
"./exercises/difference-of-squares",
|
||||
"./exercises/anagram"
|
||||
"./exercises/anagram",
|
||||
"./exercises/raindrops"
|
||||
],
|
||||
"exposed-modules": [],
|
||||
"dependencies": {
|
||||
|
|
1
exercises/raindrops/Raindrops.elm
Normal file
1
exercises/raindrops/Raindrops.elm
Normal file
|
@ -0,0 +1 @@
|
|||
module Raindrops (..) where
|
20
exercises/raindrops/Raindrops.example
Normal file
20
exercises/raindrops/Raindrops.example
Normal file
|
@ -0,0 +1,20 @@
|
|||
module Raindrops where
|
||||
|
||||
import String
|
||||
|
||||
|
||||
raindrops : Int -> String
|
||||
raindrops number =
|
||||
let
|
||||
drops =
|
||||
[ if number % 3 == 0 then "Pling" else ""
|
||||
, if number % 5 == 0 then "Plang" else ""
|
||||
, if number % 7 == 0 then "Plong" else ""
|
||||
]
|
||||
result =
|
||||
String.join "" drops
|
||||
in
|
||||
if result == "" then
|
||||
toString number
|
||||
else
|
||||
result
|
33
exercises/raindrops/RaindropsTests.elm
Normal file
33
exercises/raindrops/RaindropsTests.elm
Normal file
|
@ -0,0 +1,33 @@
|
|||
module Main (..) where
|
||||
|
||||
import Task
|
||||
import Console
|
||||
import ElmTest exposing (..)
|
||||
import Raindrops exposing (raindrops)
|
||||
|
||||
|
||||
tests : Test
|
||||
tests =
|
||||
suite
|
||||
"Raindrops"
|
||||
[ test "1" (assertEqual "1" (raindrops 1))
|
||||
, test "3" (assertEqual "Pling" (raindrops 3))
|
||||
, test "5" (assertEqual "Plang" (raindrops 5))
|
||||
, test "7" (assertEqual "Plong" (raindrops 7))
|
||||
, test "6" (assertEqual "Pling" (raindrops 6))
|
||||
, test "9" (assertEqual "Pling" (raindrops 9))
|
||||
, test "10" (assertEqual "Plang" (raindrops 10))
|
||||
, test "14" (assertEqual "Plong" (raindrops 14))
|
||||
, test "15" (assertEqual "PlingPlang" (raindrops 15))
|
||||
, test "21" (assertEqual "PlingPlong" (raindrops 21))
|
||||
, test "25" (assertEqual "Plang" (raindrops 25))
|
||||
, test "35" (assertEqual "PlangPlong" (raindrops 35))
|
||||
, test "49" (assertEqual "Plong" (raindrops 49))
|
||||
, test "52" (assertEqual "52" (raindrops 52))
|
||||
, test "105" (assertEqual "PlingPlangPlong" (raindrops 105))
|
||||
]
|
||||
|
||||
|
||||
port runner : Signal (Task.Task x ())
|
||||
port runner =
|
||||
Console.run (consoleRunner tests)
|
16
exercises/raindrops/elm-package.json
Normal file
16
exercises/raindrops/elm-package.json
Normal file
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"version": "1.0.0",
|
||||
"summary": "Exercism problems in Elm.",
|
||||
"repository": "https://github.com/exercism/xelm.git",
|
||||
"license": "BSD3",
|
||||
"source-directories": [
|
||||
"."
|
||||
],
|
||||
"exposed-modules": [],
|
||||
"dependencies": {
|
||||
"deadfoxygrandpa/elm-test": "3.0.1 <= v < 4.0.0",
|
||||
"elm-lang/core": "2.0.0 <= v < 4.0.0",
|
||||
"laszlopandy/elm-console": "1.1.0 <= v < 2.0.0"
|
||||
},
|
||||
"elm-version": "0.15.0 <= v < 0.17.0"
|
||||
}
|
Loading…
Reference in a new issue