@@ -303,6 +303,66 @@ fn eval_single_state_error_non_deter() {
303303 let csm = CSM :: new ( state_action) ;
304304
305305 let data = test_utils:: get_test_single_data ( 0.23f64 ) ;
306- let res = csm. eval_single_state ( 23 , data) ;
306+ let res = csm. eval_single_state ( id , data) ;
307307 assert ! ( res. is_err( ) )
308308}
309+
310+ #[ test]
311+ fn eval_single_state_success_fires_action ( ) {
312+ let id = 42 ;
313+ let version = 1 ;
314+ let data = Evidence :: Numerical ( 0.23f64 ) ;
315+ let causaloid = test_utils:: get_test_causaloid ( ) ; // Returns Deterministic(true)
316+
317+ let cs = CausalState :: new ( id, version, data, causaloid) ;
318+ let ca = get_test_action ( ) ; // Succeeds
319+ let state_action = & [ ( & cs, & ca) ] ;
320+ let csm = CSM :: new ( state_action) ;
321+
322+ // Data that makes the state active
323+ let eval_data = test_utils:: get_test_single_data ( 0.23f64 ) ;
324+ // Use the correct ID
325+ let res = csm. eval_single_state ( id, eval_data) ;
326+ assert ! ( res. is_ok( ) ) ;
327+ }
328+
329+ // Test for the case where the state is not active, so the action is not fired.
330+ #[ test]
331+ fn eval_single_state_success_inactive_no_action ( ) {
332+ let id = 42 ;
333+ let version = 1 ;
334+ let data = Evidence :: Numerical ( 0.88f64 ) ;
335+ let causaloid = test_utils:: get_test_causaloid ( ) ; // Returns Deterministic(false) for data > 0.5
336+
337+ let cs = CausalState :: new ( id, version, data, causaloid) ;
338+ // Use an action that would fail to prove it's not being called.
339+ let ca = get_test_error_action ( ) ;
340+ let state_action = & [ ( & cs, & ca) ] ;
341+ let csm = CSM :: new ( state_action) ;
342+
343+ // Data that makes the state inactive
344+ let eval_data = test_utils:: get_test_single_data ( 0.88f64 ) ;
345+ // Use the correct ID
346+ let res = csm. eval_single_state ( id, eval_data) ;
347+ assert ! ( res. is_err( ) ) ;
348+ }
349+
350+ // Test for the case where the state does not exist.
351+ #[ test]
352+ fn eval_single_state_error_not_found ( ) {
353+ let id = 42 ;
354+ let version = 1 ;
355+ let data = Evidence :: Numerical ( 0.23f64 ) ;
356+ let causaloid = test_utils:: get_test_causaloid ( ) ;
357+
358+ let cs = CausalState :: new ( id, version, data, causaloid) ;
359+ let ca = get_test_action ( ) ;
360+ let state_action = & [ ( & cs, & ca) ] ;
361+ let csm = CSM :: new ( state_action) ;
362+
363+ let eval_data = test_utils:: get_test_single_data ( 0.23f64 ) ;
364+ // Use a non-existent ID
365+ let res = csm. eval_single_state ( 99 , eval_data) ;
366+ assert ! ( res. is_err( ) ) ;
367+ assert ! ( res. unwrap_err( ) . 0 . contains( "State 99 does not exist" ) ) ;
368+ }
0 commit comments