From 4f4aa73d0c683ba365fabc4ec97b23c3ddef6ee4 Mon Sep 17 00:00:00 2001 From: Mathias Magnusson Date: Fri, 13 Dec 2024 23:38:42 +0100 Subject: aoc2024: add tests to template --- aoc24/build.zig | 1 + aoc24/src/dayX.zig | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/aoc24/build.zig b/aoc24/build.zig index 7648bf0..7a2c24b 100644 --- a/aoc24/build.zig +++ b/aoc24/build.zig @@ -83,6 +83,7 @@ pub fn build(b: *std.Build) void { .root_source_file = path, .target = target, .optimize = optimize, + .filters = &.{b.fmt("part{}", .{part})}, }); const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests); diff --git a/aoc24/src/dayX.zig b/aoc24/src/dayX.zig index 295b57e..6011887 100644 --- a/aoc24/src/dayX.zig +++ b/aoc24/src/dayX.zig @@ -2,18 +2,39 @@ const std = @import("std"); const Input = struct {}; +const test_input = + \\ +; + pub fn parse(allocator: std.mem.Allocator, data: []const u8) !Input { _ = allocator; _ = data; return .{}; } +test "part1" { + var arena = std.heap.ArenaAllocator.init(std.testing.allocator); + defer arena.deinit(); + + const output = try part1(arena.allocator(), try parse(arena.allocator(), test_input)); + try std.testing.expectEqual(1, output); +} + pub fn part1(allocator: std.mem.Allocator, input: Input) !u32 { _ = allocator; _ = input; return 0; } +test "part2" { + var arena = std.heap.ArenaAllocator.init(std.testing.allocator); + defer arena.deinit(); + + const output = try part2(arena.allocator(), try parse(arena.allocator(), test_input)); + std.debug.print("got {}\n", .{output}); + try std.testing.expectEqual(2, output); +} + pub fn part2(allocator: std.mem.Allocator, input: Input) !u32 { _ = allocator; _ = input; -- cgit v1.2.3