mirror of
https://github.com/correl/elm.git
synced 2024-12-18 19:21:37 +00:00
commit
18f9db051a
6 changed files with 128 additions and 6 deletions
|
@ -2,12 +2,11 @@ for example_file in exercises/**/*.example
|
|||
do
|
||||
exercise_dir=$(dirname $example_file)
|
||||
exercise=$(basename $example_file .example)
|
||||
echo 'setting up .....'
|
||||
mv "$exercise_dir/$exercise.elm" "$exercise_dir/$exercise.impl"
|
||||
mv "$exercise_dir/$exercise.example" "$exercise_dir/$exercise.elm"
|
||||
echo 'building .....'
|
||||
elm-test exercises/**/*Tests.elm
|
||||
echo 'tearing down .....'
|
||||
echo '-------------------------------------------------------'
|
||||
echo "Testing $exercise"
|
||||
elm-test $exercise_dir/*Tests.elm
|
||||
mv "$exercise_dir/$exercise.elm" "$exercise_dir/$exercise.example"
|
||||
mv "$exercise_dir/$exercise.impl" "$exercise_dir/$exercise.elm"
|
||||
done
|
||||
|
|
|
@ -5,7 +5,8 @@
|
|||
"active": false,
|
||||
"test_pattern": "TODO",
|
||||
"problems": [
|
||||
"hello_world"
|
||||
"hello_world",
|
||||
"bob"
|
||||
],
|
||||
"deprecated": [
|
||||
|
||||
|
|
|
@ -5,7 +5,8 @@
|
|||
"license": "BSD3",
|
||||
"source-directories": [
|
||||
".",
|
||||
"./exercises/hello_world"
|
||||
"./exercises/hello_world",
|
||||
"./exercises/bob"
|
||||
],
|
||||
"exposed-modules": [],
|
||||
"dependencies": {
|
||||
|
|
1
exercises/bob/Bob.elm
Normal file
1
exercises/bob/Bob.elm
Normal file
|
@ -0,0 +1 @@
|
|||
module Bob where
|
47
exercises/bob/Bob.example
Normal file
47
exercises/bob/Bob.example
Normal file
|
@ -0,0 +1,47 @@
|
|||
module Bob where
|
||||
|
||||
|
||||
import String
|
||||
import Regex
|
||||
|
||||
|
||||
hey : String -> String
|
||||
hey remark =
|
||||
if isShouting remark then
|
||||
"Whoa, chill out!"
|
||||
else if isQuestion remark then
|
||||
"Sure."
|
||||
else if isSilence remark then
|
||||
"Fine. Be that way!"
|
||||
else
|
||||
"Whatever."
|
||||
|
||||
|
||||
isShouting : String -> Bool
|
||||
isShouting remark =
|
||||
isUppercase remark && hasCharacters remark
|
||||
|
||||
|
||||
isUppercase : String -> Bool
|
||||
isUppercase remark =
|
||||
remark == String.toUpper remark
|
||||
|
||||
|
||||
isQuestion : String -> Bool
|
||||
isQuestion remark =
|
||||
String.endsWith "?" remark
|
||||
|
||||
|
||||
hasCharacters : String -> Bool
|
||||
hasCharacters remark =
|
||||
Regex.contains characterRegex remark
|
||||
|
||||
|
||||
characterRegex : Regex.Regex
|
||||
characterRegex =
|
||||
Regex.regex "[a-zA-Z]"
|
||||
|
||||
|
||||
isSilence : String -> Bool
|
||||
isSilence remark =
|
||||
String.isEmpty (String.trim remark)
|
73
exercises/bob/BobTests.elm
Normal file
73
exercises/bob/BobTests.elm
Normal file
|
@ -0,0 +1,73 @@
|
|||
import Task
|
||||
import Console
|
||||
import ElmTest exposing (..)
|
||||
import String
|
||||
import Char
|
||||
import Random
|
||||
import Bob
|
||||
|
||||
|
||||
tests : Test
|
||||
tests =
|
||||
suite "Bob"
|
||||
[ test "stating something" (assertEqual "Whatever." (Bob.hey "Tom-ay-to, tom-aaaah-to."))
|
||||
, test "shouting" (assertEqual "Whoa, chill out!" (Bob.hey "WATCH OUT!"))
|
||||
, test "shouting gibberish" (assertEqual "Whoa, chill out!" (Bob.hey (uppercaseGibberish 10)))
|
||||
, test "asking a question" (assertEqual "Sure." (Bob.hey "Does this cryogenic chamber make me look fat?"))
|
||||
, test "asking a numeric question" (assertEqual "Sure." (Bob.hey "You are, what, like 15?"))
|
||||
, test "asking gibberish" (assertEqual "Sure." (Bob.hey (gibberishQuestion 20)))
|
||||
, test "talking forcefully" (assertEqual "Whatever." (Bob.hey "Let's go make out behind the gym!"))
|
||||
, test "using acronyms in regular speech" (assertEqual "Whatever." (Bob.hey "It's OK if you don't want to go to the DMV."))
|
||||
, test "forceful questions" (assertEqual "Whoa, chill out!" (Bob.hey "WHAT THE HELL WERE YOU THINKING?"))
|
||||
, test "shouting numbers" (assertEqual "Whoa, chill out!" (Bob.hey "1, 2, 3 GO!"))
|
||||
, test "only numbers" (assertEqual "Whatever." (Bob.hey "1, 2, 3"))
|
||||
, test "question with only numbers" (assertEqual "Sure." (Bob.hey "4?"))
|
||||
, test "shouting with special characters" (assertEqual "Whoa, chill out!" (Bob.hey "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!)"))
|
||||
, test "shouting with no exclamation mark" (assertEqual "Whoa, chill out!" (Bob.hey "I HATE YOU"))
|
||||
, test "statement containing a question mark" (assertEqual "Whatever." (Bob.hey "Ending with ? means 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 ""))
|
||||
, test "prolonged silence" (assertEqual "Fine. Be that way!" (Bob.hey " "))
|
||||
, test "alternate silences" (assertEqual "Fine. Be that way!" (Bob.hey "\t \n \t "))
|
||||
, test "on multiple line questions" (assertEqual "Whatever." (Bob.hey "\nDoes this cryogenic chamber make me look fat?\nno"))
|
||||
]
|
||||
|
||||
|
||||
character : Int -> Int -> Random.Generator Char
|
||||
character start end =
|
||||
Random.map Char.fromCode (Random.int start end)
|
||||
|
||||
|
||||
anyCharacter : Random.Generator Char
|
||||
anyCharacter =
|
||||
character 32 126
|
||||
|
||||
|
||||
uppercaseCharacter : Random.Generator Char
|
||||
uppercaseCharacter =
|
||||
character 65 90
|
||||
|
||||
|
||||
listOfCharacters : Int -> Random.Generator Char -> Random.Generator (List Char)
|
||||
listOfCharacters length characterList =
|
||||
Random.list length characterList
|
||||
|
||||
|
||||
gibberish : Int -> Random.Generator Char -> String
|
||||
gibberish length characterList =
|
||||
fst (Random.generate (Random.map String.fromList (listOfCharacters length characterList)) (Random.initialSeed 424242))
|
||||
|
||||
|
||||
uppercaseGibberish : Int -> String
|
||||
uppercaseGibberish length =
|
||||
gibberish length uppercaseCharacter
|
||||
|
||||
|
||||
gibberishQuestion : Int -> String
|
||||
gibberishQuestion length =
|
||||
(gibberish length anyCharacter) ++ "?"
|
||||
|
||||
|
||||
port runner : Signal (Task.Task x ())
|
||||
port runner =
|
||||
Console.run (consoleRunner tests)
|
Loading…
Reference in a new issue