improving tests; CI skip
This commit is contained in:
103
test/maths.zig
103
test/maths.zig
@@ -3,56 +3,59 @@ const root = @import("root.zig");
|
|||||||
const compileNzsl = root.compileNzsl;
|
const compileNzsl = root.compileNzsl;
|
||||||
const case = root.case;
|
const case = root.case;
|
||||||
|
|
||||||
test "FMul vec4[f32]" {
|
test "Mul vec4" {
|
||||||
const allocator = std.testing.allocator;
|
const allocator = std.testing.allocator;
|
||||||
const shader =
|
const types = [_]type{ f32, i32 };
|
||||||
\\ [nzsl_version("1.1")]
|
inline for (types) |T| {
|
||||||
\\ module;
|
const prng: std.Random.DefaultPrng = .init(@intCast(std.time.microTimestamp()));
|
||||||
\\
|
|
||||||
\\ struct FragOut
|
|
||||||
\\ {
|
|
||||||
\\ [location(0)] color: vec4[f32]
|
|
||||||
\\ }
|
|
||||||
\\
|
|
||||||
\\ [entry(frag)]
|
|
||||||
\\ fn main() -> FragOut
|
|
||||||
\\ {
|
|
||||||
\\ let ratio = vec4[f32](2.0, 2.0, 8.0, 0.25);
|
|
||||||
\\
|
|
||||||
\\ let output: FragOut;
|
|
||||||
\\ output.color = vec4[f32](4.0, 3.0, 2.0, 1.0) * ratio;
|
|
||||||
\\ return output;
|
|
||||||
\\ }
|
|
||||||
;
|
|
||||||
const code = try compileNzsl(allocator, shader);
|
|
||||||
defer allocator.free(code);
|
|
||||||
|
|
||||||
try case.expectOutput(f32, code, "color", &.{ 8, 6, 16, 0.25 });
|
const base_color: [4]T = undefined;
|
||||||
}
|
std.Random.shuffle(prng, T, base_color);
|
||||||
|
const ratio: [4]T = undefined;
|
||||||
test "IMul vec4[i32]" {
|
std.Random.shuffle(prng, T, ratio);
|
||||||
const allocator = std.testing.allocator;
|
|
||||||
const shader =
|
const expected = [4]T{
|
||||||
\\ [nzsl_version("1.1")]
|
base_color[0] * ratio[0],
|
||||||
\\ module;
|
base_color[1] * ratio[1],
|
||||||
\\
|
base_color[2] * ratio[2],
|
||||||
\\ struct FragOut
|
base_color[3] * ratio[3],
|
||||||
\\ {
|
};
|
||||||
\\ [location(0)] color: vec4[i32]
|
|
||||||
\\ }
|
const shader = try std.fmt.allocPrint(
|
||||||
\\
|
allocator,
|
||||||
\\ [entry(frag)]
|
\\ [nzsl_version("1.1")]
|
||||||
\\ fn main() -> FragOut
|
\\ module;
|
||||||
\\ {
|
\\
|
||||||
\\ let ratio = vec4[i32](2, 2, 8, 25);
|
\\ struct FragOut
|
||||||
\\
|
\\ {{
|
||||||
\\ let output: FragOut;
|
\\ [location(0)] color: vec4[{s}]
|
||||||
\\ output.color = vec4[i32](4, 3, 2, 1) * ratio;
|
\\ }}
|
||||||
\\ return output;
|
\\
|
||||||
\\ }
|
\\ [entry(frag)]
|
||||||
;
|
\\ fn main() -> FragOut
|
||||||
const code = try compileNzsl(allocator, shader);
|
\\ {{
|
||||||
defer allocator.free(code);
|
\\ let ratio = vec4[{s}]({d}, {d}, {d}, {d});
|
||||||
|
\\
|
||||||
try case.expectOutput(i32, code, "color", &.{ 8, 6, 16, 25 });
|
\\ let output: FragOut;
|
||||||
|
\\ output.color = vec4[{s}]({d}, {d}, {d}, {d}) * ratio;
|
||||||
|
\\ return output;
|
||||||
|
\\ }}
|
||||||
|
,
|
||||||
|
@typeName(T),
|
||||||
|
@typeName(T),
|
||||||
|
ratio[0],
|
||||||
|
ratio[1],
|
||||||
|
ratio[2],
|
||||||
|
ratio[3],
|
||||||
|
@typeName(T),
|
||||||
|
base_color[0],
|
||||||
|
base_color[1],
|
||||||
|
base_color[2],
|
||||||
|
base_color[3],
|
||||||
|
);
|
||||||
|
const code = try compileNzsl(allocator, shader);
|
||||||
|
defer allocator.free(code);
|
||||||
|
|
||||||
|
try case.expectOutput(f32, code, "color", &expected);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user