Initial Commit
This commit is contained in:
44
go/bob/README.md
Normal file
44
go/bob/README.md
Normal file
@@ -0,0 +1,44 @@
|
||||
# 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!
|
||||
|
||||
|
||||
To run the tests simply run the command `go test` in the exercise directory.
|
||||
|
||||
If the test suite contains benchmarks, you can run these with the `-bench`
|
||||
flag:
|
||||
|
||||
go test -bench .
|
||||
|
||||
For more detailed info about the Go track see the [help
|
||||
page](http://exercism.io/languages/go).
|
||||
|
||||
## Source
|
||||
|
||||
Inspired by the 'Deaf Grandma' exercise in Chris Pine's Learn to Program tutorial. [view source](http://pine.fm/LearnToProgram/?Chapter=06)
|
19
go/bob/bob.go
Normal file
19
go/bob/bob.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package bob
|
||||
|
||||
import "strings"
|
||||
|
||||
// TestVersion is an exercism thing
|
||||
const TestVersion = 1
|
||||
|
||||
// Hey provokes a response from Bob
|
||||
func Hey(inp string) string {
|
||||
inp = strings.TrimSpace(inp)
|
||||
if inp == "" {
|
||||
return "Fine. Be that way!"
|
||||
} else if inp == strings.ToUpper(inp) && inp != strings.ToLower(inp) {
|
||||
return "Whoa, chill out!"
|
||||
} else if strings.HasSuffix(inp, "?") {
|
||||
return "Sure."
|
||||
}
|
||||
return "Whatever."
|
||||
}
|
33
go/bob/bob_test.go
Normal file
33
go/bob/bob_test.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package bob
|
||||
|
||||
import "testing"
|
||||
|
||||
const testVersion = 1
|
||||
|
||||
// Retired testVersions
|
||||
// (none) 4a9e144a3c5dc0d9773f4cf641ffe3efe48641d8
|
||||
|
||||
func TestHeyBob(t *testing.T) {
|
||||
if TestVersion != testVersion {
|
||||
t.Fatalf("Found TestVersion = %v, want %v", TestVersion, testVersion)
|
||||
}
|
||||
for _, tt := range testCases {
|
||||
actual := Hey(tt.input)
|
||||
if actual != tt.expected {
|
||||
msg := `
|
||||
ALICE (%s): %q
|
||||
BOB: %s
|
||||
|
||||
Expected Bob to respond: %s`
|
||||
t.Fatalf(msg, tt.description, tt.input, actual, tt.expected)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkBob(b *testing.B) {
|
||||
for _, tt := range testCases {
|
||||
for i := 0; i < b.N; i++ {
|
||||
Hey(tt.input)
|
||||
}
|
||||
}
|
||||
}
|
141
go/bob/cases_test.go
Normal file
141
go/bob/cases_test.go
Normal file
@@ -0,0 +1,141 @@
|
||||
package bob
|
||||
|
||||
// Source: exercism/x-common
|
||||
// Commit: 945d08e Merge pull request #50 from soniakeys/master
|
||||
|
||||
var testCases = []struct {
|
||||
description string
|
||||
input string
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
"stating something",
|
||||
"Tom-ay-to, tom-aaaah-to.",
|
||||
"Whatever.",
|
||||
},
|
||||
{
|
||||
"shouting",
|
||||
"WATCH OUT!",
|
||||
"Whoa, chill out!",
|
||||
},
|
||||
{
|
||||
"shouting gibberish",
|
||||
"FCECDFCAAB",
|
||||
"Whoa, chill out!",
|
||||
},
|
||||
{
|
||||
"asking a question",
|
||||
"Does this cryogenic chamber make me look fat?",
|
||||
"Sure.",
|
||||
},
|
||||
{
|
||||
"asking a numeric question",
|
||||
"You are, what, like 15?",
|
||||
"Sure.",
|
||||
},
|
||||
{
|
||||
"asking gibberish",
|
||||
"fffbbcbeab?",
|
||||
"Sure.",
|
||||
},
|
||||
{
|
||||
"talking forcefully",
|
||||
"Let's go make out behind the gym!",
|
||||
"Whatever.",
|
||||
},
|
||||
{
|
||||
"using acronyms in regular speech",
|
||||
"It's OK if you don't want to go to the DMV.",
|
||||
"Whatever.",
|
||||
},
|
||||
{
|
||||
"forceful question",
|
||||
"WHAT THE HELL WERE YOU THINKING?",
|
||||
"Whoa, chill out!",
|
||||
},
|
||||
{
|
||||
"shouting numbers",
|
||||
"1, 2, 3 GO!",
|
||||
"Whoa, chill out!",
|
||||
},
|
||||
{
|
||||
"only numbers",
|
||||
"1, 2, 3",
|
||||
"Whatever.",
|
||||
},
|
||||
{
|
||||
"question with only numbers",
|
||||
"4?",
|
||||
"Sure.",
|
||||
},
|
||||
{
|
||||
"shouting with special characters",
|
||||
"ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!",
|
||||
"Whoa, chill out!",
|
||||
},
|
||||
{
|
||||
"shouting with umlauts",
|
||||
"ÜMLÄÜTS!",
|
||||
"Whoa, chill out!",
|
||||
},
|
||||
{
|
||||
"calmly speaking with umlauts",
|
||||
"ÜMLäÜTS!",
|
||||
"Whatever.",
|
||||
},
|
||||
{
|
||||
"shouting with no exclamation mark",
|
||||
"I HATE YOU",
|
||||
"Whoa, chill out!",
|
||||
},
|
||||
{
|
||||
"statement containing question mark",
|
||||
"Ending with ? means a question.",
|
||||
"Whatever.",
|
||||
},
|
||||
{
|
||||
"non-letters with question",
|
||||
":) ?",
|
||||
"Sure.",
|
||||
},
|
||||
{
|
||||
"prattling on",
|
||||
"Wait! Hang on. Are you going to be OK?",
|
||||
"Sure.",
|
||||
},
|
||||
{
|
||||
"silence",
|
||||
"",
|
||||
"Fine. Be that way!",
|
||||
},
|
||||
{
|
||||
"prolonged silence",
|
||||
" ",
|
||||
"Fine. Be that way!",
|
||||
},
|
||||
{
|
||||
"alternate silence",
|
||||
"\t\t\t\t\t\t\t\t\t\t",
|
||||
"Fine. Be that way!",
|
||||
},
|
||||
{
|
||||
"multiple line question",
|
||||
"\nDoes this cryogenic chamber make me look fat?\nno",
|
||||
"Whatever.",
|
||||
},
|
||||
{
|
||||
"starting with whitespace",
|
||||
" hmmmmmmm...",
|
||||
"Whatever.",
|
||||
},
|
||||
{
|
||||
"ending with whitespace",
|
||||
"Okay if like my spacebar quite a bit? ",
|
||||
"Sure.",
|
||||
},
|
||||
{
|
||||
"other whitespace",
|
||||
"\n\r \t\v\u00a0\u2002",
|
||||
"Fine. Be that way!",
|
||||
},
|
||||
}
|
Reference in New Issue
Block a user