Skip to content

Commit d81c53d

Browse files
committed
Add empty collection validation in smoking example.
Signed-off-by: Marvin Hansen <[email protected]>
1 parent 195131b commit d81c53d

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

examples/smoking/src/run.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,22 @@ fn reason_causal_chain(
8888
causes: &BaseCausaloidVec,
8989
data: &[NumericalValue],
9090
) -> Result<bool, CausalityError> {
91+
if causes.is_empty() {
92+
return Err(CausalityError(
93+
"Cannot reason over empty causal chain.".into(),
94+
));
95+
}
96+
if data.is_empty() {
97+
return Err(CausalityError("Cannot reason with empty data.".into()));
98+
}
99+
if causes.len() != data.len() {
100+
return Err(CausalityError(format!(
101+
"Mismatch between number of causes ({}) and data points ({}).",
102+
causes.len(),
103+
data.len()
104+
)));
105+
}
106+
91107
if causes.len() != data.len() {
92108
return Err(CausalityError(format!(
93109
"Mismatch between number of causes ({}) and data points ({}).",

0 commit comments

Comments
 (0)