52 lines
1.4 KiB
Plaintext
52 lines
1.4 KiB
Plaintext
package crc16_test;
|
|
|
|
import hash.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);
|
|
};
|