ryankert01 commented on code in PR #805:
URL: https://github.com/apache/mahout/pull/805#discussion_r2691686912
##########
qdp/qdp-core/tests/preprocessing.rs:
##########
@@ -53,8 +53,8 @@ fn test_validate_input_empty_data() {
#[test]
fn test_validate_input_data_too_large() {
- let data = vec![1.0, 0.0, 0.0]; // 3 elements
- let result = Preprocessor::validate_input(&data, 1); // max size 2^1 = 2
+ let data = vec![1.0, 0.0, 0.0];
+ let result = Preprocessor::validate_input(&data, 1);
Review Comment:
whats the reason of removing comments?
##########
qdp/qdp-core/tests/preprocessing.rs:
##########
@@ -105,3 +105,48 @@ fn test_calculate_l2_norm_matches_sequential_sum() {
let norm_sequential = data.iter().map(|x| x * x).sum::<f64>().sqrt();
assert!((norm_parallel - norm_sequential).abs() < 1e-10);
}
+
+#[test]
+fn test_calculate_l2_norm_invalid_values() {
+ let cases = [
+ ("NaN", f64::NAN, "NaN"),
+ ("+Inf", f64::INFINITY, "Infinity"),
+ ("-Inf", f64::NEG_INFINITY, "Infinity"),
+ ];
+
+ for (label, bad_value, expected_fragment) in cases {
+ let data = vec![1.0, bad_value, 3.0];
+ let result = Preprocessor::calculate_l2_norm(&data);
+ assert!(
+ matches!(result, Err(MahoutError::InvalidInput(msg)) if
msg.contains(expected_fragment)),
+ "case {label} did not produce expected error"
+ );
+ }
+}
+
+#[test]
+fn test_calculate_batch_l2_norms_invalid_values() {
+ let cases = [
+ ("NaN", f64::NAN, "NaN"),
+ ("+Inf", f64::INFINITY, "Infinity"),
+ ("-Inf", f64::NEG_INFINITY, "Infinity"),
+ ];
+
+ for (label, bad_value, expected_fragment) in cases {
+ let batch_data = vec![1.0, 2.0, bad_value, 4.0];
+ let result = Preprocessor::calculate_batch_l2_norms(&batch_data, 2, 2);
+ assert!(
+ matches!(result, Err(MahoutError::InvalidInput(msg)) if
msg.contains(expected_fragment)),
+ "case {label} did not produce expected error"
+ );
+ }
+}
+
+#[test]
+fn test_calculate_batch_l2_norms_success() {
+ let batch_data = vec![3.0, 4.0, 5.0, 12.0];
+ let norms = Preprocessor::calculate_batch_l2_norms(&batch_data, 2,
2).unwrap();
+ assert_eq!(norms.len(), 2);
+ assert!((norms[0] - 5.0).abs() < 1e-10); // sqrt(3^2 + 4^2) = 5
+ assert!((norms[1] - 13.0).abs() < 1e-10); // sqrt(5^2 + 12^2) = 13
Review Comment:
nit: although completely understand what its doing, we can also use
`approx::assert_relative_eq` to enhance its readability.
##########
qdp/qdp-core/tests/preprocessing.rs:
##########
@@ -63,7 +63,7 @@ fn test_validate_input_data_too_large() {
#[test]
fn test_validate_input_allows_partial_state() {
let data = vec![0.5, -0.5, 0.25];
- assert!(Preprocessor::validate_input(&data, 3).is_ok()); // state vector
can hold up to 8 elements
+ assert!(Preprocessor::validate_input(&data, 3).is_ok());
Review Comment:
ditto.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]