nx_doe_test.nx source
↩ module page · 48 lines · 1725 B
1// nx_doe_test.nx -- smoke for nx_doe. Proves factorial run counts, the
2// coded sign matrix, grand mean, main + interaction effects, and dominant-
3// factor identification. Exit code = failed assertion number; 0 = pass.
4
5import "nx_syscalls.nx"
6import "nx_doe.nx"
7
8func main() -> i64 {
9 // --- run counts ---
10 if doe_num_runs(2) != 4 { return 1 }
11 if doe_num_runs(3) != 8 { return 2 }
12 if doe_num_runs(4) != 16 { return 3 }
13 if doe_frac_runs(5, 1) != 16 { return 4 }
14 if doe_frac_runs(5, 2) != 8 { return 5 }
15
16 // --- coded sign matrix (standard/Yates order) ---
17 if doe_sign(0, 0) != 0 - 1 { return 6 }
18 if doe_sign(1, 0) != 1 { return 7 }
19 if doe_sign(2, 1) != 1 { return 8 }
20 if doe_sign(0, 1) != 0 - 1 { return 9 }
21
22 // --- 2^2 design, responses y = [20, 40, 30, 52] ---
23 let y: *i64 = sys_mmap(64) as *i64
24 y[0] = 20
25 y[1] = 40
26 y[2] = 30
27 y[3] = 52
28 if doe_grand_mean(y, 4) != 35 { return 10 }
29 if doe_main_effect(y, 4, 0) != 21 { return 11 } // effect A
30 if doe_main_effect(y, 4, 1) != 11 { return 12 } // effect B
31 if doe_interaction_effect(y, 4, 0, 1) != 1 { return 13 } // AB
32 if doe_dominant_factor(y, 4, 2) != 0 { return 14 } // A dominates
33
34 // --- 2^3 design where only factor C (bit 2) drives the response ---
35 let z: *i64 = sys_mmap(128) as *i64
36 var i: i64 = 0
37 while i < 8 {
38 var v: i64 = 100
39 if ((i >> 2) & 1) == 1 { v = 110 }
40 z[i] = v
41 i = i + 1
42 }
43 if doe_main_effect(z, 8, 2) != 10 { return 15 } // C effect = 10
44 if doe_main_effect(z, 8, 0) != 0 { return 16 } // A has no effect
45 if doe_dominant_factor(z, 8, 3) != 2 { return 17 } // C dominates
46
47 return 0
48}