Skip to content

Commit

Permalink
LeetCode #002 (Zig)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuamegnauth54 committed May 17, 2024
1 parent cca506e commit 72c5b35
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions Zig/src/neet/002_add_two.zig
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ test "simple add works" {
} else {
std.debug.panic("Expected {} but got no values.", .{expected});
}

if (iter.next()) |invalid| {
std.debug.panic("Unexpected extra value: {}", .{invalid});
}
}

test "leetcode example 1" {
Expand Down Expand Up @@ -248,3 +252,28 @@ test "leetcode example 2" {
}
}
}

test "leetcode example 3" {
var lhs = try LinkedList().new(std.testing.allocator);
defer lhs.deinit();
var rhs = try LinkedList().new(std.testing.allocator);
defer rhs.deinit();

try lhs.insert_head(0);
try rhs.insert_head(0);

var out = try lhs.add(&rhs);
defer out.deinit();

const expected: u8 = 0;
var iter = out.iterator();
if (iter.next()) |actual| {
try expectEqual(expected, actual);
} else {
std.debug.panic("Expected {} but iterator is exhausted.", .{expected});
}

if (iter.next()) |invalid| {
std.debug.panic("Unexpected extra value: {}", .{invalid});
}
}

0 comments on commit 72c5b35

Please sign in to comment.