Skip to content

Commit

Permalink
Merge pull request #271 from verdammelt/update-bob-exercise
Browse files Browse the repository at this point in the history
Update Bob exercise from latest problem specifications.
  • Loading branch information
verdammelt authored Jan 18, 2020
2 parents d41c12c + 4804abc commit b9b24c5
Show file tree
Hide file tree
Showing 4 changed files with 164 additions and 62 deletions.
4 changes: 2 additions & 2 deletions exercises/bob/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

Bob is a lackadaisical teenager. In conversation, his responses are very limited.

Bob answers 'Sure.' if you ask him a question.
Bob answers 'Sure.' if you ask him a question, such as "How are you?".

He answers 'Whoa, chill out!' if you yell at him.
He answers 'Whoa, chill out!' if you YELL AT HIM (in all capitals).

He answers 'Calm down, I know what I'm doing!' if you yell a question at him.

Expand Down
213 changes: 157 additions & 56 deletions exercises/bob/bob-test.lisp
Original file line number Diff line number Diff line change
@@ -1,89 +1,190 @@
;;;
;;; bob v1.6.0
;;;
(ql:quickload "lisp-unit")
#-xlisp-test (load "bob")
;; #-xlisp-test (load "bob")
#-xlisp-test (load "example")

(defpackage #:bob-test
(:use #:common-lisp #:lisp-unit))

(in-package #:bob-test)

(define-test responds-to-something
(assert-equal "Whatever." (bob:response-for "Tom-ay-to, tom-aaaah-to.")))
(define-test
stating-something
(assert-equal
"Whatever."
(bob:response "Tom-ay-to, tom-aaaah-to.")))


(define-test
shouting
(assert-equal
"Whoa, chill out!"
(bob:response "WATCH OUT!")))


(define-test
shouting-gibberish
(assert-equal
"Whoa, chill out!"
(bob:response "FCECDFCAAB")))


(define-test
asking-a-question
(assert-equal
"Sure."
(bob:response "Does this cryogenic chamber make me look fat?")))


(define-test
asking-a-numeric-question
(assert-equal
"Sure."
(bob:response "You are, what, like 15?")))


(define-test
asking-gibberish
(assert-equal
"Sure."
(bob:response "fffbbcbeab?")))


(define-test
talking-forcefully
(assert-equal
"Whatever."
(bob:response "Hi there!")))


(define-test
using-acronyms-in-regular-speech
(assert-equal
"Whatever."
(bob:response "It's OK if you don't want to go work for NASA.")))


(define-test
forceful-question
(assert-equal
"Calm down, I know what I'm doing!"
(bob:response "WHAT'S GOING ON?")))


(define-test
shouting-numbers
(assert-equal
"Whoa, chill out!"
(bob:response "1, 2, 3 GO!")))


(define-test
no-letters
(assert-equal
"Whatever."
(bob:response "1, 2, 3")))


(define-test
question-with-no-letters
(assert-equal
"Sure."
(bob:response "4?")))


(define-test
shouting-with-special-characters
(assert-equal
"Whoa, chill out!"
(bob:response "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!")))

(define-test responds-to-shouts
(assert-equal "Whoa, chill out!" (bob:response-for "WATCH OUT!")))

(define-test shouting-gibberish
(assert-equal "Whoa, chill out!" (bob:response-for "FCECDFCAAB")))
(define-test
shouting-with-no-exclamation-mark
(assert-equal
"Whoa, chill out!"
(bob:response "I HATE THE DENTIST")))

(define-test responds-to-questions
(assert-equal "Sure." (bob:response-for "Does this cryogenic chamber make me look fat?")))

(define-test asking-a-numeric-question
(assert-equal "Sure." (bob:response-for "You are, what, like 15?")))
(define-test
statement-containing-question-mark
(assert-equal
"Whatever."
(bob:response "Ending with ? means a question.")))

(define-test asking-gibberish
(assert-equal "Sure." (bob:response-for "fffbbcbeab?")))

(define-test responds-to-forceful-talking
(assert-equal "Whatever." (bob:response-for "Let's go make out behind the gym!")))
(define-test
non-letters-with-question
(assert-equal
"Sure."
(bob:response ":) ?")))

(define-test responds-to-acronyms
(assert-equal "Whatever." (bob:response-for "It's OK if you don't want to go to the DMV.")))

(define-test responds-to-forceful-questions
(assert-equal "Calm down, I know what I'm doing!"
(bob:response-for "WHAT THE HELL WERE YOU THINKING?")))
(define-test
prattling-on
(assert-equal
"Sure."
(bob:response "Wait! Hang on. Are you going to be OK?")))

(define-test responds-to-shouting-numbers
(assert-equal "Whoa, chill out!" (bob:response-for "1, 2, 3 GO!")))

(define-test responds-to-only-numbers
(assert-equal "Whatever." (bob:response-for "1, 2, 3")))
(define-test
silence
(assert-equal
"Fine. Be that way!"
(bob:response "")))

(define-test responds-to-number-question
(assert-equal "Sure." (bob:response-for "4?")))

(define-test responds-to-shouting-with-special-characters
(assert-equal "Whoa, chill out!" (bob:response-for "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!")))
(define-test
prolonged-silence
(assert-equal
"Fine. Be that way!"
(bob:response " ")))

(define-test responds-to-shouting-with-no-exclamation-mark
(assert-equal "Whoa, chill out!" (bob:response-for "I HATE YOU")))

(define-test responds-to-statement-containing-question-mark
(assert-equal "Whatever." (bob:response-for "Ending with ? means a question.")))
(define-test
alternate-silence
(assert-equal
"Fine. Be that way!"
(bob:response " ")))

(define-test non-letters-with-question
(assert-equal "Sure." (bob:response-for ":) ?")))

(define-test prattling-ton
(assert-equal "Sure." (bob:response-for "Wait! Hang on. Are you going to be OK?")))
(define-test
multiple-line-question
(assert-equal
"Whatever."
(bob:response (format nil "~%
Does this cryogenic chamber make me look fat?~%
No."))))

(define-test responds-to-silence
(assert-equal "Fine. Be that way!" (bob:response-for "")))

(define-test responds-to-prolonged-silence
(assert-equal "Fine. Be that way!" (bob:response-for " ")))
(define-test
starting-with-whitespace
(assert-equal
"Whatever."
(bob:response " hmmmmmmm...")))

(define-test responds-to-alternate-silence
(assert-equal "Fine. Be that way!"
(bob:response-for (coerce (list #\Tab #\Tab #\Tab #\Tab) 'string))))

(define-test respond-to-multiline-question
(assert-equal "Whatever."
(bob:response-for (format nil "~%Does this cryogenic chamber make me look fat?~%no"))))
(define-test
ending-with-whitespace
(assert-equal
"Sure."
(bob:response "Okay if like my spacebar quite a bit? ")))

(define-test starting-with-whitespace
(assert-equal "Whatever." (bob:response-for " hmmmmmmm...")))

(define-test ending-with-whitespace
(assert-equal "Sure." (bob:response-for "Okay if like my spacebar quite a bit? ")))
(define-test
other-whitespace
(assert-equal
"Fine. Be that way!"
(bob:response (format nil "~%
"))))

(define-test other-whitespace
(assert-equal "Fine. Be that way!"
(bob:response-for (coerce (list #\Newline #\Tab #\Page) 'string))))

(define-test non-question-ending-with-whitespace
(assert-equal "Whatever." (bob:response-for "This is a statement ending with whitespace ")))
(define-test
non-question-ending-with-whitespace
(assert-equal
"Whatever."
(bob:response "This is a statement ending with whitespace ")))

#-xlisp-test
(let ((*print-errors* t)
Expand Down
5 changes: 3 additions & 2 deletions exercises/bob/bob.lisp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
(in-package #:cl-user)
(defpackage #:bob
(:use #:cl)
(:export #:response-for))
(:export #:response))
(in-package #:bob)

(defun response-for (input))
(defun response (hey-bob))

4 changes: 2 additions & 2 deletions exercises/bob/example.lisp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(defpackage #:bob
(:use #:common-lisp)
(:export #:response-for))
(:export #:response))

(in-package #:bob)

Expand All @@ -15,7 +15,7 @@
(let ((msg (string-trim '(#\Space #\Newline #\Tab #\Page) msg)))
(equal #\? (char msg (1- (length msg))))))

(defun response-for (msg)
(defun response (msg)
(cond ((silence-p msg) "Fine. Be that way!")
((and (shouting-p msg)
(questioning-p msg)) "Calm down, I know what I'm doing!")
Expand Down

0 comments on commit b9b24c5

Please sign in to comment.