MCPcopy Create free account
hub / github.com/apache/datafusion / test_pmod_float64

Function test_pmod_float64

datafusion/spark/src/function/math/modulus.rs:468–523  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

466
467 #[test]
468 fn test_pmod_float64() {
469 let left = Float64Array::from(vec![
470 Some(10.5),
471 Some(-7.2),
472 Some(15.8),
473 Some(-15.8),
474 Some(f64::NAN),
475 Some(f64::INFINITY),
476 Some(5.0),
477 Some(-5.0),
478 Some(10.5),
479 Some(-7.2),
480 ]);
481 let right = Float64Array::from(vec![
482 Some(3.0),
483 Some(3.0),
484 Some(4.2),
485 Some(4.2),
486 Some(2.0),
487 Some(2.0),
488 Some(f64::INFINITY),
489 Some(f64::INFINITY),
490 Some(0.0),
491 Some(0.0),
492 ]);
493
494 let left_value = ColumnarValue::Array(Arc::new(left));
495 let right_value = ColumnarValue::Array(Arc::new(right));
496
497 let result = spark_pmod(&[left_value, right_value], false).unwrap();
498
499 if let ColumnarValue::Array(result_array) = result {
500 let result_float64 = result_array
501 .as_any()
502 .downcast_ref::<Float64Array>()
503 .unwrap();
504 // Regular cases
505 assert!((result_float64.value(0) - 1.5).abs() < f64::EPSILON); // 10.5 pmod 3.0 = 1.5
506 assert!((result_float64.value(1) - 1.8).abs() < f64::EPSILON * 3.0); // -7.2 pmod 3.0 = 1.8 (positive)
507 assert!((result_float64.value(2) - 3.2).abs() < f64::EPSILON * 3.0); // 15.8 pmod 4.2 = 3.2
508 assert!((result_float64.value(3) - 1.0).abs() < f64::EPSILON * 3.0); // -15.8 pmod 4.2 = 1.0 (positive)
509 // nan pmod 2.0 = nan
510 assert!(result_float64.value(4).is_nan());
511 // inf pmod 2.0 = nan (IEEE 754)
512 assert!(result_float64.value(5).is_nan());
513 // 5.0 pmod inf = 5.0
514 assert!((result_float64.value(6) - 5.0).abs() < f64::EPSILON);
515 // -5.0 pmod inf = NaN
516 assert!(result_float64.value(7).is_nan());
517 // Division by zero returns NULL
518 assert!(result_float64.is_null(8)); // 10.5 pmod 0.0 = NULL
519 assert!(result_float64.is_null(9)); // -7.2 pmod 0.0 = NULL
520 } else {
521 panic!("Expected array result");
522 }
523 }
524
525 #[test]

Callers

nothing calls this directly

Calls 3

newFunction · 0.85
spark_pmodFunction · 0.85
as_anyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…