|
| 1 | +port module Main exposing (..) |
| 2 | + |
| 3 | +import Test.Runner.Node exposing (run, TestProgram) |
| 4 | +import Json.Encode exposing (Value) |
| 5 | +import Test exposing (..) |
| 6 | +import Expect |
| 7 | +import String |
| 8 | +import Char |
| 9 | +import Random |
| 10 | +import Bob |
| 11 | + |
| 12 | + |
| 13 | +tests : Test |
| 14 | +tests = |
| 15 | + describe "Bob" |
| 16 | + [ test "stating something" <| |
| 17 | + \() -> |
| 18 | + Expect.equal "Whatever." |
| 19 | + (Bob.hey "Tom-ay-to, tom-aaaah-to.") |
| 20 | + , test "shouting" <| |
| 21 | + \() -> |
| 22 | + Expect.equal |
| 23 | + "Whoa, chill out!" |
| 24 | + (Bob.hey "WATCH OUT!") |
| 25 | + , test "shouting gibberish" <| |
| 26 | + \() -> |
| 27 | + Expect.equal |
| 28 | + "Whoa, chill out!" |
| 29 | + (Bob.hey (uppercaseGibberish 10)) |
| 30 | + , test "asking a question" <| |
| 31 | + \() -> |
| 32 | + Expect.equal |
| 33 | + "Sure." |
| 34 | + (Bob.hey "Does this cryogenic chamber make me look fat?") |
| 35 | + , test "asking a numeric question" <| |
| 36 | + \() -> |
| 37 | + Expect.equal |
| 38 | + "Sure." |
| 39 | + (Bob.hey "You are, what, like 15?") |
| 40 | + , test "asking gibberish" <| |
| 41 | + \() -> |
| 42 | + Expect.equal |
| 43 | + "Sure." |
| 44 | + (Bob.hey (gibberishQuestion 20)) |
| 45 | + , test "talking forcefully" <| |
| 46 | + \() -> |
| 47 | + Expect.equal |
| 48 | + "Whatever." |
| 49 | + (Bob.hey "Let's go make out behind the gym!") |
| 50 | + , test "using acronyms in regular speech" <| |
| 51 | + \() -> |
| 52 | + Expect.equal |
| 53 | + "Whatever." |
| 54 | + (Bob.hey "It's OK if you don't want to go to the DMV.") |
| 55 | + , test "forceful questions" <| |
| 56 | + \() -> |
| 57 | + Expect.equal |
| 58 | + "Whoa, chill out!" |
| 59 | + (Bob.hey "WHAT THE HELL WERE YOU THINKING?") |
| 60 | + , test "shouting numbers" <| |
| 61 | + \() -> |
| 62 | + Expect.equal |
| 63 | + "Whoa, chill out!" |
| 64 | + (Bob.hey "1, 2, 3 GO!") |
| 65 | + , test "only numbers" <| |
| 66 | + \() -> |
| 67 | + Expect.equal |
| 68 | + "Whatever." |
| 69 | + (Bob.hey "1, 2, 3") |
| 70 | + , test "question with only numbers" <| |
| 71 | + \() -> |
| 72 | + Expect.equal |
| 73 | + "Sure." |
| 74 | + (Bob.hey "4?") |
| 75 | + , test "shouting with special characters" <| |
| 76 | + \() -> |
| 77 | + Expect.equal |
| 78 | + "Whoa, chill out!" |
| 79 | + (Bob.hey "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!") |
| 80 | + , test "shouting with no exclamation mark" <| |
| 81 | + \() -> |
| 82 | + Expect.equal |
| 83 | + "Whoa, chill out!" |
| 84 | + (Bob.hey "I HATE YOU") |
| 85 | + , test "statement containing a question mark" <| |
| 86 | + \() -> |
| 87 | + Expect.equal |
| 88 | + "Whatever." |
| 89 | + (Bob.hey "Ending with ? means a question.") |
| 90 | + , test "prattling on" <| |
| 91 | + \() -> |
| 92 | + Expect.equal |
| 93 | + "Sure." |
| 94 | + (Bob.hey "Wait! Hang on. Are you going to be OK?") |
| 95 | + , test "silence" <| |
| 96 | + \() -> |
| 97 | + Expect.equal |
| 98 | + "Fine. Be that way!" |
| 99 | + (Bob.hey "") |
| 100 | + , test "prolonged silence" <| |
| 101 | + \() -> |
| 102 | + Expect.equal |
| 103 | + "Fine. Be that way!" |
| 104 | + (Bob.hey " ") |
| 105 | + , test "alternate silences" <| |
| 106 | + \() -> |
| 107 | + Expect.equal |
| 108 | + "Fine. Be that way!" |
| 109 | + (Bob.hey "\t \n \t ") |
| 110 | + , test "on multiple line questions" <| |
| 111 | + \() -> |
| 112 | + Expect.equal |
| 113 | + "Whatever." |
| 114 | + (Bob.hey "\nDoes this cryogenic chamber make me look fat?\nno") |
| 115 | + ] |
| 116 | + |
| 117 | + |
| 118 | +character : Int -> Int -> Random.Generator Char |
| 119 | +character start end = |
| 120 | + Random.map Char.fromCode (Random.int start end) |
| 121 | + |
| 122 | + |
| 123 | +anyCharacter : Random.Generator Char |
| 124 | +anyCharacter = |
| 125 | + character 32 126 |
| 126 | + |
| 127 | + |
| 128 | +uppercaseCharacter : Random.Generator Char |
| 129 | +uppercaseCharacter = |
| 130 | + character 65 90 |
| 131 | + |
| 132 | + |
| 133 | +listOfCharacters : Int -> Random.Generator Char -> Random.Generator (List Char) |
| 134 | +listOfCharacters length characterList = |
| 135 | + Random.list length characterList |
| 136 | + |
| 137 | + |
| 138 | +gibberish : Int -> Random.Generator Char -> String |
| 139 | +gibberish length characterList = |
| 140 | + Tuple.first (Random.step (Random.map String.fromList (listOfCharacters length characterList)) (Random.initialSeed 424242)) |
| 141 | + |
| 142 | + |
| 143 | +uppercaseGibberish : Int -> String |
| 144 | +uppercaseGibberish length = |
| 145 | + gibberish length uppercaseCharacter |
| 146 | + |
| 147 | + |
| 148 | +gibberishQuestion : Int -> String |
| 149 | +gibberishQuestion length = |
| 150 | + (gibberish length anyCharacter) ++ "?" |
| 151 | + |
| 152 | + |
| 153 | +main : TestProgram |
| 154 | +main = |
| 155 | + run emit tests |
| 156 | + |
| 157 | + |
| 158 | +port emit : ( String, Value ) -> Cmd msg |
0 commit comments