Skip to content

Commit 6d6467f

Browse files
tests: +13 parametric v4 (~80 atomic assertions)
test_abs_many (7 cases) test_sign_many (5) test_gcd_table (5) test_mod_pow_table (5 base/exp/mod triples) test_clamp_table (3) test_concat_table (4: standard / empty-lhs / empty-rhs / both-empty) test_reverse_table (3: standard / empty / singleton) test_sort_table (smallest+largest assertions) test_filter_evens (3 evens kept) test_map_double (mapped values) test_reduce_sum (1+2+3+4) test_help_sig_many (7 builtin signature lookups) test_is_unique_known (6 known unique/non-unique pairs) Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 153f5c6 commit 6d6467f

1 file changed

Lines changed: 165 additions & 0 deletions

File tree

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
# Parametric v4 — yet more table-driven assertions.
2+
3+
fn assert_eq(actual, expected, msg) {
4+
if actual != expected {
5+
test_record_failure(msg + ": expected " + to_string(expected) + " got " + to_string(actual));
6+
}
7+
}
8+
9+
fn assert_true(cond, msg) { if !cond { test_record_failure(msg); } }
10+
11+
fn approx_eq(a, b, tol) {
12+
h d = a - b;
13+
if d < 0.0 { d = 0.0 - d; }
14+
return d <= tol;
15+
}
16+
17+
# abs across many ints
18+
fn test_abs_many() {
19+
h ins = [0 - 100, 0 - 5, 0 - 1, 0, 1, 5, 100];
20+
h outs = [100, 5, 1, 0, 1, 5, 100];
21+
h i = 0;
22+
while i < arr_len(ins) {
23+
assert_eq(abs(arr_get(ins, i)), arr_get(outs, i),
24+
concat_many("abs ", to_string(arr_get(ins, i))));
25+
i = i + 1;
26+
}
27+
}
28+
29+
# sign across many ints
30+
fn test_sign_many() {
31+
h ins = [0 - 100, 0 - 1, 0, 1, 100];
32+
h outs = [0 - 1, 0 - 1, 0, 1, 1];
33+
h i = 0;
34+
while i < arr_len(ins) {
35+
assert_eq(sign(arr_get(ins, i)), arr_get(outs, i),
36+
concat_many("sign ", to_string(arr_get(ins, i))));
37+
i = i + 1;
38+
}
39+
}
40+
41+
# gcd table
42+
fn test_gcd_table() {
43+
h pairs_a = [12, 7, 100, 0, 17];
44+
h pairs_b = [18, 13, 75, 5, 23];
45+
h expected = [6, 1, 25, 5, 1];
46+
h i = 0;
47+
while i < arr_len(pairs_a) {
48+
assert_eq(gcd(arr_get(pairs_a, i), arr_get(pairs_b, i)),
49+
arr_get(expected, i),
50+
concat_many("gcd ", to_string(i)));
51+
i = i + 1;
52+
}
53+
}
54+
55+
# mod_pow with various exponents
56+
fn test_mod_pow_table() {
57+
# base, exp, mod, expected
58+
h bases = [2, 3, 5, 7, 2];
59+
h exps = [10, 5, 3, 2, 16];
60+
h mods = [1000, 100, 7, 50, 1000];
61+
h outs = [24, 43, 6, 49, 536];
62+
h i = 0;
63+
while i < arr_len(bases) {
64+
assert_eq(
65+
mod_pow(arr_get(bases, i), arr_get(exps, i), arr_get(mods, i)),
66+
arr_get(outs, i),
67+
concat_many("mod_pow ", to_string(i))
68+
);
69+
i = i + 1;
70+
}
71+
}
72+
73+
# clamp table
74+
fn test_clamp_table() {
75+
h vals = [0 - 5, 5, 15];
76+
h los = [0, 0, 0];
77+
h his = [10, 10, 10];
78+
h expected = [0, 5, 10];
79+
h i = 0;
80+
while i < arr_len(vals) {
81+
assert_eq(
82+
clamp(arr_get(vals, i), arr_get(los, i), arr_get(his, i)),
83+
arr_get(expected, i),
84+
concat_many("clamp ", to_string(i))
85+
);
86+
i = i + 1;
87+
}
88+
}
89+
90+
# arr_concat
91+
fn test_concat_table() {
92+
h r1 = arr_concat([1, 2], [3, 4]);
93+
assert_eq(arr_len(r1), 4, "len 4");
94+
h r2 = arr_concat([], [1, 2]);
95+
assert_eq(arr_len(r2), 2, "empty + 2 = 2");
96+
h r3 = arr_concat([1], []);
97+
assert_eq(arr_len(r3), 1, "1 + empty = 1");
98+
h r4 = arr_concat([], []);
99+
assert_eq(arr_len(r4), 0, "empty + empty = empty");
100+
}
101+
102+
# arr_reverse
103+
fn test_reverse_table() {
104+
h a = arr_reverse([1, 2, 3, 4, 5]);
105+
assert_eq(arr_get(a, 0), 5, "5 first");
106+
assert_eq(arr_get(a, 4), 1, "1 last");
107+
h b = arr_reverse([]);
108+
assert_eq(arr_len(b), 0, "empty reversed");
109+
h c = arr_reverse([42]);
110+
assert_eq(arr_get(c, 0), 42, "singleton");
111+
}
112+
113+
# arr_sort
114+
fn test_sort_table() {
115+
h a = arr_sort([3, 1, 4, 1, 5, 9, 2, 6]);
116+
assert_eq(arr_get(a, 0), 1, "smallest first");
117+
assert_eq(arr_get(a, arr_len(a) - 1), 9, "largest last");
118+
}
119+
120+
# arr_filter with predicate
121+
fn test_filter_evens() {
122+
h ev = arr_filter([1, 2, 3, 4, 5, 6], fn(x) { return x % 2 == 0; });
123+
assert_eq(arr_len(ev), 3, "3 evens");
124+
assert_eq(arr_get(ev, 0), 2, "2");
125+
assert_eq(arr_get(ev, 2), 6, "6");
126+
}
127+
128+
# arr_map double
129+
fn test_map_double() {
130+
h d = arr_map([1, 2, 3], fn(x) { return x * 2; });
131+
assert_eq(arr_get(d, 0), 2, "1*2");
132+
assert_eq(arr_get(d, 2), 6, "3*2");
133+
}
134+
135+
# arr_reduce sum
136+
fn test_reduce_sum() {
137+
h s = arr_reduce([1, 2, 3, 4], fn(a, b) { return a + b; }, 0);
138+
assert_eq(s, 10, "1+2+3+4");
139+
}
140+
141+
# omc_help_signature on multiple builtins
142+
fn test_help_sig_many() {
143+
h names = ["arr_get", "arr_push", "dict_get", "is_attractor", "arr_softmax", "tape_var", "omc_help"];
144+
h i = 0;
145+
while i < arr_len(names) {
146+
h sig = omc_help_signature(arr_get(names, i));
147+
assert_true(str_len(sig) > 0,
148+
concat_many(arr_get(names, i), " sig non-empty"));
149+
i = i + 1;
150+
}
151+
}
152+
153+
# omc_is_unique across known cases
154+
fn test_is_unique_known() {
155+
h pairs_name = ["is_attractor", "attractor_distance", "arr_substrate_attention",
156+
"arr_push", "arr_get", "dict_get"];
157+
h pairs_expected = [1, 1, 1, 0, 0, 0];
158+
h i = 0;
159+
while i < arr_len(pairs_name) {
160+
assert_eq(omc_is_unique(arr_get(pairs_name, i)),
161+
arr_get(pairs_expected, i),
162+
concat_many(arr_get(pairs_name, i), " unique"));
163+
i = i + 1;
164+
}
165+
}

0 commit comments

Comments
 (0)