nx_jargon_test.nx source
↩ module page · 85 lines · 3429 B
1// nx_jargon_test.nx -- smoke for terminology-bridge primitive.
2
3import "syscalls.nx"
4import "nx_jargon.nx"
5
6func main() -> i64 {
7 let db: *JargonDb = nx_jargon_db_alloc()
8 let n: i64 = nx_jargon_seed_corpus(db)
9 // 12 concepts * 2 tiers each = 24 entries
10 if n != 24 { return 1 }
11 if db.n_entries != 24 { return 2 }
12
13 // === Lookup tests ===
14 // monoid BEGINNER
15 let idx_monoid_b: i64 = nx_jargon_lookup(db, "monoid" as *u8,
16 NX_DISC_MATH, NX_TIER_BEGINNER)
17 if idx_monoid_b < 0 { return 10 }
18
19 // monoid EXPERT
20 let idx_monoid_e: i64 = nx_jargon_lookup(db, "monoid" as *u8,
21 NX_DISC_MATH, NX_TIER_EXPERT)
22 if idx_monoid_e < 0 { return 11 }
23
24 // monoid INTERMEDIATE (not populated -> -1)
25 let idx_monoid_i: i64 = nx_jargon_lookup(db, "monoid" as *u8,
26 NX_DISC_MATH, NX_TIER_INTERMEDIATE)
27 if idx_monoid_i >= 0 { return 12 }
28
29 // === Audit: monoid has 2 tiers covered ===
30 let audit: i64 = nx_jargon_audit_tier_count(db, "monoid" as *u8, NX_DISC_MATH)
31 if audit != 2 { return 20 }
32
33 // === Discipline counts ===
34 // math: monoid + epsilon_delta + cauchy_schwarz + homeomorphism + group + manifold = 6 terms x 2 tiers = 12
35 let math_count: i64 = nx_jargon_count_by_discipline(db, NX_DISC_MATH)
36 if math_count != 12 { return 30 }
37 // stats: p_value + bias_variance = 2 x 2 = 4
38 let stats_count: i64 = nx_jargon_count_by_discipline(db, NX_DISC_STATS)
39 if stats_count != 4 { return 31 }
40 // cs: type + curry_howard + np_complete = 3 x 2 = 6
41 let cs_count: i64 = nx_jargon_count_by_discipline(db, NX_DISC_CS)
42 if cs_count != 6 { return 32 }
43 // physics: gauge = 1 x 2 = 2
44 let phys_count: i64 = nx_jargon_count_by_discipline(db, NX_DISC_PHYSICS)
45 if phys_count != 2 { return 33 }
46
47 // === Tier counts ===
48 // 12 BEGINNER + 12 EXPERT = 24
49 if nx_jargon_count_by_tier(db, NX_TIER_BEGINNER) != 12 { return 40 }
50 if nx_jargon_count_by_tier(db, NX_TIER_EXPERT) != 12 { return 41 }
51 if nx_jargon_count_by_tier(db, NX_TIER_INTERMEDIATE) != 0 { return 42 }
52
53 // === Explanation retrieval ===
54 let exp_b: *u8 = nx_jargon_explain(db, "homeomorphism" as *u8,
55 NX_DISC_MATH, NX_TIER_BEGINNER)
56 if exp_b == (0 as *u8) { return 50 }
57 // Beginner explanation should contain "coffee mug" or "donut".
58 var found_metaphor: i64 = 0
59 var i: i64 = 0
60 while i < 200 {
61 if exp_b[i] == 0 { i = 200 }
62 if exp_b[i] == 109 { // 'm' for "mug"
63 if exp_b[i + 1] == 117 { found_metaphor = 1 } // 'u'
64 }
65 if i < 200 { i = i + 1 }
66 }
67 if found_metaphor != 1 { return 51 }
68
69 // Unknown term returns null.
70 let unk: *u8 = nx_jargon_explain(db, "nonexistent_xyz" as *u8,
71 NX_DISC_MATH, NX_TIER_BEGINNER)
72 if unk != (0 as *u8) { return 60 }
73
74 // === Display a sample to stderr ===
75 sys_write(2, "BRIDGEWORK SAMPLE (homeomorphism, BEGINNER):\n " as *u8, 47)
76 var j: i64 = 0
77 while j < 256 {
78 if exp_b[j] == 0 { j = 256 }
79 if j < 256 { j = j + 1 }
80 }
81 sys_write(2, exp_b, j)
82 sys_write(2, "\n" as *u8, 1)
83
84 return 0
85}