Skip to content

Commit 72913ca

Browse files
Sync bob (#561)
* Sync bob * Canonical responses * format
1 parent 3955dad commit 72913ca

File tree

4 files changed

+135
-27
lines changed

4 files changed

+135
-27
lines changed
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
11
local bob = {}
22

33
local function shouting(say)
4-
return string.upper(say) == say
4+
return string.upper(say) == say and string.lower(say) ~= say
55
end
66

77
local function nothing(say)
8-
return say == nil or string.len(say) == 0
8+
return not say:match("%w")
99
end
1010

1111
local function question(say)
1212
return string.sub(say, -1) == '?'
1313
end
1414

1515
function bob.hey(say)
16-
if nothing(say) then
17-
return 'Fine, be that way.'
18-
end
16+
say = say:gsub("%s+", "")
1917
if shouting(say) and question(say) then
2018
return 'Calm down, I know what I\'m doing!'
2119
end
2220
if shouting(say) then
2321
return "Whoa, chill out!"
2422
end
2523
if question(say) then
26-
return "Sure"
24+
return "Sure."
25+
end
26+
if nothing(say) then
27+
return 'Fine. Be that way!'
2728
end
28-
return "Whatever"
29+
return "Whatever."
2930
end
3031

3132
return bob
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
return {
2+
module_name = 'bob',
3+
4+
generate_test = function(case)
5+
local template = [[
6+
local result = bob.hey("%s")
7+
assert.are.equals("%s", result)]]
8+
return template:format(case.input.heyBob:gsub("\n", "\\n"):gsub("\r", "\\r"):gsub("\t", "\\t"), case.expected)
9+
end
10+
}

exercises/practice/bob/.meta/tests.toml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
# This is an auto-generated file. Regular comments will be removed when this
2-
# file is regenerated. Regenerating will not touch any manually added keys,
3-
# so comments can be added in a "comment" key.
1+
# This is an auto-generated file.
2+
#
3+
# Regenerating this file via `configlet sync` will:
4+
# - Recreate every `description` key/value pair
5+
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
6+
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
7+
# - Preserve any other key/value pair
8+
#
9+
# As user-added comments (using the # character) will be removed when this file
10+
# is regenerated, comments can be added via a `comment` key.
411

512
[e162fead-606f-437a-a166-d051915cea8e]
613
description = "stating something"
@@ -64,6 +71,7 @@ description = "alternate silence"
6471

6572
[66953780-165b-4e7e-8ce3-4bcb80b6385a]
6673
description = "multiple line question"
74+
include = false
6775

6876
[5371ef75-d9ea-4103-bcfa-2da973ddec1b]
6977
description = "starting with whitespace"
@@ -76,3 +84,7 @@ description = "other whitespace"
7684

7785
[12983553-8601-46a8-92fa-fcaa3bc4a2a0]
7886
description = "non-question ending with whitespace"
87+
88+
[2c7278ac-f955-4eb4-bf8f-e33eb4116a15]
89+
description = "multiple line question"
90+
reimplements = "66953780-165b-4e7e-8ce3-4bcb80b6385a"

exercises/practice/bob/bob_spec.lua

Lines changed: 102 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,127 @@ local bob = require('bob')
22

33
describe('bob', function()
44
it('stating something', function()
5-
local result = bob.hey('Tom-ay-to, tom-aaaah-to.')
6-
assert.are.equals('Whatever', result)
5+
local result = bob.hey("Tom-ay-to, tom-aaaah-to.")
6+
assert.are.equals("Whatever.", result)
77
end)
88

99
it('shouting', function()
10-
local result = bob.hey('WATCH OUT!')
11-
assert.are.equals('Whoa, chill out!', result)
10+
local result = bob.hey("WATCH OUT!")
11+
assert.are.equals("Whoa, chill out!", result)
12+
end)
13+
14+
it('shouting gibberish', function()
15+
local result = bob.hey("FCECDFCAAB")
16+
assert.are.equals("Whoa, chill out!", result)
1217
end)
1318

1419
it('asking a question', function()
15-
local result = bob.hey('Does this cryogenic chamber make me look fat?')
16-
assert.are.equals('Sure', result)
20+
local result = bob.hey("Does this cryogenic chamber make me look fat?")
21+
assert.are.equals("Sure.", result)
22+
end)
23+
24+
it('asking a numeric question', function()
25+
local result = bob.hey("You are, what, like 15?")
26+
assert.are.equals("Sure.", result)
27+
end)
28+
29+
it('asking gibberish', function()
30+
local result = bob.hey("fffbbcbeab?")
31+
assert.are.equals("Sure.", result)
1732
end)
1833

1934
it('talking forcefully', function()
20-
local result = bob.hey("Let's go make out behind the gym!")
21-
assert.are.equals('Whatever', result)
35+
local result = bob.hey("Hi there!")
36+
assert.are.equals("Whatever.", result)
37+
end)
38+
39+
it('using acronyms in regular speech', function()
40+
local result = bob.hey("It's OK if you don't want to go work for NASA.")
41+
assert.are.equals("Whatever.", result)
42+
end)
43+
44+
it('forceful question', function()
45+
local result = bob.hey("WHAT'S GOING ON?")
46+
assert.are.equals("Calm down, I know what I'm doing!", result)
2247
end)
2348

2449
it('shouting numbers', function()
25-
local result = bob.hey('1, 2, 3 GO!')
26-
assert.are.equals('Whoa, chill out!', result)
50+
local result = bob.hey("1, 2, 3 GO!")
51+
assert.are.equals("Whoa, chill out!", result)
52+
end)
53+
54+
it('no letters', function()
55+
local result = bob.hey("1, 2, 3")
56+
assert.are.equals("Whatever.", result)
57+
end)
58+
59+
it('question with no letters', function()
60+
local result = bob.hey("4?")
61+
assert.are.equals("Sure.", result)
2762
end)
2863

2964
it('shouting with special characters', function()
30-
local result = bob.hey('ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!')
31-
assert.are.equals('Whoa, chill out!', result)
65+
local result = bob.hey("ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!")
66+
assert.are.equals("Whoa, chill out!", result)
67+
end)
68+
69+
it('shouting with no exclamation mark', function()
70+
local result = bob.hey("I HATE THE DENTIST")
71+
assert.are.equals("Whoa, chill out!", result)
72+
end)
73+
74+
it('statement containing question mark', function()
75+
local result = bob.hey("Ending with ? means a question.")
76+
assert.are.equals("Whatever.", result)
77+
end)
78+
79+
it('non-letters with question', function()
80+
local result = bob.hey(":) ?")
81+
assert.are.equals("Sure.", result)
82+
end)
83+
84+
it('prattling on', function()
85+
local result = bob.hey("Wait! Hang on. Are you going to be OK?")
86+
assert.are.equals("Sure.", result)
3287
end)
3388

3489
it('silence', function()
35-
local result = bob.hey('')
36-
assert.are.equals('Fine, be that way.', result)
90+
local result = bob.hey("")
91+
assert.are.equals("Fine. Be that way!", result)
92+
end)
93+
94+
it('prolonged silence', function()
95+
local result = bob.hey(" ")
96+
assert.are.equals("Fine. Be that way!", result)
97+
end)
98+
99+
it('alternate silence', function()
100+
local result = bob.hey("\t\t\t\t\t\t\t\t\t\t")
101+
assert.are.equals("Fine. Be that way!", result)
102+
end)
103+
104+
it('starting with whitespace', function()
105+
local result = bob.hey(" hmmmmmmm...")
106+
assert.are.equals("Whatever.", result)
107+
end)
108+
109+
it('ending with whitespace', function()
110+
local result = bob.hey("Okay if like my spacebar quite a bit? ")
111+
assert.are.equals("Sure.", result)
112+
end)
113+
114+
it('other whitespace', function()
115+
local result = bob.hey("\n\r \t")
116+
assert.are.equals("Fine. Be that way!", result)
117+
end)
118+
119+
it('non-question ending with whitespace', function()
120+
local result = bob.hey("This is a statement ending with whitespace ")
121+
assert.are.equals("Whatever.", result)
37122
end)
38123

39-
it('yelling a question', function()
40-
local result = bob.hey('WHY ARE YOU THE WAY THAT YOU ARE?')
41-
assert.are.equals('Calm down, I know what I\'m doing!', result)
124+
it('multiple line question', function()
125+
local result = bob.hey("\nDoes this cryogenic chamber make\n me look fat?")
126+
assert.are.equals("Sure.", result)
42127
end)
43128
end)

0 commit comments

Comments
 (0)