const std = @import("std"); const c = @cImport(@cInclude("pgcd.c")); // No need to have a .h pub fn main() !void { var gpa = std.heap.GeneralPurposeAllocator(.{}){}; defer _ = gpa.deinit(); const allocator = gpa.allocator(); const args = try std.process.argsAlloc(allocator); defer std.process.argsFree(allocator, args); if (args.len != 3) { std.debug.print("Usage: find-pgcd L R\n", .{}); return error.WrongArgs; } var l = try std.fmt.parseInt(u32, args[1], 10); var r = try std.fmt.parseInt(u32, args[2], 10); // A good reading is https://renato.athaydes.com/posts/testing-building-c-with-zig.html std.debug.print("PGCD({d},{d}) = {d}\n", .{ l, r, c.pgcd(l, r) }); } const expect = @import("std").testing.expect; fn expectidentical(i: u32) !void { try expect(c.pgcd(i, i) == i); } test "identical" { try expectidentical(1); try expectidentical(7); try expectidentical(18); } test "primes" { try expect(c.pgcd(4, 13) == 1); } test "pgcdexists" { try expect(c.pgcd(15, 35) == 5); } test "pgcdlower" { try expect(c.pgcd(15, 5) == 5); }