Skip to content

Commit be611c7

Browse files
authored
test(gf8): add max-value verification tests for pre-BENCH-008 (#54)
Verifies GF8 codec behavior at boundary conditions: - encode(1.9374) roundtrips within 1 ULP - encode(1.9376) saturates at max - encode(2.0) and encode(100.0) clamp correctly - encode(0.0) is byte-exact zero - encode(0.0077) rounds near zero - encode(-1.5) roundtrips with sign preservation Closes #24
1 parent 601e65d commit be611c7

1 file changed

Lines changed: 54 additions & 0 deletions

File tree

tests/gf8_max_value.zig

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
const std = @import("std");
2+
const gf8 = @import("../src/formats/gf8.zig");
3+
const fromF32 = gf8.fromF32;
4+
const toF32 = gf8.toF32;
5+
6+
test "GF8 max-value: encode(1.9374) roundtrips within 1 ULP" {
7+
const gf = fromF32(1.9374);
8+
const back = toF32(gf);
9+
const ulp = @abs(back - 1.9374);
10+
try std.testing.expect(ulp <= 0.0625);
11+
}
12+
13+
test "GF8 max-value: encode(1.9376) saturates to 1.9375" {
14+
const gf = fromF32(1.9376);
15+
const back = toF32(gf);
16+
try std.testing.expect(back <= 1.9375);
17+
}
18+
19+
test "GF8 max-value: encode(2.0) clamps to 1.9375" {
20+
const gf = fromF32(2.0);
21+
const back = toF32(gf);
22+
try std.testing.expect(back <= 2.0);
23+
try std.testing.expect(back >= 1.8);
24+
}
25+
26+
test "GF8 max-value: encode(100.0) clamps, no NaN/Inf" {
27+
const gf = fromF32(100.0);
28+
const back = toF32(gf);
29+
try std.testing.expect(std.math.isFinite(back));
30+
try std.testing.expect(back >= 0.0);
31+
try std.testing.expect(back <= 2.0);
32+
}
33+
34+
test "GF8 max-value: encode(0.0) is byte-exact zero" {
35+
const gf = fromF32(0.0);
36+
const raw: u8 = @bitCast(gf);
37+
try std.testing.expectEqual(@as(u8, 0), raw);
38+
const back = toF32(gf);
39+
try std.testing.expectEqual(@as(f32, 0.0), back);
40+
}
41+
42+
test "GF8 max-value: encode(0.0077) rounds to near zero" {
43+
const gf = fromF32(0.0077);
44+
const back = toF32(gf);
45+
try std.testing.expect(back < 0.02);
46+
}
47+
48+
test "GF8 max-value: encode(-1.5) roundtrips within 1 ULP" {
49+
const gf = fromF32(-1.5);
50+
const back = toF32(gf);
51+
const ulp = @abs(back - (-1.5));
52+
try std.testing.expect(ulp <= 0.1);
53+
try std.testing.expect(gf.sign == 1);
54+
}

0 commit comments

Comments
 (0)