Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
Added teest
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecarleitao committed Jun 28, 2022
1 parent 3b05377 commit efb5158
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion tests/it/compute/arithmetics/decimal/div.rs
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down Expand Up @@ -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([
Expand Down

0 comments on commit efb5158

Please sign in to comment.