Files
ww/lib/time/arithm_test.ww
Hojun-Cho cec382ef8a lib: split time_test into duration/instant/arithm tests per ref/hare/time
Mirror ref/hare/time's impl layout in the test siblings: constants ->
duration_test.ww (ref/hare/time/duration.ha:9-18 owns the constants);
now/sleep rows -> instant_test.ww (instant is the subject type,
ref/hare/time/instant.ha; now/sleep bodies live in
ref/hare/time/+linux/functions.ha, a platform split ww does not have);
add/diff/compare rows -> arithm_test.ww (ref/hare/time/arithm.ha).

Pure move: every @test block is byte-identical; only the section
banner lines are deleted (the file names now carry them). The stale
file header naming the retired `ww run lib/time/timetest.ww` entry
point is dropped, not relocated (rule 8: it described a WHAT that no
longer exists).

Consumers: Makefile LIBRARY_TESTS entry replaced in place;
test/byteid roster 44->46 (+2).
2026-08-08 17:19:14 +09:00

92 lines
2.3 KiB
Plaintext

package time_test;
import time;
@test fn addzero() void = {
let a: time.instant;
a.sec = 100i64; a.nsec = 500i64;
let r = time.add(a, 0i64);
assert(!(r.sec != 100i64));
assert(!(r.nsec != 500i64));
};
@test fn addpos_nocarry() void = {
let a: time.instant;
a.sec = 10i64; a.nsec = 100i64;
let r = time.add(a, 200i64);
assert(!(r.sec != 10i64));
assert(!(r.nsec != 300i64));
};
@test fn addpos_carry() void = {
let a: time.instant;
a.sec = 10i64; a.nsec = 999999900i64;
let r = time.add(a, 200i64);
assert(!(r.sec != 11i64));
assert(!(r.nsec != 100i64));
};
@test fn addpos_fullsecond() void = {
let a: time.instant;
a.sec = 5i64; a.nsec = 0i64;
let r = time.add(a, (time.second: i64) * 3i64);
assert(!(r.sec != 8i64));
assert(!(r.nsec != 0i64));
};
@test fn addneg_noborrow() void = {
let a: time.instant;
a.sec = 10i64; a.nsec = 500i64;
let r = time.add(a, -100i64);
assert(!(r.sec != 10i64));
assert(!(r.nsec != 400i64));
};
@test fn addneg_borrow() void = {
let a: time.instant;
a.sec = 10i64; a.nsec = 100i64;
let r = time.add(a, -200i64);
assert(!(r.sec != 9i64));
assert(!(r.nsec != 999999900i64));
};
@test fn diffsimple() void = {
let a: time.instant; a.sec = 10i64; a.nsec = 100i64;
let b: time.instant; b.sec = 12i64; b.nsec = 300i64;
let d: i64 = time.diff(a, b): i64;
// b - a = 2.0000002 sec = 2_000_000_200 ns
assert(!(d != 2000000200i64));
};
@test fn diffneg() void = {
let a: time.instant; a.sec = 12i64; a.nsec = 300i64;
let b: time.instant; b.sec = 10i64; b.nsec = 100i64;
let d: i64 = time.diff(a, b): i64;
assert(!(d != -2000000200i64));
};
@test fn comparelt() void = {
let a: time.instant; a.sec = 1i64; a.nsec = 0i64;
let b: time.instant; b.sec = 2i64; b.nsec = 0i64;
assert(!(time.compare(a, b) != -1i8));
};
@test fn comparegt() void = {
let a: time.instant; a.sec = 2i64; a.nsec = 0i64;
let b: time.instant; b.sec = 1i64; b.nsec = 0i64;
assert(!(time.compare(a, b) != 1i8));
};
@test fn compareeq() void = {
let a: time.instant; a.sec = 5i64; a.nsec = 42i64;
let b: time.instant; b.sec = 5i64; b.nsec = 42i64;
assert(!(time.compare(a, b) != 0i8));
};
@test fn comparensec_only() void = {
let a: time.instant; a.sec = 5i64; a.nsec = 100i64;
let b: time.instant; b.sec = 5i64; b.nsec = 200i64;
assert(!(time.compare(a, b) != -1i8));
assert(!(time.compare(b, a) != 1i8));
};