Skip to content

Commit 9dfd26e

Browse files
committed
Updated test utils to enhance error handling for non-deterministic effects; added unit test for erroneous singleton evaluation.
Signed-off-by: Marvin Hansen <[email protected]>
1 parent 61d2670 commit 9dfd26e

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

deep_causality/src/utils_test/test_utils.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -144,16 +144,15 @@ pub fn get_test_causaloid_deterministic_input_output() -> BaseCausaloid {
144144
let description = "Inverts any input";
145145

146146
fn causal_fn(effect: &PropagatingEffect) -> Result<PropagatingEffect, CausalityError> {
147-
let obs =
148-
match effect {
149-
// If it's the Deterministic variant, extract the inner value.
150-
PropagatingEffect::Deterministic(val) => *val,
151-
// For any other type of effect, this function cannot proceed, so return an error.
152-
_ => return Err(CausalityError(
153-
"Causal function expected Numerical effect but received a different variant."
154-
.into(),
155-
)),
156-
};
147+
let obs = match effect {
148+
// If it's the Deterministic variant, extract the inner value.
149+
PropagatingEffect::Deterministic(val) => *val,
150+
// For any other type of effect, this function cannot proceed, so return an error.
151+
_ => return Err(CausalityError(
152+
"Causal function expected Deterministic effect but received a different variant."
153+
.into(),
154+
)),
155+
};
157156

158157
// Just invert the value.
159158
Ok(PropagatingEffect::Deterministic(!obs))

deep_causality/tests/types/causal_types/causaloid/causaloid_tests.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
use deep_causality::*;
77
use std::sync::Arc;
88

9-
use deep_causality::utils_test::test_utils::get_base_context;
9+
use deep_causality::utils_test::test_utils::{
10+
get_base_context, get_test_causaloid_deterministic_input_output,
11+
};
1012
use deep_causality::utils_test::*;
1113

1214
// Helper function to unpack numerical evidence, used in test causal functions.
@@ -415,6 +417,17 @@ fn test_evaluate_singleton_with_context() {
415417
assert_eq!(res_false, PropagatingEffect::Deterministic(false));
416418
}
417419

420+
#[test]
421+
fn test_evaluate_singleton_err() {
422+
let causaloid: BaseCausaloid = get_test_causaloid_deterministic_input_output();
423+
424+
// The causal function expects a Deterministic effect, but we pass in a Probabilistic effect.
425+
let effect = PropagatingEffect::Probabilistic(4.2);
426+
// The result should be an error.
427+
let res = causaloid.evaluate(&effect);
428+
assert!(res.is_err());
429+
}
430+
418431
#[test]
419432
fn test_evaluate_collection_other_effect_err() {
420433
// Setup: A collection with causaloids that have effects other than Deterministic or Halting.

0 commit comments

Comments
 (0)