Skip to content

Commit 07bd913

Browse files
committed
chore: M5 CI/Workflow Sweep - final synchronisation
1 parent a5d1eab commit 07bd913

4 files changed

Lines changed: 79 additions & 79 deletions

File tree

src/abi/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ mod tests {
447447

448448
#[test]
449449
fn test_normal_distribution_valid() {
450-
let d = Distribution::new_normal(0.0, 1.0).unwrap();
450+
let d = Distribution::new_normal(0.0, 1.0).expect("TODO: handle error");
451451
assert_eq!(d.kind(), "normal");
452452
assert_eq!(
453453
d,
@@ -466,7 +466,7 @@ mod tests {
466466

467467
#[test]
468468
fn test_uniform_distribution_valid() {
469-
let d = Distribution::new_uniform(0.0, 10.0).unwrap();
469+
let d = Distribution::new_uniform(0.0, 10.0).expect("TODO: handle error");
470470
assert_eq!(d.kind(), "uniform");
471471
}
472472

@@ -478,7 +478,7 @@ mod tests {
478478

479479
#[test]
480480
fn test_beta_distribution_valid() {
481-
let d = Distribution::new_beta(2.0, 5.0).unwrap();
481+
let d = Distribution::new_beta(2.0, 5.0).expect("TODO: handle error");
482482
assert_eq!(d.kind(), "beta");
483483
}
484484

@@ -490,7 +490,7 @@ mod tests {
490490

491491
#[test]
492492
fn test_bernoulli_distribution_valid() {
493-
let d = Distribution::new_bernoulli(0.5).unwrap();
493+
let d = Distribution::new_bernoulli(0.5).expect("TODO: handle error");
494494
assert_eq!(d.kind(), "bernoulli");
495495
}
496496

@@ -507,7 +507,7 @@ mod tests {
507507
#[test]
508508
fn test_custom_distribution_valid() {
509509
let d =
510-
Distribution::new_custom("mixture(0.5, normal(0,1), normal(5,2))".to_string()).unwrap();
510+
Distribution::new_custom("mixture(0.5, normal(0,1), normal(5,2))".to_string()).expect("TODO: handle error");
511511
assert_eq!(d.kind(), "custom");
512512
}
513513

@@ -639,7 +639,7 @@ mod tests {
639639

640640
#[test]
641641
fn test_confidence_interval_valid() {
642-
let ci = ConfidenceInterval::new(1.0, 5.0, 0.95).unwrap();
642+
let ci = ConfidenceInterval::new(1.0, 5.0, 0.95).expect("TODO: handle error");
643643
assert_eq!(ci.width(), 4.0);
644644
assert_eq!(ci.midpoint(), 3.0);
645645
assert!(ci.contains(3.0));
@@ -661,7 +661,7 @@ mod tests {
661661
#[test]
662662
fn test_confidence_interval_degenerate() {
663663
// A point interval (lower == upper) is valid.
664-
let ci = ConfidenceInterval::new(3.0, 3.0, 0.95).unwrap();
664+
let ci = ConfidenceInterval::new(3.0, 3.0, 0.95).expect("TODO: handle error");
665665
assert_eq!(ci.width(), 0.0);
666666
assert!(ci.contains(3.0));
667667
}

src/codegen/codegen.rs

Lines changed: 68 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -59,48 +59,48 @@ fn emit_header(code: &mut String, project_name: &str) {
5959
code,
6060
"// Generated by betlangiser — ternary probabilistic modelling"
6161
)
62-
.unwrap();
63-
writeln!(code, "// Project: {}", project_name).unwrap();
64-
writeln!(code, "// SPDX-License-Identifier: PMPL-1.0-or-later").unwrap();
65-
writeln!(code).unwrap();
66-
writeln!(code, "module {} where", sanitize_identifier(project_name)).unwrap();
67-
writeln!(code).unwrap();
62+
.expect("TODO: handle error");
63+
writeln!(code, "// Project: {}", project_name).expect("TODO: handle error");
64+
writeln!(code, "// SPDX-License-Identifier: PMPL-1.0-or-later").expect("TODO: handle error");
65+
writeln!(code).expect("TODO: handle error");
66+
writeln!(code, "module {} where", sanitize_identifier(project_name)).expect("TODO: handle error");
67+
writeln!(code).expect("TODO: handle error");
6868
}
6969

7070
/// Emit distribution declarations — each variable gets a `let` binding
7171
/// with its Betlang distribution constructor and type annotation.
7272
fn emit_distribution_declarations(code: &mut String, variables: &[ParsedVariable]) {
73-
writeln!(code, "// --- Distribution Declarations ---").unwrap();
74-
writeln!(code).unwrap();
73+
writeln!(code, "// --- Distribution Declarations ---").expect("TODO: handle error");
74+
writeln!(code).expect("TODO: handle error");
7575

7676
for var in variables {
7777
let info = distribution_info(&var.distribution);
7878
let btype = betlang_type(&var.distribution);
7979

80-
writeln!(code, "/// {} — {}", var.name, info.description).unwrap();
81-
writeln!(code, "/// Sampling method: {}", info.sampling_method).unwrap();
82-
writeln!(code, "/// Support: {}", info.support).unwrap();
80+
writeln!(code, "/// {} — {}", var.name, info.description).expect("TODO: handle error");
81+
writeln!(code, "/// Sampling method: {}", info.sampling_method).expect("TODO: handle error");
82+
writeln!(code, "/// Support: {}", info.support).expect("TODO: handle error");
8383
writeln!(
8484
code,
8585
"let {} : {} = {}",
8686
var.name, btype, info.betlang_constructor
8787
)
88-
.unwrap();
89-
writeln!(code).unwrap();
88+
.expect("TODO: handle error");
89+
writeln!(code).expect("TODO: handle error");
9090
}
9191
}
9292

9393
/// Emit propagation rule declarations — each variable is annotated with
9494
/// how arithmetic operations on it should propagate uncertainty.
9595
fn emit_propagation_rules(code: &mut String, variables: &[ParsedVariable]) {
96-
writeln!(code, "// --- Propagation Rules ---").unwrap();
97-
writeln!(code).unwrap();
96+
writeln!(code, "// --- Propagation Rules ---").expect("TODO: handle error");
97+
writeln!(code).expect("TODO: handle error");
9898

9999
for var in variables {
100100
let rule = propagation_rule(&var.distribution);
101-
writeln!(code, "@propagation({}, \"{}\")", var.name, rule).unwrap();
101+
writeln!(code, "@propagation({}, \"{}\")", var.name, rule).expect("TODO: handle error");
102102
}
103-
writeln!(code).unwrap();
103+
writeln!(code).expect("TODO: handle error");
104104
}
105105

106106
/// Emit ternary logic helper functions for Bernoulli variables.
@@ -109,32 +109,32 @@ fn emit_propagation_rules(code: &mut String, variables: &[ParsedVariable]) {
109109
/// - A ternary evaluation function that maps sampled proportions to Kleene truth values
110110
/// - AND/OR/NOT combinators for ternary logic chains
111111
fn emit_ternary_helpers(code: &mut String, variables: &[ParsedVariable]) {
112-
writeln!(code, "// --- Ternary Logic (Kleene Algebra) ---").unwrap();
113-
writeln!(code).unwrap();
114-
115-
writeln!(code, "/// Kleene strong three-valued AND").unwrap();
116-
writeln!(code, "let ternary_and(a: Ternary, b: Ternary) -> Ternary =").unwrap();
117-
writeln!(code, " match (a, b) with").unwrap();
118-
writeln!(code, " | (False, _) | (_, False) -> False").unwrap();
119-
writeln!(code, " | (True, True) -> True").unwrap();
120-
writeln!(code, " | _ -> Unknown").unwrap();
121-
writeln!(code).unwrap();
122-
123-
writeln!(code, "/// Kleene strong three-valued OR").unwrap();
124-
writeln!(code, "let ternary_or(a: Ternary, b: Ternary) -> Ternary =").unwrap();
125-
writeln!(code, " match (a, b) with").unwrap();
126-
writeln!(code, " | (True, _) | (_, True) -> True").unwrap();
127-
writeln!(code, " | (False, False) -> False").unwrap();
128-
writeln!(code, " | _ -> Unknown").unwrap();
129-
writeln!(code).unwrap();
130-
131-
writeln!(code, "/// Kleene strong three-valued NOT").unwrap();
132-
writeln!(code, "let ternary_not(a: Ternary) -> Ternary =").unwrap();
133-
writeln!(code, " match a with").unwrap();
134-
writeln!(code, " | True -> False").unwrap();
135-
writeln!(code, " | False -> True").unwrap();
136-
writeln!(code, " | Unknown -> Unknown").unwrap();
137-
writeln!(code).unwrap();
112+
writeln!(code, "// --- Ternary Logic (Kleene Algebra) ---").expect("TODO: handle error");
113+
writeln!(code).expect("TODO: handle error");
114+
115+
writeln!(code, "/// Kleene strong three-valued AND").expect("TODO: handle error");
116+
writeln!(code, "let ternary_and(a: Ternary, b: Ternary) -> Ternary =").expect("TODO: handle error");
117+
writeln!(code, " match (a, b) with").expect("TODO: handle error");
118+
writeln!(code, " | (False, _) | (_, False) -> False").expect("TODO: handle error");
119+
writeln!(code, " | (True, True) -> True").expect("TODO: handle error");
120+
writeln!(code, " | _ -> Unknown").expect("TODO: handle error");
121+
writeln!(code).expect("TODO: handle error");
122+
123+
writeln!(code, "/// Kleene strong three-valued OR").expect("TODO: handle error");
124+
writeln!(code, "let ternary_or(a: Ternary, b: Ternary) -> Ternary =").expect("TODO: handle error");
125+
writeln!(code, " match (a, b) with").expect("TODO: handle error");
126+
writeln!(code, " | (True, _) | (_, True) -> True").expect("TODO: handle error");
127+
writeln!(code, " | (False, False) -> False").expect("TODO: handle error");
128+
writeln!(code, " | _ -> Unknown").expect("TODO: handle error");
129+
writeln!(code).expect("TODO: handle error");
130+
131+
writeln!(code, "/// Kleene strong three-valued NOT").expect("TODO: handle error");
132+
writeln!(code, "let ternary_not(a: Ternary) -> Ternary =").expect("TODO: handle error");
133+
writeln!(code, " match a with").expect("TODO: handle error");
134+
writeln!(code, " | True -> False").expect("TODO: handle error");
135+
writeln!(code, " | False -> True").expect("TODO: handle error");
136+
writeln!(code, " | Unknown -> Unknown").expect("TODO: handle error");
137+
writeln!(code).expect("TODO: handle error");
138138

139139
// Per-variable ternary evaluators.
140140
for var in variables {
@@ -144,41 +144,41 @@ fn emit_ternary_helpers(code: &mut String, variables: &[ParsedVariable]) {
144144
"/// Evaluate '{}' as ternary: True if p >= 0.9, False if p <= 0.1, else Unknown",
145145
var.name
146146
)
147-
.unwrap();
147+
.expect("TODO: handle error");
148148
writeln!(
149149
code,
150150
"let {}_ternary(observed: Float) -> Ternary =",
151151
var.name
152152
)
153-
.unwrap();
154-
writeln!(code, " if observed >= 0.9 then True").unwrap();
155-
writeln!(code, " else if observed <= 0.1 then False").unwrap();
156-
writeln!(code, " else Unknown").unwrap();
157-
writeln!(code).unwrap();
153+
.expect("TODO: handle error");
154+
writeln!(code, " if observed >= 0.9 then True").expect("TODO: handle error");
155+
writeln!(code, " else if observed <= 0.1 then False").expect("TODO: handle error");
156+
writeln!(code, " else Unknown").expect("TODO: handle error");
157+
writeln!(code).expect("TODO: handle error");
158158
}
159159
}
160160
}
161161

162162
/// Emit the simulation configuration block.
163163
fn emit_simulation_config(code: &mut String, config: &AbiSimConfig) {
164-
writeln!(code, "// --- Simulation Configuration ---").unwrap();
165-
writeln!(code).unwrap();
166-
writeln!(code, "@config(samples = {})", config.samples).unwrap();
167-
writeln!(code, "@config(confidence = {})", config.confidence).unwrap();
164+
writeln!(code, "// --- Simulation Configuration ---").expect("TODO: handle error");
165+
writeln!(code).expect("TODO: handle error");
166+
writeln!(code, "@config(samples = {})", config.samples).expect("TODO: handle error");
167+
writeln!(code, "@config(confidence = {})", config.confidence).expect("TODO: handle error");
168168
if let Some(seed) = config.seed {
169-
writeln!(code, "@config(seed = {})", seed).unwrap();
169+
writeln!(code, "@config(seed = {})", seed).expect("TODO: handle error");
170170
}
171-
writeln!(code, "@config(output = \"{}\")", config.output_format).unwrap();
172-
writeln!(code).unwrap();
171+
writeln!(code, "@config(output = \"{}\")", config.output_format).expect("TODO: handle error");
172+
writeln!(code).expect("TODO: handle error");
173173
}
174174

175175
/// Emit the main `simulate` entry point that runs the Monte Carlo simulation.
176176
fn emit_entry_point(code: &mut String, variables: &[ParsedVariable], config: &AbiSimConfig) {
177-
writeln!(code, "// --- Entry Point ---").unwrap();
178-
writeln!(code).unwrap();
179-
writeln!(code, "/// Run the Monte Carlo simulation.").unwrap();
180-
writeln!(code, "let simulate() -> SimulationResults =").unwrap();
181-
writeln!(code, " let results = {{").unwrap();
177+
writeln!(code, "// --- Entry Point ---").expect("TODO: handle error");
178+
writeln!(code).expect("TODO: handle error");
179+
writeln!(code, "/// Run the Monte Carlo simulation.").expect("TODO: handle error");
180+
writeln!(code, "let simulate() -> SimulationResults =").expect("TODO: handle error");
181+
writeln!(code, " let results = {{").expect("TODO: handle error");
182182

183183
for var in variables {
184184
let info = distribution_info(&var.distribution);
@@ -187,11 +187,11 @@ fn emit_entry_point(code: &mut String, variables: &[ParsedVariable], config: &Ab
187187
" {}: sample({}, {}),",
188188
var.name, info.betlang_constructor, config.samples
189189
)
190-
.unwrap();
190+
.expect("TODO: handle error");
191191
}
192192

193-
writeln!(code, " }}").unwrap();
194-
writeln!(code, " report(results, confidence={})", config.confidence).unwrap();
193+
writeln!(code, " }}").expect("TODO: handle error");
194+
writeln!(code, " report(results, confidence={})", config.confidence).expect("TODO: handle error");
195195
}
196196

197197
/// Sanitize a project name into a valid Betlang module identifier.
@@ -266,7 +266,7 @@ mod tests {
266266
},
267267
];
268268
let m = make_manifest("risk-model", vars);
269-
let code = generate_betlang_code(&m).unwrap();
269+
let code = generate_betlang_code(&m).expect("TODO: handle error");
270270

271271
// Header present.
272272
assert!(code.contains("Generated by betlangiser"));
@@ -309,7 +309,7 @@ mod tests {
309309
expression: None,
310310
}];
311311
let m = make_manifest("no-bernoulli", vars);
312-
let code = generate_betlang_code(&m).unwrap();
312+
let code = generate_betlang_code(&m).expect("TODO: handle error");
313313

314314
// No ternary helpers when there are no Bernoulli variables.
315315
assert!(!code.contains("ternary_and"));
@@ -390,7 +390,7 @@ mod tests {
390390
},
391391
];
392392
let m = make_manifest("all-dists", vars);
393-
let code = generate_betlang_code(&m).unwrap();
393+
let code = generate_betlang_code(&m).expect("TODO: handle error");
394394

395395
// All five variables declared.
396396
assert!(code.contains("let a :"));
@@ -416,7 +416,7 @@ mod tests {
416416
}];
417417
let mut m = make_manifest("seeded", vars);
418418
m.simulation.seed = Some(42);
419-
let code = generate_betlang_code(&m).unwrap();
419+
let code = generate_betlang_code(&m).expect("TODO: handle error");
420420
assert!(code.contains("@config(seed = 42)"));
421421
}
422422
}

src/codegen/parser.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ mod tests {
138138
expression: None,
139139
};
140140
let m = make_manifest(var);
141-
let parsed = parse_variables(&m).unwrap();
141+
let parsed = parse_variables(&m).expect("TODO: handle error");
142142
assert_eq!(parsed.len(), 1);
143143
assert_eq!(parsed[0].name, "price");
144144
assert_eq!(parsed[0].distribution.kind(), "normal");
@@ -216,7 +216,7 @@ mod tests {
216216
variables: vars,
217217
simulation: SimulationConfig::default(),
218218
};
219-
let parsed = parse_variables(&m).unwrap();
219+
let parsed = parse_variables(&m).expect("TODO: handle error");
220220
assert_eq!(parsed.len(), 5);
221221
assert_eq!(parsed[0].distribution.kind(), "normal");
222222
assert_eq!(parsed[1].distribution.kind(), "uniform");

src/manifest/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ samples = 1000
414414
confidence = 0.90
415415
output-format = "json"
416416
"#;
417-
let m: Manifest = toml::from_str(toml_str).unwrap();
417+
let m: Manifest = toml::from_str(toml_str).expect("TODO: handle error");
418418
assert!(validate(&m).is_ok());
419419
assert_eq!(m.project.name, "test-model");
420420
assert_eq!(m.variables.len(), 1);
@@ -435,7 +435,7 @@ distribution = "normal"
435435
mean = 0.0
436436
std-dev = 1.0
437437
"#;
438-
let m: Manifest = toml::from_str(toml_str).unwrap();
438+
let m: Manifest = toml::from_str(toml_str).expect("TODO: handle error");
439439
assert!(validate(&m).is_err());
440440
}
441441

0 commit comments

Comments
 (0)