File tree Expand file tree Collapse file tree 2 files changed +23
-11
lines changed
tests/types/causal_types/causaloid Expand file tree Collapse file tree 2 files changed +23
-11
lines changed Original file line number Diff line number Diff 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) )
Original file line number Diff line number Diff line change 66use deep_causality:: * ;
77use 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+ } ;
1012use 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]
419432fn test_evaluate_collection_other_effect_err ( ) {
420433 // Setup: A collection with causaloids that have effects other than Deterministic or Halting.
You can’t perform that action at this time.
0 commit comments