Initial Commit
This commit is contained in:
10
ocaml/bob/Makefile
Normal file
10
ocaml/bob/Makefile
Normal file
@@ -0,0 +1,10 @@
|
||||
test: test.native
|
||||
@./test.native
|
||||
|
||||
test.native: *.ml *.mli
|
||||
@corebuild -quiet -pkg oUnit test.native
|
||||
|
||||
clean:
|
||||
rm -rf _build
|
||||
|
||||
.PHONY: clean
|
54
ocaml/bob/README.md
Normal file
54
ocaml/bob/README.md
Normal file
@@ -0,0 +1,54 @@
|
||||
# Bob
|
||||
|
||||
Bob is a lackadaisical teenager. In conversation, his responses are very limited.
|
||||
|
||||
Bob answers 'Sure.' if you ask him a question.
|
||||
|
||||
He answers 'Whoa, chill out!' if you yell at him.
|
||||
|
||||
He says 'Fine. Be that way!' if you address him without actually saying
|
||||
anything.
|
||||
|
||||
He answers 'Whatever.' to anything else.
|
||||
|
||||
## Instructions
|
||||
|
||||
Run the test file, and fix each of the errors in turn. When you get the
|
||||
first test to pass, go to the first pending or skipped test, and make
|
||||
that pass as well. When all of the tests are passing, feel free to
|
||||
submit.
|
||||
|
||||
Remember that passing code is just the first step. The goal is to work
|
||||
towards a solution that is as readable and expressive as you can make
|
||||
it.
|
||||
|
||||
Please make your solution as general as possible. Good code doesn't just
|
||||
pass the test suite, it works with any input that fits the
|
||||
specification.
|
||||
|
||||
Have fun!
|
||||
|
||||
|
||||
## Running Tests
|
||||
|
||||
Because OCaml is a compiled language you need to compile your submission and the test code before you can run the tests. Compile with
|
||||
|
||||
```bash
|
||||
$ corebuild -quiet test.native
|
||||
```
|
||||
|
||||
and when successful run the tests by running the `test.native` executable:
|
||||
|
||||
```bash
|
||||
./test.native
|
||||
```
|
||||
|
||||
Alternatively just type
|
||||
|
||||
```bash
|
||||
make
|
||||
```
|
||||
|
||||
## Source
|
||||
|
||||
Inspired by the 'Deaf Grandma' exercise in Chris Pine's Learn to Program tutorial. [view source](http://pine.fm/LearnToProgram/?Chapter=06)
|
18
ocaml/bob/bob.mli
Normal file
18
ocaml/bob/bob.mli
Normal file
@@ -0,0 +1,18 @@
|
||||
(*
|
||||
Answers to `hey` like a teenager.
|
||||
|
||||
## Examples
|
||||
|
||||
# response_for ""
|
||||
"Fine. Be that way!"
|
||||
|
||||
# response_for "Do you like math?"
|
||||
"Sure."
|
||||
|
||||
# response_for "HELLO!"
|
||||
"Woah, chill out!"
|
||||
|
||||
# response_for "Coding is cool."
|
||||
"Whatever."
|
||||
*)
|
||||
val response_for : string -> string
|
48
ocaml/bob/test.ml
Normal file
48
ocaml/bob/test.ml
Normal file
@@ -0,0 +1,48 @@
|
||||
open Core.Std
|
||||
open OUnit2
|
||||
open Bob
|
||||
|
||||
let ae exp got _test_ctxt = assert_equal ~printer:String.to_string exp got
|
||||
|
||||
let tests =
|
||||
["something">::
|
||||
ae "Whatever." (response_for "Tom-ay-to, tom-aaaah-to.");
|
||||
"shouts">::
|
||||
ae "Whoa, chill out!" (response_for "WATCH OUT!");
|
||||
"questions">::
|
||||
ae "Sure." (response_for "Does this cryogenic chamber make me look fat?");
|
||||
"forceful talking">::
|
||||
ae "Whatever." (response_for "Let's go make out behind the gym!");
|
||||
"acronyms">::
|
||||
ae "Whatever." (response_for "It's ok if you don't want to go to the DMV.");
|
||||
"forceful questions">::
|
||||
ae "Whoa, chill out!" (response_for "WHAT THE HELL WERE YOU THINKING?");
|
||||
"shouting with special characters">::
|
||||
ae "Whoa, chill out!"
|
||||
(response_for "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!");
|
||||
"shouting numbers">::
|
||||
ae "Whoa, chill out!" (response_for "1, 2, 3, GO!");
|
||||
"statement containing question mark">::
|
||||
ae "Whatever." (response_for "Ending with ? means a question.");
|
||||
"silence">::
|
||||
ae "Fine. Be that way!" (response_for "");
|
||||
"prolonged silence">::
|
||||
ae "Fine. Be that way!" (response_for " ");
|
||||
"non-letters with question">::
|
||||
ae "Sure." (response_for ":) ?");
|
||||
"multiple line questons">::
|
||||
ae "Whatever."
|
||||
(response_for "\nDoes this cryogenic chamber make me look fat? \nno");
|
||||
"other whitespace">::
|
||||
(* No unicode whitespace as OCaml Core doesn't seem to handle Unicode.
|
||||
* Not it seems does it see ASCII 11 (\v) as whitespace.
|
||||
*)
|
||||
ae "Fine. Be that way!" (response_for "\n\r \t");
|
||||
"only numbers">::
|
||||
ae "Whatever." (response_for "1, 2, 3");
|
||||
"question with only numbers">::
|
||||
ae "Sure." (response_for "4?");
|
||||
]
|
||||
|
||||
let () =
|
||||
run_test_tt_main ("bob tests" >::: tests)
|
1
ocaml/current
Symbolic link
1
ocaml/current
Symbolic link
@@ -0,0 +1 @@
|
||||
bob
|
Reference in New Issue
Block a user