Add raindrops exercise (closes #11)

This commit is contained in:
Erik Simmler 2016-03-13 16:20:01 -04:00
parent e5d8f76941
commit 14cf73ed94
6 changed files with 74 additions and 2 deletions

View file

@ -14,7 +14,8 @@
"bob",
"run-length-encoding",
"difference-of-squares",
"anagram"
"anagram",
"raindrops"
],
"deprecated": [

View file

@ -14,7 +14,8 @@
"./exercises/bob",
"./exercises/run-length-encoding",
"./exercises/difference-of-squares",
"./exercises/anagram"
"./exercises/anagram",
"./exercises/raindrops"
],
"exposed-modules": [],
"dependencies": {

View file

@ -0,0 +1 @@
module Raindrops (..) where

View 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

View 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)

View 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"
}