MCPcopy Create free account
hub / github.com/apache/arrow-rs / test_duration_impl

Function test_duration_impl

arrow-arith/src/numeric.rs:1485–1519  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1483 }
1484
1485 fn test_duration_impl<T: ArrowPrimitiveType<Native = i64>>() {
1486 let a = PrimitiveArray::<T>::new(vec![1000, 4394, -3944].into(), None);
1487 let b = PrimitiveArray::<T>::new(vec![4, -5, -243].into(), None);
1488
1489 let result = add(&a, &b).unwrap();
1490 assert_eq!(result.as_primitive::<T>().values(), &[1004, 4389, -4187]);
1491 let result = sub(&a, &b).unwrap();
1492 assert_eq!(result.as_primitive::<T>().values(), &[996, 4399, -3701]);
1493
1494 let err = mul(&a, &b).unwrap_err().to_string();
1495 assert!(
1496 err.contains("Invalid duration arithmetic operation"),
1497 "{err}"
1498 );
1499
1500 let err = div(&a, &b).unwrap_err().to_string();
1501 assert!(
1502 err.contains("Invalid duration arithmetic operation"),
1503 "{err}"
1504 );
1505
1506 let err = rem(&a, &b).unwrap_err().to_string();
1507 assert!(
1508 err.contains("Invalid duration arithmetic operation"),
1509 "{err}"
1510 );
1511
1512 let a = PrimitiveArray::<T>::new(vec![i64::MAX].into(), None);
1513 let b = PrimitiveArray::<T>::new(vec![1].into(), None);
1514 let err = add(&a, &b).unwrap_err().to_string();
1515 assert_eq!(
1516 err,
1517 "Arithmetic overflow: Overflow happened on: 9223372036854775807 + 1"
1518 );
1519 }
1520
1521 #[test]
1522 fn test_duration() {

Callers

nothing calls this directly

Calls 5

addFunction · 0.85
subFunction · 0.85
mulFunction · 0.85
divFunction · 0.85
remFunction · 0.85

Tested by

no test coverage detected