From dc8a85c7849cc1f01f2a05b9fb9afdbec1706037 Mon Sep 17 00:00:00 2001 From: 2wenty1ne Date: Tue, 5 Nov 2024 12:56:25 +0100 Subject: [PATCH] Finished --- main.zig | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 main.zig diff --git a/main.zig b/main.zig new file mode 100644 index 0000000..87532d5 --- /dev/null +++ b/main.zig @@ -0,0 +1,44 @@ +const std = @import("std"); +const expect = std.testing.expect; + +const MeinTyp = struct { + a: f64, + b: f64, + fn init(self: *MeinTyp) void { + self.a = 1.0; + self.b = 1.0; + } +}; + +fn MyType(comptime T:type) type { + return struct { + const Self = @This(); + a: T, + b: T, + fn init(this: *Self) void { + this.a = 1.0; + this.b = 1.0; + } + }; +} + + +test "MeinTyp" { + var mt: MeinTyp = undefined; + mt.init(); + try expect(mt.a == 1.0); + try expect(mt.b == 1.0); +} + +test "MyType" { + const Myt = MyType(f64); + var myInt: Myt = undefined; + myInt.init(); + try expect(myInt.a == 1.0); + try expect(myInt.b == 1.0); + + myInt.a = 2.0; + myInt.b = 3.0; + try expect(myInt.a == 2.0); + try expect(myInt.b == 3.0); +}