From efb515832a6689fd6de63a3c6327404553a8d360 Mon Sep 17 00:00:00 2001 From: "Jorge C. Leitao" Date: Tue, 28 Jun 2022 09:51:19 +0000 Subject: [PATCH] Added teest --- tests/it/compute/arithmetics/decimal/div.rs | 27 ++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/tests/it/compute/arithmetics/decimal/div.rs b/tests/it/compute/arithmetics/decimal/div.rs index 55cca8d303d..39138d05dda 100644 --- a/tests/it/compute/arithmetics/decimal/div.rs +++ b/tests/it/compute/arithmetics/decimal/div.rs @@ -1,9 +1,12 @@ #![allow(clippy::zero_prefixed_literal, clippy::inconsistent_digit_grouping)] use arrow2::array::*; -use arrow2::compute::arithmetics::decimal::{adaptive_div, checked_div, div, saturating_div}; +use arrow2::compute::arithmetics::decimal::{ + adaptive_div, checked_div, div, div_scalar, saturating_div, +}; use arrow2::compute::arithmetics::{ArrayCheckedDiv, ArrayDiv}; use arrow2::datatypes::DataType; +use arrow2::scalar::PrimitiveScalar; #[test] fn test_divide_normal() { @@ -65,6 +68,28 @@ fn test_divide_panic() { div(&a, &b); } +#[test] +fn test_div_scalar() { + // 222.222 --> 222222000 + // 123.456 --> 123456 + // -------- --------- + // 1.800 <-- 1800 + let a = PrimitiveArray::from([Some(222_222i128), None]).to(DataType::Decimal(7, 3)); + let b = PrimitiveScalar::from(Some(123_456i128)).to(DataType::Decimal(7, 3)); + let result = div_scalar(&a, &b); + + let expected = PrimitiveArray::from([Some(1_800i128), None]).to(DataType::Decimal(7, 3)); + assert_eq!(result, expected); +} + +#[test] +#[should_panic(expected = "Overflow in multiplication presented for precision 5")] +fn test_divide_scalar_panic() { + let a = PrimitiveArray::from([Some(99999i128)]).to(DataType::Decimal(5, 2)); + let b = PrimitiveScalar::from(Some(000_01i128)).to(DataType::Decimal(5, 2)); + div_scalar(&a, &b); +} + #[test] fn test_divide_saturating() { let a = PrimitiveArray::from([