Skip to content

Commit

Permalink
Bob: sync expected test results and input data with problem-specifica…
Browse files Browse the repository at this point in the history
…tions (#1784)

* Bob:  sync expected test results and input data  with problem-specifications.
  • Loading branch information
BethanyG authored and cmccandless committed May 23, 2019
1 parent ec506df commit bb681f9
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 40 deletions.
2 changes: 1 addition & 1 deletion exercises/bob/bob.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
def hey(phrase):
def response(hey_bob):
pass
55 changes: 28 additions & 27 deletions exercises/bob/bob_test.py
Original file line number Diff line number Diff line change
@@ -1,100 +1,101 @@
import unittest

from bob import hey
from bob import response


# Tests adapted from `problem-specifications//canonical-data.json` @ v1.4.0

class BobTest(unittest.TestCase):
def test_stating_something(self):
self.assertEqual(hey("Tom-ay-to, tom-aaaah-to."), "Whatever.")
self.assertEqual(response("Tom-ay-to, tom-aaaah-to."), "Whatever.")

def test_shouting(self):
self.assertEqual(hey("WATCH OUT!"), "Whoa, chill out!")
self.assertEqual(response("WATCH OUT!"), "Whoa, chill out!")

def test_shouting_gibberish(self):
self.assertEqual(hey("FCECDFCAAB"), "Whoa, chill out!")
self.assertEqual(response("FCECDFCAAB"), "Whoa, chill out!")

def test_asking_a_question(self):
self.assertEqual(
hey("Does this cryogenic chamber make me look fat?"), "Sure.")
response("Does this cryogenic chamber make me look fat?"), "Sure.")

def test_asking_a_numeric_question(self):
self.assertEqual(hey("You are, what, like 15?"), "Sure.")
self.assertEqual(response("You are, what, like 15?"), "Sure.")

def test_asking_gibberish(self):
self.assertEqual(hey("fffbbcbeab?"), "Sure.")
self.assertEqual(response("fffbbcbeab?"), "Sure.")

def test_talking_forcefully(self):
self.assertEqual(
hey("Let's go make out behind the gym!"), "Whatever.")
response("Let's go make out behind the gym!"), "Whatever.")

def test_using_acronyms_in_regular_speech(self):
self.assertEqual(
hey("It's OK if you don't want to go to the DMV."),
response("It's OK if you don't want to go to the DMV."),
"Whatever.")

def test_forceful_question(self):
self.assertEqual(
hey("WHAT THE HELL WERE YOU THINKING?"),
response("WHAT THE HELL WERE YOU THINKING?"),
"Calm down, I know what I'm doing!"
)

def test_shouting_numbers(self):
self.assertEqual(hey("1, 2, 3 GO!"), "Whoa, chill out!")
self.assertEqual(response("1, 2, 3 GO!"), "Whoa, chill out!")

def test_no_letters(self):
self.assertEqual(hey("1, 2, 3"), "Whatever.")
self.assertEqual(response("1, 2, 3"), "Whatever.")

def test_question_with_no_letters(self):
self.assertEqual(hey("4?"), "Sure.")
self.assertEqual(response("4?"), "Sure.")

def test_shouting_with_special_characters(self):
self.assertEqual(
hey("ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!"),
response("ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!"),
"Whoa, chill out!")

def test_shouting_with_no_exclamation_mark(self):
self.assertEqual(hey("I HATE THE DMV"), "Whoa, chill out!")
self.assertEqual(response("I HATE THE DMV"), "Whoa, chill out!")

def test_statement_containing_question_mark(self):
self.assertEqual(
hey("Ending with ? means a question."), "Whatever.")
response("Ending with ? means a question."), "Whatever.")

def test_non_letters_with_question(self):
self.assertEqual(hey(":) ?"), "Sure.")
self.assertEqual(response(":) ?"), "Sure.")

def test_prattling_on(self):
self.assertEqual(
hey("Wait! Hang on. Are you going to be OK?"), "Sure.")
response("Wait! Hang on. Are you going to be OK?"), "Sure.")

def test_silence(self):
self.assertEqual(hey(""), "Fine. Be that way!")
self.assertEqual(response(""), "Fine. Be that way!")

def test_prolonged_silence(self):
self.assertEqual(hey(" "), "Fine. Be that way!")
self.assertEqual(response(" "), "Fine. Be that way!")

def test_alternate_silence(self):
self.assertEqual(hey("\t\t\t\t\t\t\t\t\t\t"), "Fine. Be that way!")
self.assertEqual(response("\t\t\t\t\t\t\t\t\t\t"),
"Fine. Be that way!")

def test_multiple_line_question(self):
self.assertEqual(
hey("\nDoes this cryogenic chamber make me look fat?\nNo."),
"Whatever.")
response("\nDoes this cryogenic chamber make me look fat?\n"
"No."), "Whatever.")

def test_starting_with_whitespace(self):
self.assertEqual(hey(" hmmmmmmm..."), "Whatever.")
self.assertEqual(response(" hmmmmmmm..."), "Whatever.")

def test_ending_with_whitespace(self):
self.assertEqual(
hey("Okay if like my spacebar quite a bit? "), "Sure.")
response("Okay if like my spacebar quite a bit? "), "Sure.")

def test_other_whitespace(self):
self.assertEqual(hey("\n\r \t"), "Fine. Be that way!")
self.assertEqual(response("\n\r \t"), "Fine. Be that way!")

def test_non_question_ending_with_whitespace(self):
self.assertEqual(
hey("This is a statement ending with whitespace "),
response("This is a statement ending with whitespace "),
"Whatever.")


Expand Down
24 changes: 12 additions & 12 deletions exercises/bob/example.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
def hey(stimulus):
stimulus = stimulus.strip()
def response(hey_bob):
hey_bob = hey_bob.strip()

if _is_silence(stimulus):
if _is_silence(hey_bob):
return 'Fine. Be that way!'
if _is_shouting(stimulus):
if _is_question(stimulus):
if _is_shouting(hey_bob):
if _is_question(hey_bob):
return "Calm down, I know what I'm doing!"
else:
return 'Whoa, chill out!'
elif _is_question(stimulus):
elif _is_question(hey_bob):
return 'Sure.'
else:
return 'Whatever.'


def _is_silence(stimulus):
return stimulus == ''
def _is_silence(hey_bob):
return hey_bob == ''


def _is_shouting(stimulus):
return stimulus.isupper()
def _is_shouting(hey_bob):
return hey_bob.isupper()


def _is_question(stimulus):
return stimulus.endswith('?')
def _is_question(hey_bob):
return hey_bob.endswith('?')

0 comments on commit bb681f9

Please sign in to comment.