Skip to content

Commit 23f67f1

Browse files
committed
test(deep_causality_uncertain): Increased test coverage.
Signed-off-by: Marvin Hansen <[email protected]>
1 parent 077e267 commit 23f67f1

File tree

5 files changed

+138
-1
lines changed

5 files changed

+138
-1
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* SPDX-License-Identifier: MIT
3+
* Copyright (c) "2025" . The DeepCausality Authors and Contributors. All Rights Reserved.
4+
*/
5+
use deep_causality_uncertain::{
6+
FromSampledValue, IntoSampledValue, ProbabilisticType, SampledValue, UncertainError,
7+
};
8+
9+
// Tests for IntoSampledValue for bool
10+
#[test]
11+
fn test_bool_into_sampled_value_true() {
12+
let val = true;
13+
assert_eq!(val.into_sampled_value(), SampledValue::Bool(true));
14+
}
15+
16+
#[test]
17+
fn test_bool_into_sampled_value_false() {
18+
let val = false;
19+
assert_eq!(val.into_sampled_value(), SampledValue::Bool(false));
20+
}
21+
22+
// Tests for FromSampledValue for bool
23+
#[test]
24+
fn test_bool_from_sampled_value_bool() {
25+
let sampled = SampledValue::Bool(true);
26+
let result = bool::from_sampled_value(sampled);
27+
assert!(result.is_ok());
28+
let val = result.unwrap();
29+
assert!(val);
30+
}
31+
32+
#[test]
33+
fn test_bool_from_sampled_value_float_err() {
34+
let sampled = SampledValue::Float(0.42);
35+
let result = bool::from_sampled_value(sampled);
36+
// Ensure the correct error type and message is returned
37+
assert!(matches!(
38+
result,
39+
Err(UncertainError::UnsupportedTypeError(_))
40+
));
41+
if let Err(UncertainError::UnsupportedTypeError(msg)) = result {
42+
assert_eq!(msg, "Expected bool SampledValue");
43+
}
44+
}
45+
46+
// Test for ProbabilisticType for bool
47+
#[test]
48+
fn test_bool_default_value() {
49+
assert!(!bool::default_value());
50+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* SPDX-License-Identifier: MIT
3+
* Copyright (c) "2025" . The DeepCausality Authors and Contributors. All Rights Reserved.
4+
*/
5+
use deep_causality_uncertain::{
6+
FromSampledValue, IntoSampledValue, ProbabilisticType, SampledValue, UncertainError,
7+
};
8+
9+
// Test for IntoSampledValue for f64
10+
#[test]
11+
fn test_f64_into_sampled_value() {
12+
let val = 42.0;
13+
assert_eq!(val.into_sampled_value(), SampledValue::Float(42.0));
14+
}
15+
16+
// Tests for FromSampledValue for f64
17+
#[test]
18+
fn test_f64_from_sampled_value_float() {
19+
let sampled = SampledValue::Float(42.0);
20+
let result = f64::from_sampled_value(sampled);
21+
assert!(result.is_ok());
22+
let val = result.unwrap();
23+
assert_eq!(val, 42.0);
24+
}
25+
26+
#[test]
27+
fn test_f64_from_sampled_value_bool_err() {
28+
let sampled = SampledValue::Bool(true);
29+
let result = f64::from_sampled_value(sampled);
30+
// Ensure the correct error type and message is returned
31+
assert!(matches!(
32+
result,
33+
Err(UncertainError::UnsupportedTypeError(_))
34+
));
35+
if let Err(UncertainError::UnsupportedTypeError(msg)) = result {
36+
assert_eq!(msg, "Expected f64 SampledValue");
37+
}
38+
}
39+
40+
// Test for ProbabilisticType for f64
41+
#[test]
42+
fn test_f64_default_value() {
43+
assert_eq!(f64::default_value(), 0.0);
44+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/*
2+
* SPDX-License-Identifier: MIT
3+
* Copyright (c) "2025" . The DeepCausality Authors and Contributors. All Rights Reserved.
4+
*/
5+
mod bool_probabilistic_type_tests;
6+
mod f64_probabilistic_type_tests;

deep_causality_uncertain/tests/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55

66
mod algos;
77
mod errors;
8+
mod extensions;
89
mod integration_tests;
910
mod types;

deep_causality_uncertain/tests/types/cache/sampled_value_tests.rs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
* SPDX-License-Identifier: MIT
33
* Copyright (c) "2025" . The DeepCausality Authors and Contributors. All Rights Reserved.
44
*/
5-
use deep_causality_uncertain::SampledValue;
5+
use deep_causality_uncertain::{
6+
FromSampledValue, IntoSampledValue, ProbabilisticType, SampledValue,
7+
};
68

79
#[test]
810
fn test_sampled_value_float_display() {
@@ -54,3 +56,37 @@ fn test_sampled_value_float_copy() {
5456
let copied_val = val; // Copy happens implicitly
5557
assert_eq!(val, copied_val);
5658
}
59+
60+
// Tests for IntoSampledValue implementation
61+
#[test]
62+
fn test_into_sampled_value_float() {
63+
let value = SampledValue::Float(42.0);
64+
assert_eq!(value.into_sampled_value(), SampledValue::Float(42.0));
65+
}
66+
67+
#[test]
68+
fn test_into_sampled_value_bool() {
69+
let value = SampledValue::Bool(true);
70+
assert_eq!(value.into_sampled_value(), SampledValue::Bool(true));
71+
}
72+
73+
// Tests for FromSampledValue implementation
74+
#[test]
75+
fn test_from_sampled_value_float() {
76+
let value = SampledValue::Float(42.0);
77+
let result = SampledValue::from_sampled_value(value).unwrap();
78+
assert_eq!(result, SampledValue::Float(42.0));
79+
}
80+
81+
#[test]
82+
fn test_from_sampled_value_bool() {
83+
let value = SampledValue::Bool(true);
84+
let result = SampledValue::from_sampled_value(value).unwrap();
85+
assert_eq!(result, SampledValue::Bool(true));
86+
}
87+
88+
// Test for ProbabilisticType implementation
89+
#[test]
90+
fn test_default_value() {
91+
assert_eq!(SampledValue::default_value(), SampledValue::Float(0.0));
92+
}

0 commit comments

Comments
 (0)