lib/strconv tests: hand-main plumbing -> assert (@test conversion B3)
inttest keeps now-inert per-row id params (rows 1:1 per spec; removal deferred, ~100 callsites).
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
// stoftest — exercises lib/strconv/stof.ww (Hare stof.ha port).
|
||||
// Run with `out/bin/ww run lib/strconv/test/stoftest.ww`. Same
|
||||
// signalled-then-os.exit(signalled+10) pattern as decimaltest: a
|
||||
// non-zero exit names the failing @test (1..N → exit 11..N+10).
|
||||
// Run with `out/bin/ww run lib/strconv/test/stoftest.ww`. A failing row
|
||||
// aborts via the assert/abort builtin (task #5 @test conversion).
|
||||
//
|
||||
// Ports ref/hare/strconv/stof.ha's @test vectors (stof64 / stof32 /
|
||||
// stofhex). Comparisons are BIT-level (math.f64bits / f32bits) so a
|
||||
@@ -18,11 +17,8 @@
|
||||
package strconv_test;
|
||||
|
||||
import strconv;
|
||||
import os;
|
||||
import math;
|
||||
|
||||
let signalled: i32 = 0;
|
||||
fn fail() void = { os.exit(signalled + 10); };
|
||||
|
||||
// ---- unwrap helpers (bit-exact value checks) -------------------------
|
||||
|
||||
@@ -108,20 +104,20 @@ fn nan32(s: str) bool = {
|
||||
let nzero: f64 = math.f64frombits(1u64 << 63u64); // -0.0 (1<<63 dodges the I64_MIN-literal emit bug #144)
|
||||
let subn: f64 = math.f64frombits(0x0000000000000001u64); // 5e-324
|
||||
|
||||
if (!chk64("0", base.DEC, 0.0)) { fail(); };
|
||||
if (!chk64("200", base.DEC, 200.0)) { fail(); };
|
||||
if (!chk64("12345", base.DEC, 12345.0)) { fail(); };
|
||||
if (!chk64("+112233445566778899", base.DEC, 1.122334455667789e17)) { fail(); };
|
||||
if (!chk64("3.14", base.DEC, 3.14)) { fail(); };
|
||||
if (!chk64("2.99792458E+8", base.DEC, 299792458.0)) { fail(); };
|
||||
if (!chk64("6.022e23", base.DEC, 6.022e23)) { fail(); };
|
||||
if (!ovf64("1e310", base.DEC)) { fail(); };
|
||||
if (!chk64("9007199254740991", base.DEC, 9007199254740991.0)) { fail(); };
|
||||
if (!chk64("90071992547409915", base.DEC, 90071992547409920.0)) { fail(); };
|
||||
if (!chk64("90071992547409925", base.DEC, 90071992547409920.0)) { fail(); };
|
||||
if (!chk64("2.2250738585072014e-308", base.DEC, 2.2250738585072014e-308)) { fail(); };
|
||||
if (!chk64("-1e-324", base.DEC, nzero)) { fail(); };
|
||||
if (!chk64("5e-324", base.DEC, subn)) { fail(); };
|
||||
assert(!(!chk64("0", base.DEC, 0.0)));
|
||||
assert(!(!chk64("200", base.DEC, 200.0)));
|
||||
assert(!(!chk64("12345", base.DEC, 12345.0)));
|
||||
assert(!(!chk64("+112233445566778899", base.DEC, 1.122334455667789e17)));
|
||||
assert(!(!chk64("3.14", base.DEC, 3.14)));
|
||||
assert(!(!chk64("2.99792458E+8", base.DEC, 299792458.0)));
|
||||
assert(!(!chk64("6.022e23", base.DEC, 6.022e23)));
|
||||
assert(!(!ovf64("1e310", base.DEC)));
|
||||
assert(!(!chk64("9007199254740991", base.DEC, 9007199254740991.0)));
|
||||
assert(!(!chk64("90071992547409915", base.DEC, 90071992547409920.0)));
|
||||
assert(!(!chk64("90071992547409925", base.DEC, 90071992547409920.0)));
|
||||
assert(!(!chk64("2.2250738585072014e-308", base.DEC, 2.2250738585072014e-308)));
|
||||
assert(!(!chk64("-1e-324", base.DEC, nzero)));
|
||||
assert(!(!chk64("5e-324", base.DEC, subn)));
|
||||
|
||||
// Decimal-engine edge probes migrated here when the white-box
|
||||
// decimaltest.ww retired (#16): the external-test idiom can't reach
|
||||
@@ -132,23 +128,23 @@ fn nan32(s: str) bool = {
|
||||
// Micro-gap (rule-7, honest): decimal_shift's k=0 early-return no-op
|
||||
// is a trivial guard, not reached transitively by any slow-path input
|
||||
// — consciously un-migrated, not silently dropped.
|
||||
if (!chk64("9999999999999999", base.DEC, 1.0e16)) { fail(); };
|
||||
if (!chk64("100000000000000000001", base.DEC, 1.0e20)) { fail(); };
|
||||
assert(!(!chk64("9999999999999999", base.DEC, 1.0e16)));
|
||||
assert(!(!chk64("100000000000000000001", base.DEC, 1.0e20)));
|
||||
|
||||
if (inv64("") != 0) { fail(); };
|
||||
if (inv64("0ZO") != 1) { fail(); };
|
||||
if (inv64("1.23ezz") != 5) { fail(); };
|
||||
assert(!(inv64("") != 0));
|
||||
assert(!(inv64("0ZO") != 1));
|
||||
assert(!(inv64("1.23ezz") != 5));
|
||||
|
||||
if (!chk64("Infinity", base.DEC, inf)) { fail(); };
|
||||
if (!chk64("+Infinity", base.DEC, inf)) { fail(); };
|
||||
if (!chk64("-Infinity", base.DEC, ninf)) { fail(); };
|
||||
if (!chk64("infinity", base.DEC, inf)) { fail(); };
|
||||
if (!chk64("inFinIty", base.DEC, inf)) { fail(); };
|
||||
if (!chk64("-infinity", base.DEC, ninf)) { fail(); };
|
||||
if (!chk64("-infiNity", base.DEC, ninf)) { fail(); };
|
||||
if (!nan64("NaN")) { fail(); };
|
||||
if (!nan64("nan")) { fail(); };
|
||||
if (!nan64("naN")) { fail(); };
|
||||
assert(!(!chk64("Infinity", base.DEC, inf)));
|
||||
assert(!(!chk64("+Infinity", base.DEC, inf)));
|
||||
assert(!(!chk64("-Infinity", base.DEC, ninf)));
|
||||
assert(!(!chk64("infinity", base.DEC, inf)));
|
||||
assert(!(!chk64("inFinIty", base.DEC, inf)));
|
||||
assert(!(!chk64("-infinity", base.DEC, ninf)));
|
||||
assert(!(!chk64("-infiNity", base.DEC, ninf)));
|
||||
assert(!(!nan64("NaN")));
|
||||
assert(!(!nan64("nan")));
|
||||
assert(!(!nan64("naN")));
|
||||
};
|
||||
|
||||
// ---- stof32 ----------------------------------------------------------
|
||||
@@ -160,34 +156,34 @@ fn nan32(s: str) bool = {
|
||||
let nzero: f32 = math.f32frombits(0x80000000u32); // -0.0
|
||||
let subn: f32 = math.f32frombits(0x00000001u32); // 1e-45
|
||||
|
||||
if (!chk32("0", base.DEC, 0.0f32)) { fail(); };
|
||||
if (!chk32("1e10", base.DEC, 1.0e10f32)) { fail(); };
|
||||
if (!chk32("299792458", base.DEC, 299792458.0f32)) { fail(); };
|
||||
if (!chk32("6.022e23", base.DEC, 6.022e23f32)) { fail(); };
|
||||
if (!ovf32("1e40", base.DEC)) { fail(); };
|
||||
if (!chk32("16777215", base.DEC, 16777215.0f32)) { fail(); };
|
||||
if (!chk32("167772155", base.DEC, 167772160.0f32)) { fail(); };
|
||||
if (!chk32("167772145", base.DEC, 167772140.0f32)) { fail(); };
|
||||
if (!chk32("6.62607015e-34", base.DEC, 6.62607015e-34f32)) { fail(); };
|
||||
if (!chk32("1.1754944e-38", base.DEC, 1.1754944e-38f32)) { fail(); };
|
||||
if (!chk32("-1e-50", base.DEC, nzero)) { fail(); };
|
||||
if (!chk32("1e-45", base.DEC, subn)) { fail(); };
|
||||
assert(!(!chk32("0", base.DEC, 0.0f32)));
|
||||
assert(!(!chk32("1e10", base.DEC, 1.0e10f32)));
|
||||
assert(!(!chk32("299792458", base.DEC, 299792458.0f32)));
|
||||
assert(!(!chk32("6.022e23", base.DEC, 6.022e23f32)));
|
||||
assert(!(!ovf32("1e40", base.DEC)));
|
||||
assert(!(!chk32("16777215", base.DEC, 16777215.0f32)));
|
||||
assert(!(!chk32("167772155", base.DEC, 167772160.0f32)));
|
||||
assert(!(!chk32("167772145", base.DEC, 167772140.0f32)));
|
||||
assert(!(!chk32("6.62607015e-34", base.DEC, 6.62607015e-34f32)));
|
||||
assert(!(!chk32("1.1754944e-38", base.DEC, 1.1754944e-38f32)));
|
||||
assert(!(!chk32("-1e-50", base.DEC, nzero)));
|
||||
assert(!(!chk32("1e-45", base.DEC, subn)));
|
||||
|
||||
if (inv32("") != 0) { fail(); };
|
||||
if (inv32("0ZO") != 1) { fail(); };
|
||||
if (inv32("1.23e-zz") != 6) { fail(); };
|
||||
assert(!(inv32("") != 0));
|
||||
assert(!(inv32("0ZO") != 1));
|
||||
assert(!(inv32("1.23e-zz") != 6));
|
||||
|
||||
if (!chk32("Infinity", base.DEC, inf)) { fail(); };
|
||||
if (!chk32("+Infinity", base.DEC, inf)) { fail(); };
|
||||
if (!chk32("-Infinity", base.DEC, ninf)) { fail(); };
|
||||
if (!chk32("infinity", base.DEC, inf)) { fail(); };
|
||||
if (!chk32("inFinIty", base.DEC, inf)) { fail(); };
|
||||
if (!chk32("-infinity", base.DEC, ninf)) { fail(); };
|
||||
if (!chk32("-infiniTy", base.DEC, ninf)) { fail(); };
|
||||
if (!nan32("NaN")) { fail(); };
|
||||
if (!nan32("nan")) { fail(); };
|
||||
if (!nan32("naN")) { fail(); };
|
||||
if (!chk32("9.19100241453305036800e+20", base.DEC, 9.19100241453305036800e+20f32)) { fail(); };
|
||||
assert(!(!chk32("Infinity", base.DEC, inf)));
|
||||
assert(!(!chk32("+Infinity", base.DEC, inf)));
|
||||
assert(!(!chk32("-Infinity", base.DEC, ninf)));
|
||||
assert(!(!chk32("infinity", base.DEC, inf)));
|
||||
assert(!(!chk32("inFinIty", base.DEC, inf)));
|
||||
assert(!(!chk32("-infinity", base.DEC, ninf)));
|
||||
assert(!(!chk32("-infiniTy", base.DEC, ninf)));
|
||||
assert(!(!nan32("NaN")));
|
||||
assert(!(!nan32("nan")));
|
||||
assert(!(!nan32("naN")));
|
||||
assert(!(!chk32("9.19100241453305036800e+20", base.DEC, 9.19100241453305036800e+20f32)));
|
||||
};
|
||||
|
||||
// ---- stofhex ---------------------------------------------------------
|
||||
@@ -196,44 +192,44 @@ fn nan32(s: str) bool = {
|
||||
// has no hex-float literal lexer / no F*_MAX_NORMAL math consts.
|
||||
|
||||
@test fn stof64_hex() void = {
|
||||
if (!chk64("0p0", base.HEX, 0.0)) { fail(); };
|
||||
if (!chk64("1p0", base.HEX, 1.0)) { fail(); };
|
||||
if (!chk64("-1p0", base.HEX_LOWER, -1.0)) { fail(); };
|
||||
assert(!(!chk64("0p0", base.HEX, 0.0)));
|
||||
assert(!(!chk64("1p0", base.HEX, 1.0)));
|
||||
assert(!(!chk64("-1p0", base.HEX_LOWER, -1.0)));
|
||||
// 0x1.fp-2 = 1.9375 * 2^-2 = 0.484375 (exact).
|
||||
if (!chk64("1.fp-2", base.HEX, 0.484375)) { fail(); };
|
||||
assert(!(!chk64("1.fp-2", base.HEX, 0.484375)));
|
||||
// F64_MAX_NORMAL.
|
||||
if (!chk64("1.fffffffffffffp+1023", base.HEX,
|
||||
math.f64frombits(0x7FEFFFFFFFFFFFFFu64))) { fail(); };
|
||||
math.f64frombits(0x7FEFFFFFFFFFFFFFu64))) { abort(); };
|
||||
// F64_MIN_NORMAL.
|
||||
if (!chk64("1.0000000000000p-1022", base.HEX,
|
||||
math.f64frombits(0x0010000000000000u64))) { fail(); };
|
||||
math.f64frombits(0x0010000000000000u64))) { abort(); };
|
||||
// F64_MIN_SUBNORMAL.
|
||||
if (!chk64("0.0000000000001p-1022", base.HEX,
|
||||
math.f64frombits(0x0000000000000001u64))) { fail(); };
|
||||
if (!ovf64("1p+1024", base.HEX)) { fail(); };
|
||||
if (!chk64("0.00000000000001p-1022", base.HEX, 0.0)) { fail(); };
|
||||
math.f64frombits(0x0000000000000001u64))) { abort(); };
|
||||
assert(!(!ovf64("1p+1024", base.HEX)));
|
||||
assert(!(!chk64("0.00000000000001p-1022", base.HEX, 0.0)));
|
||||
};
|
||||
|
||||
@test fn stof32_hex() void = {
|
||||
if (!chk32("0p0", base.HEX, 0.0f32)) { fail(); };
|
||||
if (!chk32("1p0", base.HEX, 1.0f32)) { fail(); };
|
||||
if (!chk32("-1p0", base.HEX, -1.0f32)) { fail(); };
|
||||
if (!chk32("1.fp-2", base.HEX, 0.484375f32)) { fail(); };
|
||||
assert(!(!chk32("0p0", base.HEX, 0.0f32)));
|
||||
assert(!(!chk32("1p0", base.HEX, 1.0f32)));
|
||||
assert(!(!chk32("-1p0", base.HEX, -1.0f32)));
|
||||
assert(!(!chk32("1.fp-2", base.HEX, 0.484375f32)));
|
||||
// F32_MAX_NORMAL.
|
||||
if (!chk32("1.fffffd586b834p+127", base.HEX,
|
||||
math.f32frombits(0x7F7FFFFFu32))) { fail(); };
|
||||
math.f32frombits(0x7F7FFFFFu32))) { abort(); };
|
||||
// F32_MIN_NORMAL.
|
||||
if (!chk32("1.0p-126", base.HEX, math.f32frombits(0x00800000u32))) { fail(); };
|
||||
assert(!(!chk32("1.0p-126", base.HEX, math.f32frombits(0x00800000u32))));
|
||||
// F32_MIN_SUBNORMAL.
|
||||
if (!chk32("1.6p-150", base.HEX, math.f32frombits(0x00000001u32))) { fail(); };
|
||||
if (!ovf32("1.0p+128", base.HEX)) { fail(); };
|
||||
if (!chk32("1.0p-151", base.HEX, 0.0f32)) { fail(); };
|
||||
assert(!(!chk32("1.6p-150", base.HEX, math.f32frombits(0x00000001u32))));
|
||||
assert(!(!ovf32("1.0p+128", base.HEX)));
|
||||
assert(!(!chk32("1.0p-151", base.HEX, 0.0f32)));
|
||||
};
|
||||
|
||||
export fn main() i32 = {
|
||||
signalled = 1; stof64_dec();
|
||||
signalled = 2; stof32_dec();
|
||||
signalled = 3; stof64_hex();
|
||||
signalled = 4; stof32_hex();
|
||||
stof64_dec();
|
||||
stof32_dec();
|
||||
stof64_hex();
|
||||
stof32_hex();
|
||||
return 0;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user