diff --git a/.gitignore b/.gitignore index 4c82b07..ddc746a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ zig-cache zig-out +input.txt diff --git a/src/day1.zig b/src/day1.zig index 746f85e..9c8cefb 100644 --- a/src/day1.zig +++ b/src/day1.zig @@ -94,20 +94,17 @@ pub fn part2(input: *aoc.Input) !aoc.Result { } test "part 1 example" { - var lines = [_][]const u8{ + var example_input = [_][]const u8{ "1abc2", "pqr3stu8vwx", "a1b2c3d4e5f", "treb7uchet", }; - var input = aoc.Input{ .lines = &lines, .allocator = std.testing.allocator }; - var actual = try part1(&input); - var expected: u32 = 142; - try std.testing.expectEqual(expected, actual.uint); + try aoc.expectAnswerUInt(part1, 142, &example_input); } test "part 2 example" { - var lines = [_][]const u8{ + var example_input = [_][]const u8{ "two1nine", "eightwothree", "abcone2threexyz", @@ -116,8 +113,5 @@ test "part 2 example" { "zoneight234", "7pqrstsixteen", }; - var input = aoc.Input{ .lines = &lines, .allocator = std.testing.allocator }; - var actual = try part2(&input); - var expected: u32 = 281; - try std.testing.expectEqual(expected, actual.uint); + try aoc.expectAnswerUInt(part2, 281, &example_input); } diff --git a/src/day2.zig b/src/day2.zig index fe8735f..2c3fb4e 100644 --- a/src/day2.zig +++ b/src/day2.zig @@ -111,15 +111,9 @@ const example_input = [_][]const u8{ }; test "part 1 example" { - var input = aoc.Input{ .lines = &example_input, .allocator = std.testing.allocator }; - var actual = try part1(&input); - var expected: u32 = 8; - try std.testing.expectEqual(expected, actual.uint); + try aoc.expectAnswerUInt(part1, 8, &example_input); } test "part 2 example" { - var input = aoc.Input{ .lines = &example_input, .allocator = std.testing.allocator }; - var actual = try part2(&input); - var expected: u32 = 2286; - try std.testing.expectEqual(expected, actual.uint); + try aoc.expectAnswerUInt(part2, 2286, &example_input); } diff --git a/src/day3.zig b/src/day3.zig index e4e13f5..9a5ecfd 100644 --- a/src/day3.zig +++ b/src/day3.zig @@ -121,15 +121,9 @@ const example_input = [_][]const u8{ }; test "part 1 example" { - var input = aoc.Input{ .lines = &example_input, .allocator = std.testing.allocator }; - var actual = try part1(&input); - var expected: u32 = 4361; - try std.testing.expectEqual(expected, actual.uint); + try aoc.expectAnswerUInt(part1, 4361, &example_input); } test "part 2 example" { - var input = aoc.Input{ .lines = &example_input, .allocator = std.testing.allocator }; - var actual = try part2(&input); - var expected: u32 = 467835; - try std.testing.expectEqual(expected, actual.uint); + try aoc.expectAnswerUInt(part2, 467835, &example_input); } diff --git a/src/day4.zig b/src/day4.zig index 4827e40..bb34622 100644 --- a/src/day4.zig +++ b/src/day4.zig @@ -105,15 +105,9 @@ const example_input = [_][]const u8{ }; test "part 1 example" { - var input = aoc.Input{ .lines = &example_input, .allocator = std.testing.allocator }; - var actual = try part1(&input); - var expected: u32 = 13; - try std.testing.expectEqual(expected, actual.uint); + try aoc.expectAnswerUInt(part1, 13, &example_input); } test "part 2 example" { - var input = aoc.Input{ .lines = &example_input, .allocator = std.testing.allocator }; - var actual = try part2(&input); - var expected: u32 = 30; - try std.testing.expectEqual(expected, actual.uint); + try aoc.expectAnswerUInt(part2, 30, &example_input); } diff --git a/src/day5.zig b/src/day5.zig index 13a631e..7d27d70 100644 --- a/src/day5.zig +++ b/src/day5.zig @@ -249,16 +249,10 @@ const example_input = [_][]const u8{ }; test "part 1 example" { - var input = aoc.Input{ .lines = &example_input, .allocator = std.testing.allocator }; - var actual = try part1(&input); - var expected: u32 = 35; - try std.testing.expectEqual(expected, actual.uint); + try aoc.expectAnswerUInt(part1, 35, &example_input); } test "part 2 example" { - var input = aoc.Input{ .lines = &example_input, .allocator = std.testing.allocator }; - var actual = try part2(&input); - var expected: u32 = 46; - try std.testing.expectEqual(expected, actual.uint); + try aoc.expectAnswerUInt(part2, 46, &example_input); } diff --git a/src/day6.zig b/src/day6.zig index a7a9bcc..bc5cc89 100644 --- a/src/day6.zig +++ b/src/day6.zig @@ -101,15 +101,9 @@ const example_input = [_][]const u8{ }; test "part 1 example" { - var input = aoc.Input{ .lines = &example_input, .allocator = std.testing.allocator }; - var actual = try part1(&input); - var expected: u32 = 288; - try std.testing.expectEqual(expected, actual.uint); + try aoc.expectAnswerUInt(part1, 288, &example_input); } test "part 2 example" { - var input = aoc.Input{ .lines = &example_input, .allocator = std.testing.allocator }; - var actual = try part2(&input); - var expected: u32 = 71503; - try std.testing.expectEqual(expected, actual.uint); + try aoc.expectAnswerUInt(part2, 71503, &example_input); }