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

Function test_mod_float64

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

Source from the content-addressed store, hash-verified

230
231 #[test]
232 fn test_mod_float64() {
233 let left = Float64Array::from(vec![
234 Some(10.5),
235 Some(7.2),
236 Some(15.8),
237 Some(f64::NAN),
238 Some(f64::INFINITY),
239 Some(5.0),
240 Some(5.0),
241 Some(f64::NAN),
242 Some(f64::INFINITY),
243 Some(10.5),
244 Some(15.8),
245 ]);
246 let right = Float64Array::from(vec![
247 Some(3.0),
248 Some(2.5),
249 Some(4.2),
250 Some(2.0),
251 Some(2.0),
252 Some(f64::NAN),
253 Some(f64::INFINITY),
254 Some(f64::INFINITY),
255 Some(f64::NAN),
256 Some(0.0),
257 Some(0.0),
258 ]);
259
260 let left_value = ColumnarValue::Array(Arc::new(left));
261 let right_value = ColumnarValue::Array(Arc::new(right));
262
263 let result = spark_mod(&[left_value, right_value], false).unwrap();
264
265 if let ColumnarValue::Array(result_array) = result {
266 let result_float64 = result_array
267 .as_any()
268 .downcast_ref::<Float64Array>()
269 .unwrap();
270 // Regular cases
271 assert!((result_float64.value(0) - 1.5).abs() < f64::EPSILON); // 10.5 % 3.0 = 1.5
272 assert!((result_float64.value(1) - 2.2).abs() < f64::EPSILON); // 7.2 % 2.5 = 2.2
273 assert!((result_float64.value(2) - 3.2).abs() < f64::EPSILON); // 15.8 % 4.2 = 3.2
274 // nan % 2.0 = nan
275 assert!(result_float64.value(3).is_nan());
276 // inf % 2.0 = nan (IEEE 754)
277 assert!(result_float64.value(4).is_nan());
278 // 5.0 % nan = nan
279 assert!(result_float64.value(5).is_nan());
280 // 5.0 % inf = 5.0
281 assert!((result_float64.value(6) - 5.0).abs() < f64::EPSILON);
282 // nan % inf = nan
283 assert!(result_float64.value(7).is_nan());
284 // inf % nan = nan
285 assert!(result_float64.value(8).is_nan());
286 // Division by zero returns NULL
287 assert!(result_float64.is_null(9)); // 10.5 % 0.0 = NULL
288 assert!(result_float64.is_null(10)); // 15.8 % 0.0 = NULL
289 } else {

Callers

nothing calls this directly

Calls 3

newFunction · 0.85
spark_modFunction · 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…