Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions exercises/practice/bob/.meta/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ 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"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test is already implemented


[a20e0c54-2224-4dde-8b10-bd2cdd4f61bc]
description = "shouting numbers"

Expand Down
108 changes: 30 additions & 78 deletions exercises/practice/bob/test_bob.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3,158 +3,110 @@ const testing = std.testing;

const response = @import("bob.zig").response;

fn testResponse(s: []const u8, expected: []const u8) !void {
try testing.expectEqualStrings(expected, response(s));
}

test "asking a question" {
const expected = "Sure.";
const actual = response("Does this cryogenic chamber make me look fat?");
try testing.expectEqualStrings(expected, actual);
try testResponse("Does this cryogenic chamber make me look fat?", "Sure.");
}

test "shouting" {
const expected = "Whoa, chill out!";
const actual = response("WATCH OUT!");
try testing.expectEqualStrings(expected, actual);
try testResponse("WATCH OUT!", "Whoa, chill out!");
}

test "forceful question" {
const expected = "Calm down, I know what I'm doing!";
const actual = response("WHAT'S GOING ON?");
try testing.expectEqualStrings(expected, actual);
try testResponse("WHAT'S GOING ON?", "Calm down, I know what I'm doing!");
}

test "silence" {
const expected = "Fine. Be that way!";
const actual = response("");
try testing.expectEqualStrings(expected, actual);
try testResponse("", "Fine. Be that way!");
}

test "stating something" {
const expected = "Whatever.";
const actual = response("Tom-ay-to, tom-aaaah-to.");
try testing.expectEqualStrings(expected, actual);
try testResponse("Tom-ay-to, tom-aaaah-to.", "Whatever.");
}

test "asking a numeric question" {
const expected = "Sure.";
const actual = response("You are, what, like 15?");
try testing.expectEqualStrings(expected, actual);
try testResponse("You are, what, like 15?", "Sure.");
}

test "asking gibberish" {
const expected = "Sure.";
const actual = response("fffbbcbeab?");
try testing.expectEqualStrings(expected, actual);
try testResponse("fffbbcbeab?", "Sure.");
}

test "question with no letters" {
const expected = "Sure.";
const actual = response("4?");
try testing.expectEqualStrings(expected, actual);
try testResponse("4?", "Sure.");
}

test "non-letters with question" {
const expected = "Sure.";
const actual = response(":) ?");
try testing.expectEqualStrings(expected, actual);
try testResponse(":) ?", "Sure.");
}

test "prattling on" {
const expected = "Sure.";
const actual = response("Wait! Hang on. Are you going to be OK?");
try testing.expectEqualStrings(expected, actual);
try testResponse("Wait! Hang on. Are you going to be OK?", "Sure.");
}

test "ending with whitespace" {
const expected = "Sure.";
const actual = response("Okay if like my spacebar quite a bit? ");
try testing.expectEqualStrings(expected, actual);
try testResponse("Okay if like my spacebar quite a bit? ", "Sure.");
}

test "multiple line question" {
const expected = "Sure.";
const actual = response("\nDoes this cryogenic chamber make\n me look fat?");
try testing.expectEqualStrings(expected, actual);
try testResponse("\nDoes this cryogenic chamber make\n me look fat?", "Sure.");
}

test "shouting gibberish" {
const expected = "Whoa, chill out!";
const actual = response("FCECDFCAAB");
try testing.expectEqualStrings(expected, actual);
try testResponse("FCECDFCAAB", "Whoa, chill out!");
}

test "shouting a statement containing a question mark" {
const expected = "Whoa, chill out!";
const actual = response("DO LIONS EAT PEOPLE? AHHHHH.");
try testing.expectEqualStrings(expected, actual);
try testResponse("DO LIONS EAT PEOPLE? AHHHHH.", "Whoa, chill out!");
}

test "shouting numbers" {
const expected = "Whoa, chill out!";
const actual = response("1, 2, 3 GO!");
try testing.expectEqualStrings(expected, actual);
try testResponse("1, 2, 3 GO!", "Whoa, chill out!");
}

test "shouting with special characters" {
const expected = "Whoa, chill out!";
const actual = response("ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!");
try testing.expectEqualStrings(expected, actual);
try testResponse("ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!", "Whoa, chill out!");
}

test "shouting with no exclamation mark" {
const expected = "Whoa, chill out!";
const actual = response("I HATE THE DENTIST");
try testing.expectEqualStrings(expected, actual);
try testResponse("I HATE THE DENTIST", "Whoa, chill out!");
}

test "prolonged silence" {
const expected = "Fine. Be that way!";
const actual = response(" ");
try testing.expectEqualStrings(expected, actual);
try testResponse(" ", "Fine. Be that way!");
}

test "alternate silence" {
const expected = "Fine. Be that way!";
const actual = response("\t\t\t\t\t\t\t\t\t\t");
try testing.expectEqualStrings(expected, actual);
try testResponse("\t\t\t\t\t\t\t\t\t\t", "Fine. Be that way!");
}

test "other whitespace" {
const expected = "Fine. Be that way!";
const actual = response("\n\r \t");
try testing.expectEqualStrings(expected, actual);
try testResponse("\n\r \t", "Fine. Be that way!");
}

test "talking forcefully" {
const expected = "Whatever.";
const actual = response("Hi there!");
try testing.expectEqualStrings(expected, actual);
try testResponse("Hi there!", "Whatever.");
}

test "using acronyms in regular speech" {
const expected = "Whatever.";
const actual = response("It's OK if you don't want to go work for NASA.");
try testing.expectEqualStrings(expected, actual);
try testResponse("It's OK if you don't want to go work for NASA.", "Whatever.");
}

test "no letters" {
const expected = "Whatever.";
const actual = response("1, 2, 3");
try testing.expectEqualStrings(expected, actual);
try testResponse("1, 2, 3", "Whatever.");
}

test "statement containing question mark" {
const expected = "Whatever.";
const actual = response("Ending with ? means a question.");
try testing.expectEqualStrings(expected, actual);
try testResponse("Ending with ? means a question.", "Whatever.");
}

test "starting with whitespace" {
const expected = "Whatever.";
const actual = response(" hmmmmmmm...");
try testing.expectEqualStrings(expected, actual);
try testResponse(" hmmmmmmm...", "Whatever.");
}

test "non-question ending with whitespace" {
const expected = "Whatever.";
const actual = response("This is a statement ending with whitespace ");
try testing.expectEqualStrings(expected, actual);
try testResponse("This is a statement ending with whitespace ", "Whatever.");
}
14 changes: 7 additions & 7 deletions exercises/practice/state-of-tic-tac-toe/.meta/example.zig
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ pub fn gameState(board: []const []const u8) GameState {
current = current << 1;
}

if (countO > countX) {
// Wrong turn order: O started
const winX = isWin(bitsetX);
const winO = isWin(bitsetO);

if (countO + @intFromBool(winX) > countX) {
// Wrong turn order: O started, or O kept playing after X wins
return .impossible;
}

if (countX > countO + 1) {
// Wrong turn order: X went twice
if (countX + @intFromBool(winO) > countO + 1) {
// Wrong turn order: X went twice, or X kept playing after O wins
return .impossible;
}

const winX = isWin(bitsetX);
const winO = isWin(bitsetO);

if (winX or winO) {
if (winX and winO) {
// Impossible board: game should have ended after the game was won
Expand Down
6 changes: 6 additions & 0 deletions exercises/practice/state-of-tic-tac-toe/.meta/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Loading
Loading