commit dc8a85c7849cc1f01f2a05b9fb9afdbec1706037 Author: 2wenty1ne Date: Tue Nov 5 12:56:25 2024 +0100 Finished 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); +}