Skip to content

Commit 2ee0195

Browse files
committed
Improved test coverage; renamed for simpler name convention.
Signed-off-by: Marvin Hansen <[email protected]>
1 parent 29b9f1d commit 2ee0195

File tree

10 files changed

+124
-82
lines changed

10 files changed

+124
-82
lines changed

deep_causality/benches/benchmarks/bench_collection.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fn small_causality_collection_benchmark(criterion: &mut Criterion) {
2020

2121
criterion.bench_function("small_causality_collection_propagation", |bencher| {
2222
bencher.iter(|| {
23-
coll.evaluate_deterministic_propagation(&evidence, &AggregateLogic::All)
23+
coll.evaluate_deterministic(&evidence, &AggregateLogic::All)
2424
.unwrap()
2525
})
2626
});
@@ -32,7 +32,7 @@ fn medium_causality_collection_benchmark(criterion: &mut Criterion) {
3232

3333
criterion.bench_function("medium_causality_collection_propagation", |bencher| {
3434
bencher.iter(|| {
35-
coll.evaluate_deterministic_propagation(&evidence, &AggregateLogic::All)
35+
coll.evaluate_deterministic(&evidence, &AggregateLogic::All)
3636
.unwrap()
3737
})
3838
});
@@ -44,7 +44,7 @@ fn large_causality_collection_benchmark(criterion: &mut Criterion) {
4444

4545
criterion.bench_function("large_causality_collection_propagation", |bencher| {
4646
bencher.iter(|| {
47-
coll.evaluate_deterministic_propagation(&evidence, &AggregateLogic::All)
47+
coll.evaluate_deterministic(&evidence, &AggregateLogic::All)
4848
.unwrap()
4949
})
5050
});

deep_causality/src/traits/causable/causable_reasoning.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ where
6060
///
6161
/// # Errors
6262
/// Returns a `CausalityError` if any `Causable` item returns a non-deterministic effect.
63-
fn evaluate_deterministic_propagation(
63+
fn evaluate_deterministic(
6464
&self,
6565
effect: &PropagatingEffect,
6666
logic: &AggregateLogic,
@@ -84,7 +84,7 @@ where
8484
///
8585
/// # Errors
8686
/// Returns a `CausalityError` if a `ContextualLink` is encountered.
87-
fn evaluate_probabilistic_propagation(
87+
fn evaluate_probabilistic(
8888
&self,
8989
effect: &PropagatingEffect,
9090
logic: &AggregateLogic,
@@ -115,7 +115,7 @@ where
115115
/// # Errors
116116
/// Returns a `CausalityError` if a `ContextualLink` is encountered, as it cannot be
117117
/// converted to a numerical probability.
118-
fn evaluate_mixed_propagation(
118+
fn evaluate_mixed(
119119
&self,
120120
effect: &PropagatingEffect,
121121
logic: &AggregateLogic,

deep_causality/tests/extensions/causable/causable_arr_tests.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ fn test_evaluate_deterministic_propagation() {
4646

4747
// Case 1: All succeed, chain should be deterministically true.
4848
let effect_success = PropagatingEffect::Numerical(0.99);
49-
let res = col.evaluate_deterministic_propagation(&effect_success, &AggregateLogic::All);
49+
let res = col.evaluate_deterministic(&effect_success, &AggregateLogic::All);
5050
assert!(res.is_ok());
5151
let res_success = res.unwrap();
5252
assert_eq!(res_success, PropagatingEffect::Deterministic(true));
5353

5454
// Case 2: One fails, chain should be deterministically false.
5555
let effect_fail = PropagatingEffect::Numerical(0.1);
56-
let res = col.evaluate_deterministic_propagation(&effect_fail, &AggregateLogic::All);
56+
let res = col.evaluate_deterministic(&effect_fail, &AggregateLogic::All);
5757
assert!(res.is_ok());
5858
let res_fail = res.unwrap();
5959
assert_eq!(res_fail, PropagatingEffect::Deterministic(false));
@@ -64,7 +64,7 @@ fn test_evaluate_probabilistic_propagation() {
6464
let col = get_test_causality_array(false);
6565

6666
let effect_success = PropagatingEffect::Probabilistic(0.99);
67-
let res = col.evaluate_probabilistic_propagation(&effect_success, &AggregateLogic::All, 0.5);
67+
let res = col.evaluate_probabilistic(&effect_success, &AggregateLogic::All, 0.5);
6868
assert!(res.is_ok());
6969

7070
let res_success = res.unwrap();
@@ -73,7 +73,7 @@ fn test_evaluate_probabilistic_propagation() {
7373
// Case 2: One fails (Deterministic(false) is treated as probability 0.0).
7474
// The chain should short-circuit and return a cumulative probability of 0.0.
7575
let effect_fail = PropagatingEffect::Numerical(0.1);
76-
let res = col.evaluate_probabilistic_propagation(&effect_fail, &AggregateLogic::All, 0.5);
76+
let res = col.evaluate_probabilistic(&effect_fail, &AggregateLogic::All, 0.5);
7777
assert!(res.is_ok());
7878
let res_fail = res.unwrap();
7979
assert_eq!(res_fail, PropagatingEffect::Probabilistic(0.0));
@@ -85,15 +85,15 @@ fn test_evaluate_mixed_propagation() {
8585

8686
// Case 1: All succeed, chain remains deterministically true.
8787
let effect_success = PropagatingEffect::Numerical(0.99);
88-
let res = col.evaluate_mixed_propagation(&effect_success, &AggregateLogic::All, 0.5);
88+
let res = col.evaluate_mixed(&effect_success, &AggregateLogic::All, 0.5);
8989
assert!(res.is_ok());
9090
let res_success = res.unwrap();
9191
assert_eq!(res_success, PropagatingEffect::Deterministic(true));
9292

9393
// Case 2: One fails, chain becomes deterministically false.
9494
let effect_fail = PropagatingEffect::Numerical(0.1);
9595
let res_fail = col
96-
.evaluate_mixed_propagation(&effect_fail, &AggregateLogic::All, 0.5)
96+
.evaluate_mixed(&effect_fail, &AggregateLogic::All, 0.5)
9797
.unwrap();
9898
assert_eq!(res_fail, PropagatingEffect::Deterministic(false));
9999
}
@@ -103,7 +103,7 @@ fn test_explain() {
103103
let col = get_test_causality_array(true);
104104

105105
let effect = PropagatingEffect::Numerical(0.99);
106-
let res = col.evaluate_deterministic_propagation(&effect, &AggregateLogic::All);
106+
let res = col.evaluate_deterministic(&effect, &AggregateLogic::All);
107107
assert!(res.is_ok());
108108

109109
let res = col.explain();

deep_causality/tests/extensions/causable/causable_btree_map_tests.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,14 @@ fn test_evaluate_deterministic_propagation() {
8787

8888
// Case 1: All succeed, chain should be deterministically true.
8989
let effect_success = PropagatingEffect::Numerical(0.99);
90-
let res = map.evaluate_deterministic_propagation(&effect_success, &AggregateLogic::All);
90+
let res = map.evaluate_deterministic(&effect_success, &AggregateLogic::All);
9191
assert!(res.is_ok());
9292
let res_success = res.unwrap();
9393
assert_eq!(res_success, PropagatingEffect::Deterministic(true));
9494

9595
// Case 2: One fails, chain should be deterministically false.
9696
let effect_fail = PropagatingEffect::Numerical(0.1);
97-
let res = map.evaluate_deterministic_propagation(&effect_fail, &AggregateLogic::All);
97+
let res = map.evaluate_deterministic(&effect_fail, &AggregateLogic::All);
9898
assert!(res.is_ok());
9999
let res_fail = res.unwrap();
100100
assert_eq!(res_fail, PropagatingEffect::Deterministic(false));
@@ -107,15 +107,15 @@ fn test_evaluate_probabilistic_propagation() {
107107
// Case 1: All succeed (Deterministic(true) is treated as probability 1.0).
108108
// The cumulative probability should be 1.0.
109109
let effect_success = PropagatingEffect::Numerical(0.99);
110-
let res = map.evaluate_probabilistic_propagation(&effect_success, &AggregateLogic::All, 0.5);
110+
let res = map.evaluate_probabilistic(&effect_success, &AggregateLogic::All, 0.5);
111111
assert!(res.is_ok());
112112
let res_success = res.unwrap();
113113
assert_eq!(res_success, PropagatingEffect::Probabilistic(1.0));
114114

115115
// Case 2: One fails (Deterministic(false) is treated as probability 0.0).
116116
// The chain should short-circuit and return a cumulative probability of 0.0.
117117
let effect_fail = PropagatingEffect::Numerical(0.1);
118-
let res = map.evaluate_probabilistic_propagation(&effect_fail, &AggregateLogic::All, 0.5);
118+
let res = map.evaluate_probabilistic(&effect_fail, &AggregateLogic::All, 0.5);
119119
assert!(res.is_ok());
120120
let res_fail = res.unwrap();
121121
assert_eq!(res_fail, PropagatingEffect::Probabilistic(0.0));
@@ -127,14 +127,14 @@ fn test_evaluate_mixed_propagation() {
127127

128128
// Case 1: All succeed, chain remains deterministically true.
129129
let effect_success = PropagatingEffect::Numerical(0.99);
130-
let res = map.evaluate_mixed_propagation(&effect_success, &AggregateLogic::All, 0.5);
130+
let res = map.evaluate_mixed(&effect_success, &AggregateLogic::All, 0.5);
131131
assert!(res.is_ok());
132132
let res_success = res.unwrap();
133133
assert_eq!(res_success, PropagatingEffect::Deterministic(true));
134134

135135
// Case 2: One fails, chain becomes deterministically false.
136136
let effect_fail = PropagatingEffect::Numerical(0.1);
137-
let res = map.evaluate_mixed_propagation(&effect_fail, &AggregateLogic::All, 0.5);
137+
let res = map.evaluate_mixed(&effect_fail, &AggregateLogic::All, 0.5);
138138
assert!(res.is_ok());
139139
let res_fail = res.unwrap();
140140
assert_eq!(res_fail, PropagatingEffect::Deterministic(false));
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* SPDX-License-Identifier: MIT
3+
* Copyright (c) "2025" . The DeepCausality Authors and Contributors. All Rights Reserved.
4+
*/
5+
use deep_causality::{AggregateLogic, BaseCausaloid, CausableReasoning, PropagatingEffect};
6+
7+
#[test]
8+
fn test_get_all_items_empty() {
9+
let col: [BaseCausaloid; 0] = [];
10+
let exp_len = col.len();
11+
assert_eq!(exp_len, 0);
12+
}
13+
14+
#[test]
15+
fn test_evaluate_deterministic_propagation_empty() {
16+
let col: [BaseCausaloid; 0] = [];
17+
let exp_len = col.len();
18+
assert_eq!(exp_len, 0);
19+
20+
let effect_fail = PropagatingEffect::Numerical(0.1);
21+
let res = col.evaluate_deterministic(&effect_fail, &AggregateLogic::All);
22+
assert!(res.is_err());
23+
}
24+
25+
#[test]
26+
fn test_evaluate_probabilistic_propagation_empty() {
27+
let col: [BaseCausaloid; 0] = [];
28+
let exp_len = col.len();
29+
assert_eq!(exp_len, 0);
30+
31+
let effect_fail = PropagatingEffect::Numerical(0.1);
32+
let res = col.evaluate_probabilistic(&effect_fail, &AggregateLogic::All, 0.5);
33+
assert!(res.is_err());
34+
}
35+
36+
#[test]
37+
fn test_evaluate_probabilistic_mixed_empty() {
38+
let col: [BaseCausaloid; 0] = [];
39+
let exp_len = col.len();
40+
assert_eq!(exp_len, 0);
41+
42+
let effect_fail = PropagatingEffect::Numerical(0.1);
43+
let res = col.evaluate_mixed(&effect_fail, &AggregateLogic::All, 0.5);
44+
assert!(res.is_err());
45+
}

deep_causality/tests/extensions/causable/causable_map_tests.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,14 @@ fn test_evaluate_deterministic_propagation() {
103103

104104
// Case 1: All succeed, chain should be deterministically true.
105105
let effect_success = PropagatingEffect::Numerical(0.99);
106-
let res = map.evaluate_deterministic_propagation(&effect_success, &AggregateLogic::All);
106+
let res = map.evaluate_deterministic(&effect_success, &AggregateLogic::All);
107107
assert!(res.is_ok());
108108
let res_success = res.unwrap();
109109
assert_eq!(res_success, PropagatingEffect::Deterministic(true));
110110

111111
// Case 2: One fails, chain should be deterministically false.
112112
let effect_fail = PropagatingEffect::Numerical(0.1);
113-
let res = map.evaluate_deterministic_propagation(&effect_fail, &AggregateLogic::All);
113+
let res = map.evaluate_deterministic(&effect_fail, &AggregateLogic::All);
114114
assert!(res.is_ok());
115115
let res_fail = res.unwrap();
116116
assert_eq!(res_fail, PropagatingEffect::Deterministic(false));
@@ -123,15 +123,15 @@ fn test_evaluate_probabilistic_propagation() {
123123
// Case 1: All succeed (Deterministic(true) is treated as probability 1.0).
124124
// The cumulative probability should be 1.0.
125125
let effect_success = PropagatingEffect::Numerical(0.99);
126-
let res = map.evaluate_probabilistic_propagation(&effect_success, &AggregateLogic::All, 0.5);
126+
let res = map.evaluate_probabilistic(&effect_success, &AggregateLogic::All, 0.5);
127127
assert!(res.is_ok());
128128
let res_success = res.unwrap();
129129
assert_eq!(res_success, PropagatingEffect::Probabilistic(1.0));
130130

131131
// Case 2: One fails (Deterministic(false) is treated as probability 0.0).
132132
// The chain should short-circuit and return a cumulative probability of 0.0.
133133
let effect_fail = PropagatingEffect::Numerical(0.1);
134-
let res = map.evaluate_probabilistic_propagation(&effect_fail, &AggregateLogic::All, 0.5);
134+
let res = map.evaluate_probabilistic(&effect_fail, &AggregateLogic::All, 0.5);
135135
assert!(res.is_ok());
136136
let res_fail = res.unwrap();
137137
assert_eq!(res_fail, PropagatingEffect::Probabilistic(0.0));
@@ -143,7 +143,7 @@ fn test_evaluate_mixed_propagation() {
143143

144144
// Case 1: All succeed, chain remains deterministically true.
145145
let effect_success = PropagatingEffect::Numerical(0.99);
146-
let res = map.evaluate_mixed_propagation(&effect_success, &AggregateLogic::All, 0.5);
146+
let res = map.evaluate_mixed(&effect_success, &AggregateLogic::All, 0.5);
147147
assert!(res.is_ok());
148148
let res_success = res.unwrap();
149149
// All mixed cased evaluate
@@ -156,7 +156,7 @@ fn test_evaluate_mixed_propagation_err() {
156156

157157
//
158158
let effect_fail = PropagatingEffect::Numerical(0.1);
159-
let res = map.evaluate_mixed_propagation(&effect_fail, &AggregateLogic::All, 0.5);
159+
let res = map.evaluate_mixed(&effect_fail, &AggregateLogic::All, 0.5);
160160
assert!(res.is_err());
161161
}
162162

0 commit comments

Comments
 (0)