template.
This commit is contained in:
parent
579c643f3f
commit
0a9f08cbf0
5 changed files with 51 additions and 0 deletions
0
days/template/input.txt
Normal file
0
days/template/input.txt
Normal file
1
days/template/lib.zig
Normal file
1
days/template/lib.zig
Normal file
|
@ -0,0 +1 @@
|
|||
const std = @import("std");
|
24
days/template/main.zig
Normal file
24
days/template/main.zig
Normal file
|
@ -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());
|
||||
}
|
13
days/template/part1.zig
Normal file
13
days/template/part1.zig
Normal file
|
@ -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);
|
||||
}
|
13
days/template/part2.zig
Normal file
13
days/template/part2.zig
Normal file
|
@ -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);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue