nx_caplab_cities_test.nx source
↩ module page · 88 lines · 3912 B
1// nx_caplab_cities_test.nx -- gate for Capitalism Lab R6 (cities + the map).
2//
3// Proves: (1) a city's market scales with population, (2) per-city competition
4// splits that city's demand, (3) a firm's total = sum across cities, (4)
5// PRESENCE matters -- a firm absent from a city sells 0 there and a present
6// rival takes that demand, (5) expanding to a city raises your total reach,
7// (6) bigger city = more demand.
8
9import "nx_syscalls.nx"
10import "nx_runtime.nx"
11import "nx_tier.nx"
12import "nx_caplab_cities.nx"
13
14func nx_assert_eq(label: *u8, got: nx_int, want: nx_int, pass_n: *nx_int, fail_n: *nx_int) {
15 print(label); print(": got=" as *u8); print_i64(got); print(" want=" as *u8); print_i64(want)
16 if got == want { println(" PASS" as *u8); pass_n[0] = pass_n[0] + 1; return }
17 println(" FAIL" as *u8); fail_n[0] = fail_n[0] + 1
18}
19
20func nx_assert_gt(label: *u8, got: nx_int, floor: nx_int, pass_n: *nx_int, fail_n: *nx_int) {
21 print(label); print(": got=" as *u8); print_i64(got); print(" > " as *u8); print_i64(floor)
22 if got > floor { println(" PASS" as *u8); pass_n[0] = pass_n[0] + 1; return }
23 println(" FAIL" as *u8); fail_n[0] = fail_n[0] + 1
24}
25
26func mk2(a: nx_int, b: nx_int) -> *i64 {
27 let p: *i64 = (sys_mmap(16)) as *i64
28 p[0] = a
29 p[1] = b
30 return p
31}
32
33func main() -> nx_exit {
34 let pass_n: *nx_int = (sys_mmap(8)) as *nx_int
35 let fail_n: *nx_int = (sys_mmap(8)) as *nx_int
36 pass_n[0] = 0
37 fail_n[0] = 0
38 let wp: nx_int = 1
39 let wq: nx_int = 2
40 let wb: nx_int = 1
41 let choke: nx_int = 100
42
43 println("=== CAPLAB R6: cities + the map ===" as *u8)
44
45 let pr: *i64 = mk2(40, 60)
46 let ql: *i64 = mk2(0, 30)
47 let br: *i64 = mk2(0, 20)
48
49 // --- city sizes scale with population (base 60) ---
50 let metroM: nx_int = nx_clab_city_market_m(60, 200, 100)
51 let townM: nx_int = nx_clab_city_market_m(60, 50, 100)
52 nx_assert_eq("Metro market (pop 200) " as *u8, metroM, 120, pass_n, fail_n)
53 nx_assert_eq("Town market (pop 50) " as *u8, townM, 30, pass_n, fail_n)
54 nx_assert_gt("bigger city, more demand" as *u8, metroM, townM, pass_n, fail_n)
55
56 // --- both firms present in both cities ---
57 let capBoth: *i64 = mk2(100, 100)
58 let mSold: *i64 = mk2(0, 0)
59 nx_clab_city_run(2, pr, ql, br, choke, wp, wq, wb, metroM, capBoth, mSold)
60 nx_assert_eq("Metro: firm0 sold " as *u8, mSold[0], 40, pass_n, fail_n)
61 nx_assert_eq("Metro: firm1 sold " as *u8, mSold[1], 80, pass_n, fail_n)
62 let tSold: *i64 = mk2(0, 0)
63 nx_clab_city_run(2, pr, ql, br, choke, wp, wq, wb, townM, capBoth, tSold)
64 nx_assert_eq("Town: firm0 sold " as *u8, tSold[0], 10, pass_n, fail_n)
65 nx_assert_eq("Town: firm1 sold " as *u8, tSold[1], 20, pass_n, fail_n)
66
67 // --- geo totals: a firm's sales sum across the cities it serves ---
68 let f0: *i64 = mk2(mSold[0], tSold[0])
69 let f1: *i64 = mk2(mSold[1], tSold[1])
70 nx_assert_eq("firm0 total (both) " as *u8, nx_clab_geo_total(2, f0), 50, pass_n, fail_n)
71 nx_assert_eq("firm1 total (both) " as *u8, nx_clab_geo_total(2, f1), 100, pass_n, fail_n)
72
73 // --- PRESENCE: firm1 absent from Town -> sells 0; firm0 takes it all ---
74 let capF0only: *i64 = mk2(100, 0)
75 let tSold2: *i64 = mk2(0, 0)
76 nx_clab_city_run(2, pr, ql, br, choke, wp, wq, wb, townM, capF0only, tSold2)
77 nx_assert_eq("absent firm1 Town = 0 " as *u8, tSold2[1], 0, pass_n, fail_n)
78 nx_assert_eq("present firm0 takes all " as *u8, tSold2[0], 30, pass_n, fail_n)
79
80 // --- expanding to a city raises your reach (firm0: 50 in both vs 40 metro-only) ---
81 nx_assert_gt("expansion raises reach " as *u8, nx_clab_geo_total(2, f0), mSold[0], pass_n, fail_n)
82
83 println("" as *u8)
84 print("PASS=" as *u8); print_i64(pass_n[0])
85 print(" FAIL=" as *u8); print_i64(fail_n[0]); println("" as *u8)
86 if fail_n[0] > 0 { return 1 }
87 return 0
88}