Skip to content

Instantly share code, notes, and snippets.

@rreas

rreas/Readme.md Secret

Last active August 29, 2015 13:57
Show Gist options
  • Save rreas/cb9179806cd423fe7f60 to your computer and use it in GitHub Desktop.
Save rreas/cb9179806cd423fe7f60 to your computer and use it in GitHub Desktop.
Programming Question #1 - Warmup

This is a simple evaluation problem. You'll code Bob, a simple message responder as follows:

  • Bob answers 'Sure.' if you ask him a question.
  • He answers 'Woah, chill out!' if you yell at him (ALL CAPS).
  • He says 'Fine. Be that way!' if you address him without actually saying anything.
  • He answers 'Whatever.' to anything else.

For help in completing the initial problem, specs are attached in each of the following languages: Ruby, Python, JavaScript and Clojure. Please select one language, complete the code in your language of choice so that all specs pass and upload the result to a private Gist here on GitHub. Please send us the URL when you're finished. Thanks!

Note, if you've seen this problem before (we didn't create it!) please submit your solution anyways.

(ns bob.test (:require [clojure.test :refer :all]))
(load-file "bob.clj")
(deftest responds-to-something
(is (= "Whatever." (bob/response-for "Tom-ay-to, tom-aaaah-to."))))
(deftest responds-to-shouts
(is (= "Woah, chill out!" (bob/response-for "WATCH OUT!"))))
(deftest responds-to-questions
(is (= "Sure." (bob/response-for "Does this cryogenic chamber make me look fat?"))))
(deftest responds-to-forceful-talking
(is (= "Whatever." (bob/response-for "Let's go make out behind the gym!"))))
(deftest responds-to-acronyms
(is (= "Whatever." (bob/response-for "It's OK if you don't want to go to the DMV."))))
(deftest responds-to-forceful-questions
(is (= "Woah, chill out!" (bob/response-for "WHAT THE HELL WERE YOU THINKING?"))))
(deftest responds-to-shouting-with-special-characters
(is (= "Woah, chill out!" (bob/response-for "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!"))))
(deftest responds-to-shouting-numbers
(is (= "Woah, chill out!" (bob/response-for "1, 2, 3 GO!"))))
(deftest responds-to-shouting-with-no-exclamation-mark
(is (= "Woah, chill out!" (bob/response-for "I HATE YOU"))))
(deftest responds-to-statement-containing-question-mark
(is (= "Whatever." (bob/response-for "Ending with ? means a question."))))
(deftest responds-to-silence
(is (= "Fine. Be that way!" (bob/response-for ""))))
(deftest responds-to-prolonged-silence
(is (= "Fine. Be that way!" (bob/response-for " "))))
(deftest responds-to-only-numbers
(is (= "Whatever." (bob/response-for "1, 2, 3"))))
(deftest responds-to-number-question
(is (= "Sure." (bob/response-for "4?"))))
(run-tests)
try:
import bob
except ImportError:
raise SystemExit('Could not find bob.py. Does it exist?')
import unittest
class BobTests(unittest.TestCase):
def setUp(self):
self.bob = bob.Bob()
def test_stating_something(self):
self.assertEqual(
'Whatever.',
self.bob.hey('Tom-ay-to, tom-aaaah-to.')
)
def test_shouting(self):
self.assertEqual(
'Woah, chill out!',
self.bob.hey('WATCH OUT!')
)
def test_asking_a_question(self):
self.assertEqual(
'Sure.',
self.bob.hey('Does this cryogenic chamber make me look fat?')
)
def test_asking_a_numeric_question(self):
self.assertEqual(
'Sure.',
self.bob.hey('You are, what, like 15?')
)
def test_talking_forcefully(self):
self.assertEqual(
'Whatever.',
self.bob.hey("Let's go make out behind the gym!")
)
def test_using_acronyms_in_regular_speech(self):
self.assertEqual(
'Whatever.', self.bob.hey("It's OK if you don't want to go to the DMV.")
)
def test_forceful_questions(self):
self.assertEqual(
'Woah, chill out!', self.bob.hey('WHAT THE HELL WERE YOU THINKING?')
)
def test_shouting_numbers(self):
self.assertEqual(
'Woah, chill out!', self.bob.hey('1, 2, 3 GO!')
)
def test_only_numbers(self):
self.assertEqual(
'Whatever.', self.bob.hey('1, 2, 3')
)
def test_question_with_only_numbers(self):
self.assertEqual(
'Sure.', self.bob.hey('4?')
)
def test_shouting_with_special_characters(self):
self.assertEqual(
'Woah, chill out!', self.bob.hey('ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!')
)
def test_shouting_with_umlauts(self):
self.assertEqual(
'Woah, chill out!', self.bob.hey("\xdcML\xc4\xdcTS!")
)
def test_calmly_speaking_with_umlauts(self):
self.assertEqual(
'Whatever.', self.bob.hey("\xdcML\xe4\xdcTS!")
)
def test_shouting_with_no_exclamation_mark(self):
self.assertEqual(
'Woah, chill out!', self.bob.hey('I HATE YOU')
)
def test_statement_containing_question_mark(self):
self.assertEqual(
'Whatever.', self.bob.hey('Ending with ? means a question.')
)
def test_prattling_on(self):
self.assertEqual(
'Sure.', self.bob.hey("Wait! Hang on. Are you going to be OK?")
)
def test_silence(self):
self.assertEqual(
'Fine. Be that way!', self.bob.hey('')
)
def test_more_silence(self):
self.assertEqual(
'Fine. Be that way!', self.bob.hey(None)
)
def test_prolonged_silence(self):
self.assertEqual(
'Fine. Be that way!', self.bob.hey(' ')
)
if __name__ == '__main__':
unittest.main()
require 'minitest/autorun'
require_relative 'bob'
class TeenagerTest < MiniTest::Unit::TestCase
attr_reader :teenager
def setup
@teenager = ::Bob.new
end
def test_stating_something
assert_equal 'Whatever.', teenager.hey('Tom-ay-to, tom-aaaah-to.')
end
def test_shouting
assert_equal 'Woah, chill out!', teenager.hey('WATCH OUT!')
end
def test_asking_a_question
assert_equal 'Sure.', teenager.hey('Does this cryogenic chamber make me look fat?')
end
def test_asking_a_numeric_question
assert_equal 'Sure.', teenager.hey('You are, what, like 15?')
end
def test_talking_forcefully
assert_equal 'Whatever.', teenager.hey("Let's go make out behind the gym!")
end
def test_using_acronyms_in_regular_speech
assert_equal 'Whatever.', teenager.hey("It's OK if you don't want to go to the DMV.")
end
def test_forceful_questions
assert_equal 'Woah, chill out!', teenager.hey('WHAT THE HELL WERE YOU THINKING?')
end
def test_shouting_numbers
assert_equal 'Woah, chill out!', teenager.hey('1, 2, 3 GO!')
end
def test_only_numbers
assert_equal 'Whatever.', teenager.hey('1, 2, 3')
end
def test_question_with_only_numbers
assert_equal 'Sure.', teenager.hey('4?')
end
def test_shouting_with_special_characters
assert_equal 'Woah, chill out!', teenager.hey('ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!')
end
def test_shouting_with_no_exclamation_mark
assert_equal 'Woah, chill out!', teenager.hey('I HATE YOU')
end
def test_statement_containing_question_mark
assert_equal 'Whatever.', teenager.hey('Ending with ? means a question.')
end
def test_prattling_on
assert_equal 'Sure.', teenager.hey("Wait! Hang on. Are you going to be OK?")
end
def test_silence
assert_equal 'Fine. Be that way!', teenager.hey('')
end
def test_prolonged_silence
assert_equal 'Fine. Be that way!', teenager.hey(' ')
end
def test_on_multiple_line_questions
assert_equal 'Whatever.', teenager.hey(%{
Does this cryogenic chamber make me look fat?
no})
end
end
var Bob = require('./bob');
describe("Bob", function() {
var bob = new Bob();
it("stating something", function() {
var result = bob.hey('Tom-ay-to, tom-aaaah-to.');
expect(result).toEqual('Whatever.');
});
xit("shouting", function() {
var result = bob.hey('WATCH OUT!');
expect(result).toEqual('Woah, chill out!');
});
xit("asking a question", function() {
var result = bob.hey('Does this cryogenic chamber make me look fat?');
expect(result).toEqual('Sure.');
});
xit("talking forcefully", function() {
var result = bob.hey("Let's go make out behind the gym!");
expect(result).toEqual('Whatever.');
});
xit("using acronyms in regular speech", function() {
var result = bob.hey("It's OK if you don't want to go to the DMV.");
expect(result).toEqual('Whatever.');
});
xit("forceful questions", function() {
var result = bob.hey('WHAT THE HELL WERE YOU THINKING?');
expect(result).toEqual('Woah, chill out!');
});
xit("shouting numbers", function() {
var result = bob.hey('1, 2, 3 GO!');
expect(result).toEqual('Woah, chill out!');
});
xit("only numbers", function() {
var result = bob.hey('1, 2, 3');
expect(result).toEqual('Whatever.');
});
xit("question with only numbers", function() {
var result = bob.hey('4?');
expect(result).toEqual('Sure.');
});
xit("shouting with special characters", function() {
var result = bob.hey('ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!');
expect(result).toEqual('Woah, chill out!');
});
xit("shouting with umlauts", function() {
var result = bob.hey("\xdcML\xc4\xdcTS!");
expect(result).toEqual('Woah, chill out!');
});
xit("calmly speaking about umlauts", function() {
var result = bob.hey("\xdcML\xe4\xdcTS!");
expect(result).toEqual('Whatever.');
});
xit("shouting with no exclamation mark", function () {
var result = bob.hey('I HATE YOU');
expect(result).toEqual('Woah, chill out!');
});
xit("statement containing question mark", function() {
var result = bob.hey('Ending with a ? means a question.');
expect(result).toEqual('Whatever.');
});
xit("prattling on", function () {
var result = bob.hey('Wait! Hang on. Are you going to be OK?');
expect(result).toEqual('Sure.');
});
xit("silence", function () {
var result = bob.hey('');
expect(result).toEqual('Fine. Be that way!');
});
xit("prolonged silence", function () {
var result = bob.hey(' ');
expect(result).toEqual('Fine. Be that way!');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment