From 79403271ecca81e4b6d3e731161abf05e738385f Mon Sep 17 00:00:00 2001 From: Ryan Hartlage <2488333+ryanplusplus@users.noreply.github.com> Date: Tue, 14 Jul 2026 20:42:31 -0400 Subject: [PATCH] Sync tests for bob and tic-tac-toe --- exercises/practice/bob/.meta/tests.toml | 89 ++++++------- exercises/practice/bob/bob_spec.lua | 121 +++++++++--------- .../state-of-tic-tac-toe/.meta/example.lua | 7 +- .../state-of-tic-tac-toe/.meta/tests.toml | 6 + .../state-of-tic-tac-toe_spec.lua | 22 ++++ 5 files changed, 143 insertions(+), 102 deletions(-) diff --git a/exercises/practice/bob/.meta/tests.toml b/exercises/practice/bob/.meta/tests.toml index 5299e289..c6a46496 100644 --- a/exercises/practice/bob/.meta/tests.toml +++ b/exercises/practice/bob/.meta/tests.toml @@ -9,17 +9,20 @@ # As user-added comments (using the # character) will be removed when this file # is regenerated, comments can be added via a `comment` key. -[e162fead-606f-437a-a166-d051915cea8e] -description = "stating something" +[8a2e771d-d6f1-4e3f-b6c6-b41495556e37] +description = "asking a question" [73a966dc-8017-47d6-bb32-cf07d1a5fcd9] description = "shouting" -[d6c98afd-df35-4806-b55e-2c457c3ab748] -description = "shouting gibberish" +[a5193c61-4a92-4f68-93e2-f554eb385ec6] +description = "forceful question" -[8a2e771d-d6f1-4e3f-b6c6-b41495556e37] -description = "asking a question" +[bc39f7c6-f543-41be-9a43-fd1c2f753fc0] +description = "silence" + +[e162fead-606f-437a-a166-d051915cea8e] +description = "stating something" [81080c62-4e4d-4066-b30a-48d8d76920d9] description = "asking a numeric question" @@ -27,23 +30,34 @@ description = "asking a numeric question" [2a02716d-685b-4e2e-a804-2adaf281c01e] description = "asking gibberish" -[c02f9179-ab16-4aa7-a8dc-940145c385f7] -description = "talking forcefully" +[bb0011c5-cd52-4a5b-8bfb-a87b6283b0e2] +description = "question with no letters" -[153c0e25-9bb5-4ec5-966e-598463658bcd] -description = "using acronyms in regular speech" +[9bfc677d-ea3a-45f2-be44-35bc8fa3753e] +description = "non-letters with question" -[a5193c61-4a92-4f68-93e2-f554eb385ec6] -description = "forceful question" +[8608c508-f7de-4b17-985b-811878b3cf45] +description = "prattling on" -[a20e0c54-2224-4dde-8b10-bd2cdd4f61bc] -description = "shouting numbers" +[05b304d6-f83b-46e7-81e0-4cd3ca647900] +description = "ending with whitespace" -[f7bc4b92-bdff-421e-a238-ae97f230ccac] -description = "no letters" +[66953780-165b-4e7e-8ce3-4bcb80b6385a] +description = "multiple line question" +include = false -[bb0011c5-cd52-4a5b-8bfb-a87b6283b0e2] -description = "question with no letters" +[2c7278ac-f955-4eb4-bf8f-e33eb4116a15] +description = "multiple line question" +reimplements = "66953780-165b-4e7e-8ce3-4bcb80b6385a" + +[d6c98afd-df35-4806-b55e-2c457c3ab748] +description = "shouting gibberish" + +[3c954328-86fb-4c71-8961-e18d6a5e2517] +description = "shouting a statement containing a question mark" + +[a20e0c54-2224-4dde-8b10-bd2cdd4f61bc] +description = "shouting numbers" [496143c8-1c31-4c01-8a08-88427af85c66] description = "shouting with special characters" @@ -51,40 +65,29 @@ description = "shouting with special characters" [e6793c1c-43bd-4b8d-bc11-499aea73925f] description = "shouting with no exclamation mark" -[aa8097cc-c548-4951-8856-14a404dd236a] -description = "statement containing question mark" - -[9bfc677d-ea3a-45f2-be44-35bc8fa3753e] -description = "non-letters with question" - -[8608c508-f7de-4b17-985b-811878b3cf45] -description = "prattling on" - -[bc39f7c6-f543-41be-9a43-fd1c2f753fc0] -description = "silence" - [d6c47565-372b-4b09-b1dd-c40552b8378b] description = "prolonged silence" [4428f28d-4100-4d85-a902-e5a78cb0ecd3] description = "alternate silence" -[66953780-165b-4e7e-8ce3-4bcb80b6385a] -description = "multiple line question" -include = false +[72bd5ad3-9b2f-4931-a988-dce1f5771de2] +description = "other whitespace" -[5371ef75-d9ea-4103-bcfa-2da973ddec1b] -description = "starting with whitespace" +[c02f9179-ab16-4aa7-a8dc-940145c385f7] +description = "talking forcefully" -[05b304d6-f83b-46e7-81e0-4cd3ca647900] -description = "ending with whitespace" +[153c0e25-9bb5-4ec5-966e-598463658bcd] +description = "using acronyms in regular speech" -[72bd5ad3-9b2f-4931-a988-dce1f5771de2] -description = "other whitespace" +[f7bc4b92-bdff-421e-a238-ae97f230ccac] +description = "no letters" + +[aa8097cc-c548-4951-8856-14a404dd236a] +description = "statement containing question mark" + +[5371ef75-d9ea-4103-bcfa-2da973ddec1b] +description = "starting with whitespace" [12983553-8601-46a8-92fa-fcaa3bc4a2a0] description = "non-question ending with whitespace" - -[2c7278ac-f955-4eb4-bf8f-e33eb4116a15] -description = "multiple line question" -reimplements = "66953780-165b-4e7e-8ce3-4bcb80b6385a" diff --git a/exercises/practice/bob/bob_spec.lua b/exercises/practice/bob/bob_spec.lua index 0a93d5df..e4cdb77f 100644 --- a/exercises/practice/bob/bob_spec.lua +++ b/exercises/practice/bob/bob_spec.lua @@ -1,9 +1,9 @@ local bob = require('bob') describe('bob', function() - it('stating something', function() - local result = bob.hey("Tom-ay-to, tom-aaaah-to.") - assert.are.equals("Whatever.", result) + it('asking a question', function() + local result = bob.hey("Does this cryogenic chamber make me look fat?") + assert.are.equals("Sure.", result) end) it('shouting', function() @@ -11,14 +11,19 @@ describe('bob', function() assert.are.equals("Whoa, chill out!", result) end) - it('shouting gibberish', function() - local result = bob.hey("FCECDFCAAB") - assert.are.equals("Whoa, chill out!", result) + it('forceful question', function() + local result = bob.hey("WHAT'S GOING ON?") + assert.are.equals("Calm down, I know what I'm doing!", result) end) - it('asking a question', function() - local result = bob.hey("Does this cryogenic chamber make me look fat?") - assert.are.equals("Sure.", result) + it('silence', function() + local result = bob.hey("") + assert.are.equals("Fine. Be that way!", result) + end) + + it('stating something', function() + local result = bob.hey("Tom-ay-to, tom-aaaah-to.") + assert.are.equals("Whatever.", result) end) it('asking a numeric question', function() @@ -31,34 +36,44 @@ describe('bob', function() assert.are.equals("Sure.", result) end) - it('talking forcefully', function() - local result = bob.hey("Hi there!") - assert.are.equals("Whatever.", result) + it('question with no letters', function() + local result = bob.hey("4?") + assert.are.equals("Sure.", result) end) - it('using acronyms in regular speech', function() - local result = bob.hey("It's OK if you don't want to go work for NASA.") - assert.are.equals("Whatever.", result) + it('non-letters with question', function() + local result = bob.hey(":) ?") + assert.are.equals("Sure.", result) end) - it('forceful question', function() - local result = bob.hey("WHAT'S GOING ON?") - assert.are.equals("Calm down, I know what I'm doing!", result) + it('prattling on', function() + local result = bob.hey("Wait! Hang on. Are you going to be OK?") + assert.are.equals("Sure.", result) end) - it('shouting numbers', function() - local result = bob.hey("1, 2, 3 GO!") + it('ending with whitespace', function() + local result = bob.hey("Okay if like my spacebar quite a bit? ") + assert.are.equals("Sure.", result) + end) + + it('multiple line question', function() + local result = bob.hey("\nDoes this cryogenic chamber make\n me look fat?") + assert.are.equals("Sure.", result) + end) + + it('shouting gibberish', function() + local result = bob.hey("FCECDFCAAB") assert.are.equals("Whoa, chill out!", result) end) - it('no letters', function() - local result = bob.hey("1, 2, 3") - assert.are.equals("Whatever.", result) + it('shouting a statement containing a question mark', function() + local result = bob.hey("DO LIONS EAT PEOPLE? AHHHHH.") + assert.are.equals("Whoa, chill out!", result) end) - it('question with no letters', function() - local result = bob.hey("4?") - assert.are.equals("Sure.", result) + it('shouting numbers', function() + local result = bob.hey("1, 2, 3 GO!") + assert.are.equals("Whoa, chill out!", result) end) it('shouting with special characters', function() @@ -71,58 +86,48 @@ describe('bob', function() assert.are.equals("Whoa, chill out!", result) end) - it('statement containing question mark', function() - local result = bob.hey("Ending with ? means a question.") - assert.are.equals("Whatever.", result) - end) - - it('non-letters with question', function() - local result = bob.hey(":) ?") - assert.are.equals("Sure.", result) + it('prolonged silence', function() + local result = bob.hey(" ") + assert.are.equals("Fine. Be that way!", result) end) - it('prattling on', function() - local result = bob.hey("Wait! Hang on. Are you going to be OK?") - assert.are.equals("Sure.", result) + it('alternate silence', function() + local result = bob.hey("\t\t\t\t\t\t\t\t\t\t") + assert.are.equals("Fine. Be that way!", result) end) - it('silence', function() - local result = bob.hey("") + it('other whitespace', function() + local result = bob.hey("\n\r \t") assert.are.equals("Fine. Be that way!", result) end) - it('prolonged silence', function() - local result = bob.hey(" ") - assert.are.equals("Fine. Be that way!", result) + it('talking forcefully', function() + local result = bob.hey("Hi there!") + assert.are.equals("Whatever.", result) end) - it('alternate silence', function() - local result = bob.hey("\t\t\t\t\t\t\t\t\t\t") - assert.are.equals("Fine. Be that way!", result) + it('using acronyms in regular speech', function() + local result = bob.hey("It's OK if you don't want to go work for NASA.") + assert.are.equals("Whatever.", result) end) - it('starting with whitespace', function() - local result = bob.hey(" hmmmmmmm...") + it('no letters', function() + local result = bob.hey("1, 2, 3") assert.are.equals("Whatever.", result) end) - it('ending with whitespace', function() - local result = bob.hey("Okay if like my spacebar quite a bit? ") - assert.are.equals("Sure.", result) + it('statement containing question mark', function() + local result = bob.hey("Ending with ? means a question.") + assert.are.equals("Whatever.", result) end) - it('other whitespace', function() - local result = bob.hey("\n\r \t") - assert.are.equals("Fine. Be that way!", result) + it('starting with whitespace', function() + local result = bob.hey(" hmmmmmmm...") + assert.are.equals("Whatever.", result) end) it('non-question ending with whitespace', function() local result = bob.hey("This is a statement ending with whitespace ") assert.are.equals("Whatever.", result) end) - - it('multiple line question', function() - local result = bob.hey("\nDoes this cryogenic chamber make\n me look fat?") - assert.are.equals("Sure.", result) - end) end) diff --git a/exercises/practice/state-of-tic-tac-toe/.meta/example.lua b/exercises/practice/state-of-tic-tac-toe/.meta/example.lua index f6e98dac..ef9056f6 100644 --- a/exercises/practice/state-of-tic-tac-toe/.meta/example.lua +++ b/exercises/practice/state-of-tic-tac-toe/.meta/example.lua @@ -33,7 +33,12 @@ local function gamestate(board) end end - assert(#win_x == 0 or #win_o == 0, 'Impossible board: game should have ended after the game was won') + local x_won = #win_x > 0 + local o_won = #win_o > 0 + + if (x_won and o_won) or (x_won and count_o == count_x) or (o_won and count_x > count_o) then + error('Impossible board: game should have ended after the game was won') + end if #win_x > 0 or #win_o > 0 then return 'win' diff --git a/exercises/practice/state-of-tic-tac-toe/.meta/tests.toml b/exercises/practice/state-of-tic-tac-toe/.meta/tests.toml index 8fc25e21..5f574b2a 100644 --- a/exercises/practice/state-of-tic-tac-toe/.meta/tests.toml +++ b/exercises/practice/state-of-tic-tac-toe/.meta/tests.toml @@ -99,3 +99,9 @@ reimplements = "b1dc8b13-46c4-47db-a96d-aa90eedc4e8d" [4801cda2-f5b7-4c36-8317-3cdd167ac22c] description = "Invalid boards -> Invalid board: players kept playing after a win" + +[5a84757a-fc86-4328-aec9-a5759e6ed35d] +description = "Invalid boards -> Invalid board: O kept playing after X wins" + +[cf25543d-583a-4656-b9ab-f82dc00a4a02] +description = "Invalid boards -> Invalid board: X kept playing after O wins" diff --git a/exercises/practice/state-of-tic-tac-toe/state-of-tic-tac-toe_spec.lua b/exercises/practice/state-of-tic-tac-toe/state-of-tic-tac-toe_spec.lua index 774613cd..c89629b7 100644 --- a/exercises/practice/state-of-tic-tac-toe/state-of-tic-tac-toe_spec.lua +++ b/exercises/practice/state-of-tic-tac-toe/state-of-tic-tac-toe_spec.lua @@ -258,5 +258,27 @@ describe('state-of-tic-tac-toe', function() state_of_tic_tac_toe.gamestate(board) end) end) + + it('invalid board: o kept playing after x wins', function() + local board = { + 'OO ', -- + 'XXX', -- + ' O ' -- + } + assert.has.error(function() + state_of_tic_tac_toe.gamestate(board) + end) + end) + + it('invalid board: x kept playing after o wins', function() + local board = { + 'XX ', -- + 'OOO', -- + ' XX' -- + } + assert.has.error(function() + state_of_tic_tac_toe.gamestate(board) + end) + end) end) end)