Skip to content

Commit

Permalink
Improve LeetCode 922 unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuamegnauth54 committed Mar 15, 2024
1 parent 728fe78 commit afd9a10
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions Zig/src/neet/922_array_parity_2.zig
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,22 @@ test "LeetCode example 2" {
try expectEqualSlices(u8, &expected, actual);
}

test "unbalanced parity fails" {
test "unbalanced parity (even) fails" {
const input = [_]u8{ 4, 6, 8, 10 };
const expected = ArrayParityError.NotEnoughOdds;

const actual = sort_array_parity_2(u8, std.testing.allocator, &input) catch |err| {
try expectError(expected, err);
};
const actual = sort_array_parity_2(u8, std.testing.allocator, &input);
errdefer std.testing.allocator.free(actual catch unreachable);

try expectError(expected, actual);
}

test "unbalanced parity (odd) fails" {
const input = [_]u8{ 3, 5, 7, 9 };
const expected = ArrayParityError.NotEnoughEvens;

const actual = sort_array_parity_2(u8, std.testing.allocator, &input);
errdefer std.testing.allocator.free(actual catch unreachable);

std.testing.allocator.free(actual);
@panic("Expected error `NotEnoughOdds`");
try expectError(expected, actual);
}

0 comments on commit afd9a10

Please sign in to comment.