Skip to content

Instantly share code, notes, and snippets.

@gegagome
Created February 25, 2015 21:35
Show Gist options
  • Save gegagome/faac1e4b8323d84d2ef2 to your computer and use it in GitHub Desktop.
Save gegagome/faac1e4b8323d84d2ef2 to your computer and use it in GitHub Desktop.
class Bob
{
func hey(prompt: String) -> String {
let shouting = "Woah, chill out!"
let question = "Sure"
let touchy = "Fine. Be that way!"
let apathy = "Whatever."
if (isLowerCase(prompt: prompt)) {
return shouting
}
else if (prompt.isEmpty) {
return touchy
}
else if (prompt.hasSuffix("?")){
return question
}
else {
return apathy
}
}
func isLowerCase(#prompt: String) -> Bool {
var isTrue: Bool = false
for letter in prompt {
let chr = String(letter)
if chr.lowercaseString != chr {
isTrue = true
}
}
return isTrue
}
}
// actual test file
import XCTest
class BobTests: XCTestCase {
func testStatingSomething() {
let input = "Tom-ay-to, tom-aaaah-to."
let expected = "Whatever."
let result = Bob.hey(input)
XCTAssertEqual(expected, result)
}
func testShouting() {
let input = "WATCH OUT!"
let expected = "Woah, chill out!"
let result = Bob.hey(input)
XCTAssertEqual(expected, result)
}
func testAskingAQustion() {
let input = "Does this cryogenic chamber make me look fat?"
let expected = "Sure."
let result = Bob.hey(input)
XCTAssertEqual(expected, result)
}
func testTalkingForcefully() {
let input = "Let's go make out behind the gym!"
let expected = "Whatever."
let result = Bob.hey(input)
XCTAssertEqual(expected, result)
}
func testUsingAcronyms() {
let input = "It's OK if you don't want to go to the DMV."
let expected = "Whatever."
let result = Bob.hey(input)
XCTAssertEqual(expected, result)
}
func testForcefulQuestions() {
let input = "WHAT THE HELL WERE YOU THINKING?"
let expected = "Woah, chill out!"
let result = Bob.hey(input)
XCTAssertEqual(expected, result)
}
func testShoutingNumbers() {
let input = "1, 2, 3 GO!"
let expected = "Woah, chill out!"
let result = Bob.hey(input)
XCTAssertEqual(expected, result)
}
func testOnlyNumbers() {
let input = "1, 2, 3."
let expected = "Whatever."
let result = Bob.hey(input)
XCTAssertEqual(expected, result)
}
func testQuestionWithOnlyNumbers() {
let input = "4?"
let expected = "Sure."
let result = Bob.hey(input)
XCTAssertEqual(expected, result)
}
func testShoutingWithSpecialCharacters() {
let input = "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!"
let expected = "Woah, chill out!"
let result = Bob.hey(input)
XCTAssertEqual(expected, result)
}
func testShoutingWithUmlautsCharacters() {
let input = "ÄMLÄTS!"
let expected = "Woah, chill out!"
let result = Bob.hey(input)
XCTAssertEqual(expected, result)
}
func testCalmlySpeakingAboutUmlauts() {
let input = "ÄMLäTS!"
let expected = "Whatever."
let result = Bob.hey(input)
XCTAssertEqual(expected, result)
}
func testShoutingWithNoExclamationmark() {
let input = "I HATE YOU"
let expected = "Woah, chill out!"
let result = Bob.hey(input)
XCTAssertEqual(expected, result)
}
func testStatementContainingQuestionsMark() {
let input = "Ending with a ? means a question."
let expected = "Whatever."
let result = Bob.hey(input)
XCTAssertEqual(expected, result)
}
func testPrattlingOn() {
let input = "Wait! Hang on. Are you going to be OK?"
let expected = "Sure."
let result = Bob.hey(input)
XCTAssertEqual(expected, result)
}
func testSilence() {
let input = ""
let expected = "Fine, be that way."
let result = Bob.hey(input)
XCTAssertEqual(expected, result)
}
func testProlongedSilence() {
let input = " "
let expected = "Fine, be that way."
let result = Bob.hey(input)
XCTAssertEqual(expected, result)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment