Skip to content

Commit 4458b71

Browse files
committed
More Linting and formatting
Signed-off-by: Marvin Hansen <[email protected]>
1 parent 69a6bf5 commit 4458b71

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

deep_causality_uncertain/src/types/sampler/sequential_sampler.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ impl Sampler for SequentialSampler {
3131
fn sample(&self, root_node: &Arc<ComputationNode>) -> Result<SampledValue, UncertainError> {
3232
let mut context: HashMap<*const ComputationNode, SampledValue> = HashMap::new();
3333
// Call the internal method.
34-
self.evaluate_node(root_node, &mut context, &mut rand::rng())
34+
let mut rng = rand::rng();
35+
self.evaluate_node(root_node, &mut context, &mut rng)
3536
}
3637
}
3738

@@ -104,19 +105,30 @@ impl SequentialSampler {
104105
for operand_node in operands {
105106
match self.evaluate_node(operand_node, context, rng)? {
106107
SampledValue::Bool(b) => vals.push(b),
107-
_ => return Err(UncertainError::TypeError("Logical op requires boolean inputs".into())),
108+
_ => {
109+
return Err(UncertainError::UnsupportedTypeError(
110+
"Logical op requires boolean inputs".into(),
111+
));
112+
}
108113
}
109114
}
110115
let result = match op {
111116
LogicalOperator::Not => {
112117
if vals.len() != 1 {
113-
return Err(UncertainError::TypeError("NOT expects exactly 1 operand".into()));
118+
return Err(UncertainError::UnsupportedTypeError(
119+
"NOT expects exactly 1 operand".into(),
120+
));
114121
}
115122
!vals[0]
116123
}
117-
LogicalOperator::And | LogicalOperator::Or | LogicalOperator::NOR | LogicalOperator::XOR => {
124+
LogicalOperator::And
125+
| LogicalOperator::Or
126+
| LogicalOperator::NOR
127+
| LogicalOperator::XOR => {
118128
if vals.len() != 2 {
119-
return Err(UncertainError::TypeError("Binary logical op expects exactly 2 operands".into()));
129+
return Err(UncertainError::UnsupportedTypeError(
130+
"Binary logical op expects exactly 2 operands".into(),
131+
));
120132
}
121133
match op {
122134
LogicalOperator::And => vals[0] && vals[1],

deep_causality_uncertain/tests/types/sampler/sequential_sampler_tests.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ fn test_sequential_sampler_logical_op_and() {
101101
}
102102

103103
#[test]
104-
#[should_panic(expected = "Type error: Logical op requires boolean inputs")]
105104
fn test_sequential_sampler_logical_op_type_error() {
106105
let sampler = SequentialSampler;
107106
let op1 = Arc::new(ComputationNode::LeafF64(DistributionEnum::Point(1.0))); // Type mismatch
@@ -110,7 +109,13 @@ fn test_sequential_sampler_logical_op_type_error() {
110109
op: LogicalOperator::And,
111110
operands: vec![Box::new((*op1).clone()), Box::new((*op2).clone())],
112111
});
113-
let _ = sampler.sample(&root_node).unwrap();
112+
let res = sampler.sample(&root_node);
113+
dbg!(&res);
114+
assert!(res.is_err());
115+
match res.err().unwrap() {
116+
UncertainError::UnsupportedTypeError(_) => (),
117+
_ => panic!("Expected UnsupportedTypeError"),
118+
}
114119
}
115120

116121
#[test]

0 commit comments

Comments
 (0)