Basic framework for day modules

This commit is contained in:
Tyler Hallada 2022-12-01 13:13:35 -05:00
parent 03ce9032f7
commit 960737ff42
3 changed files with 27 additions and 13 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
zig-cache
zig-out

17
src/day01.zig Normal file
View File

@ -0,0 +1,17 @@
const std = @import("std");
pub fn solve_part1() !u32 {
return 0;
}
pub fn solve_part2() !u32 {
return 0;
}
test "solves part1" {
try std.testing.expectEqual(solve_part1(), 0);
}
test "solves part2" {
try std.testing.expectEqual(solve_part2(), 0);
}

View File

@ -1,24 +1,19 @@
const std = @import("std"); const std = @import("std");
pub fn main() !void { const day01 = @import("day01.zig");
// Prints to stderr (it's a shortcut based on `std.io.getStdErr()`)
std.debug.print("All your {s} are belong to us.\n", .{"codebase"});
// stdout is for the actual output of your application, for example if you pub fn main() !void {
// are implementing gzip, then only the compressed bytes should be sent to
// stdout, not any debugging messages.
const stdout_file = std.io.getStdOut().writer(); const stdout_file = std.io.getStdOut().writer();
var bw = std.io.bufferedWriter(stdout_file); var bw = std.io.bufferedWriter(stdout_file);
const stdout = bw.writer(); const stdout = bw.writer();
try stdout.print("Run `zig build test` to run the tests.\n", .{}); try stdout.print("Day 1\nPart 1: {}\nPart 2: {}\n\n", .{ try day01.solve_part1(), try day01.solve_part2() });
try bw.flush(); // don't forget to flush! try bw.flush();
} }
test "simple test" { test {
var list = std.ArrayList(i32).init(std.testing.allocator); std.testing.refAllDecls(@This());
defer list.deinit(); // try commenting this out and see if zig detects the memory leak!
try list.append(42); _ = day01;
try std.testing.expectEqual(@as(i32, 42), list.pop());
} }