improving mul test
Some checks failed
Build / build (push) Successful in 55s
Test / build (push) Failing after 4m26s

This commit is contained in:
2026-01-14 20:14:23 +01:00
parent b8a564e135
commit 88e847e2d9
4 changed files with 103 additions and 85 deletions

View File

@@ -5,25 +5,26 @@ const case = root.case;
test "Mul vec4" {
const allocator = std.testing.allocator;
const types = [_]type{ f32, i32 };
const types = [_]type{
f32,
//f64,
i32,
u32,
};
inline for (types) |T| {
const prng: std.Random.DefaultPrng = .init(@intCast(std.time.microTimestamp()));
const base_color: [4]T = undefined;
std.Random.shuffle(prng, T, base_color);
const ratio: [4]T = undefined;
std.Random.shuffle(prng, T, ratio);
const expected = [4]T{
base_color[0] * ratio[0],
base_color[1] * ratio[1],
base_color[2] * ratio[2],
base_color[3] * ratio[3],
const base_color = case.random(@Vector(4, T));
const ratio = case.random(@Vector(4, T));
const expected = switch (@typeInfo(T)) {
.float => base_color * ratio,
.int => @mulWithOverflow(base_color, ratio)[0],
else => unreachable,
};
const shader = try std.fmt.allocPrint(
allocator,
\\ [nzsl_version("1.1")]
\\ [feature(float64)]
\\ module;
\\
\\ struct FragOut
@@ -41,21 +42,23 @@ test "Mul vec4" {
\\ 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],
.{
@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],
},
);
defer allocator.free(shader);
const code = try compileNzsl(allocator, shader);
defer allocator.free(code);
try case.expectOutput(f32, code, "color", &expected);
try case.expectOutput(T, 4, code, "color", &@as([4]T, expected));
}
}