Files
ww/lib/hash/crc16/crc16_test.ww
Hojun-Cho 2338ea5d59 ww: lib tests run via -T test mode; bare mains retired (closes @test conversion)
'ww test' gains the istest build path (-T injection in build_one/
buildone) and do_test/dotest accept -I, mirroring do_run - both twins.
The 35 converted lib tests drop their interim bare mains (-T
synthesizes the entry from @test fns and rejects a user main); their
35 C run-drivers flip 'ww run' -> 'ww test'; 989_lib_byteid compiles
lib tests under -T (8 user-main probe fixtures stay non-T, gated on
the fixture field). Abort-on-first-failure stands until the deferred
record-and-continue harness lands with the multi-package arc.
2026-06-10 20:45:46 +09:00

52 lines
1.4 KiB
Plaintext

package crc16_test;
import crc16;
fn putstr(s: str, into: []u8, off: i32) i32 = {
let i: i32 = 0;
for (i < s.len) {
into[off + i] = s[i];
i += 1;
};
return off + s.len;
};
fn check(s: str, ccitt: u16, cmda: u16, dect: u16, ansi: u16) void = {
let arr: [256]u8;
let n: i32 = putstr(s, arr[0:256], 0);
let buf: []u8 = arr[0:n];
assert(!(crc16.sum16ccitt(buf) != ccitt));
assert(!(crc16.sum16cmda2000(buf) != cmda));
assert(!(crc16.sum16dect(buf) != dect));
assert(!(crc16.sum16ansi(buf) != ansi));
};
@test fn vec_empty() void = {
let arr: [1]u8;
let buf: []u8 = arr[0:0];
assert(!(crc16.sum16ccitt(buf) != 0u16));
assert(!(crc16.sum16cmda2000(buf) != 0u16));
assert(!(crc16.sum16dect(buf) != 0u16));
assert(!(crc16.sum16ansi(buf) != 0u16));
};
@test fn vec_truman() void = {
check("Always be sincere, even if you don't mean it. -- Harry Truman",
0x38DFu16, 0x2441u16, 0x8E44u16, 0xEF5Eu16);
};
@test fn vec_animals() void = {
check("You get along very well with everyone except animals and people.",
0xB6AEu16, 0xFED0u16, 0x8739u16, 0xCF56u16);
};
@test fn vec_twain() void = {
check("All generalizations are false, including this one. -- Mark Twain",
0xCA68u16, 0x65ECu16, 0x098Au16, 0x45B4u16);
};
@test fn vec_peace() void = {
check("I want peace and I'm willing to fight for it. -- Harry Truman",
0xB0E8u16, 0xFE1Fu16, 0x4659u16, 0x5062u16);
};