nx_decl_random_environment_test.nx source
↩ module page · 85 lines · 3875 B
1// nx_decl_random_environment_test.nx -- smoke for the first
2// declarative #tag-style primitive.
3//
4// expect_exit: 0
5//
6// license_tier: ORIGINAL
7
8import "nx_syscalls.nx"
9import "nx_types.nx"
10import "nx_tier.nx"
11import "nx_biome_classifier.nx"
12import "nx_decl_random_environment.nx"
13
14func main() -> nx_int {
15 // ---- Test 1: validity predicate --------------------------------
16 if nx_re_modifier_is_valid(NX_RE_MODIFIER_REAL) != 1 { return 1 }
17 if nx_re_modifier_is_valid(NX_RE_MODIFIER_FANTASY) != 1 { return 2 }
18 if nx_re_modifier_is_valid(NX_RE_MODIFIER_SCI_FI) != 1 { return 3 }
19 if nx_re_modifier_is_valid(NX_RE_MODIFIER_N) != 0 { return 4 }
20 if nx_re_modifier_is_valid(-1) != 0 { return 5 }
21
22 // ---- Test 2: REAL modifier produces valid struct --------------
23 let env: *NxRandomEnvironment = nx_re_alloc()
24 nx_decl_random_environment(env, NX_RE_MODIFIER_REAL, 0xC0FFEE)
25 if env.is_valid != 1 { return 10 }
26 if env.size_tiles != 256 { return 11 }
27 if env.modifier != NX_RE_MODIFIER_REAL { return 12 }
28 if nx_biome_is_valid(env.biome) != 1 { return 13 }
29 if env.river_count < 0 { return 14 }
30 if env.forest_count < 0 { return 15 }
31 if env.decoration_density < 0 { return 16 }
32 if env.decoration_density > 1024 { return 17 }
33 if env.elevation_max_m < 0 { return 18 }
34
35 // ---- Test 3: FANTASY scales up --------------------------------
36 let env2: *NxRandomEnvironment = nx_re_alloc()
37 nx_decl_random_environment(env2, NX_RE_MODIFIER_FANTASY, 0xC0FFEE)
38 if env2.size_tiles != 512 { return 20 }
39 if env2.modifier != NX_RE_MODIFIER_FANTASY { return 21 }
40
41 // ---- Test 4: SCI_FI scales up further -------------------------
42 let env3: *NxRandomEnvironment = nx_re_alloc()
43 nx_decl_random_environment(env3, NX_RE_MODIFIER_SCI_FI, 0xC0FFEE)
44 if env3.size_tiles != 1024 { return 30 }
45
46 // ---- Test 5: determinism (same seed -> same struct) -----------
47 let env_a: *NxRandomEnvironment = nx_re_alloc()
48 let env_b: *NxRandomEnvironment = nx_re_alloc()
49 nx_decl_random_environment(env_a, NX_RE_MODIFIER_REAL, 42)
50 nx_decl_random_environment(env_b, NX_RE_MODIFIER_REAL, 42)
51 if env_a.biome != env_b.biome { return 40 }
52 if env_a.river_count != env_b.river_count { return 41 }
53 if env_a.forest_count != env_b.forest_count { return 42 }
54 if env_a.settlement_present != env_b.settlement_present { return 43 }
55
56 // ---- Test 6: different seeds -> different biomes (likely) -----
57 let env_c: *NxRandomEnvironment = nx_re_alloc()
58 let env_d: *NxRandomEnvironment = nx_re_alloc()
59 nx_decl_random_environment(env_c, NX_RE_MODIFIER_REAL, 100)
60 nx_decl_random_environment(env_d, NX_RE_MODIFIER_REAL, 200)
61 // Either biomes differ OR feature counts differ. Not guaranteed
62 // 100% but very likely with Knuth-hash spreading.
63 var differ: nx_int = 0
64 if env_c.biome != env_d.biome { differ = 1 }
65 if env_c.river_count != env_d.river_count { differ = 1 }
66 if env_c.forest_count != env_d.forest_count { differ = 1 }
67 if differ != 1 { return 50 }
68
69 // ---- Test 7: invalid modifier sets is_valid=0 -----------------
70 let env_bad: *NxRandomEnvironment = nx_re_alloc()
71 nx_decl_random_environment(env_bad, 999, 0)
72 if env_bad.is_valid != 0 { return 60 }
73
74 // ---- Test 8: desert biome zeros river+forest ------------------
75 // Construct manually: bypass hash by writing biome then calling
76 // the helper APIs directly.
77 var rc: nx_int = 0
78 rc = _re_default_river_count(NX_RE_MODIFIER_REAL, NX_BIOME_DESERT)
79 if rc != 0 { return 70 }
80 var fc: nx_int = 0
81 fc = _re_default_forest_count(NX_RE_MODIFIER_REAL, NX_BIOME_DESERT)
82 if fc != 0 { return 71 }
83
84 return 0
85}