From 0a9f08cbf01c251f4f878cfad6f3685ace8f6f9d Mon Sep 17 00:00:00 2001 From: Gabe Venberg Date: Mon, 2 Dec 2024 17:59:08 +0100 Subject: [PATCH] template. --- days/template/input.txt | 0 days/template/lib.zig | 1 + days/template/main.zig | 24 ++++++++++++++++++++++++ days/template/part1.zig | 13 +++++++++++++ days/template/part2.zig | 13 +++++++++++++ 5 files changed, 51 insertions(+) create mode 100644 days/template/input.txt create mode 100644 days/template/lib.zig create mode 100644 days/template/main.zig create mode 100644 days/template/part1.zig create mode 100644 days/template/part2.zig diff --git a/days/template/input.txt b/days/template/input.txt new file mode 100644 index 0000000..e69de29 diff --git a/days/template/lib.zig b/days/template/lib.zig new file mode 100644 index 0000000..95a0b68 --- /dev/null +++ b/days/template/lib.zig @@ -0,0 +1 @@ +const std = @import("std"); diff --git a/days/template/main.zig b/days/template/main.zig new file mode 100644 index 0000000..c8a3f67 --- /dev/null +++ b/days/template/main.zig @@ -0,0 +1,24 @@ +const std = @import("std"); + +pub fn main() !void { + // 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 + // are implementing gzip, then only the compressed bytes should be sent to + // stdout, not any debugging messages. + const stdout_file = std.io.getStdOut().writer(); + var bw = std.io.bufferedWriter(stdout_file); + const stdout = bw.writer(); + + try stdout.print("Run `zig build test` to run the tests.\n", .{}); + + try bw.flush(); // don't forget to flush! +} + +test "simple test" { + var list = std.ArrayList(i32).init(std.testing.allocator); + defer list.deinit(); // try commenting this out and see if zig detects the memory leak! + try list.append(42); + try std.testing.expectEqual(@as(i32, 42), list.pop()); +} diff --git a/days/template/part1.zig b/days/template/part1.zig new file mode 100644 index 0000000..2d9e59d --- /dev/null +++ b/days/template/part1.zig @@ -0,0 +1,13 @@ +const lib = @import("lib.zig"); +const std = @import("std"); + +pub fn part1(comptime input: []const u8) i32 { + return input.len; +} + +test "part1 sample" { + const input = + \\0 + ; + try std.testing.expectEqual(part1(input), 11); +} diff --git a/days/template/part2.zig b/days/template/part2.zig new file mode 100644 index 0000000..9b0420f --- /dev/null +++ b/days/template/part2.zig @@ -0,0 +1,13 @@ +const lib = @import("lib.zig"); +const std = @import("std"); + +pub fn part2(comptime input: []const u8) i32 { + return input.len; +} + +test "part2 sample" { + const input = + \\0 + ; + try std.testing.expectEqual(part2(input), 1); +}