Skip to content

Commit

Permalink
tests: Parameterized pytests for math operations
Browse files Browse the repository at this point in the history
This replaces some math tests within Kaskada with pytests coverage.
  • Loading branch information
bjchambers committed Oct 18, 2023
1 parent 1a2d930 commit e807043
Show file tree
Hide file tree
Showing 129 changed files with 1,175 additions and 549 deletions.
6 changes: 5 additions & 1 deletion crates/sparrow-instructions/src/evaluators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,12 @@ impl<'a> StaticInfo<'a> {

fn check_numeric(evaluator: &'static str, data_type: &DataType) -> anyhow::Result<()> {
match data_type {
DataType::Int32
DataType::Int8
| DataType::Int16
| DataType::Int32
| DataType::Int64
| DataType::UInt8
| DataType::UInt16
| DataType::UInt32
| DataType::UInt64
| DataType::Float32
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub trait NumericProperties {
}

impl NumericProperties for f32 {
const ZERO: f32 = 0.0;
const ZERO: Self = 0.0;

fn max(a: Self, b: Self) -> Self {
a.max(b)
Expand Down Expand Up @@ -44,6 +44,42 @@ impl NumericProperties for f64 {
}
}

impl NumericProperties for i8 {
const ZERO: Self = 0;

fn max(a: Self, b: Self) -> Self {
a.max(b)
}
fn min(a: Self, b: Self) -> Self {
a.min(b)
}
fn as_f64(&self) -> f64 {
*self as f64
}

fn saturating_add(a: Self, b: Self) -> Self {
a + b
}
}

impl NumericProperties for i16 {
const ZERO: Self = 0;

fn max(a: Self, b: Self) -> Self {
a.max(b)
}
fn min(a: Self, b: Self) -> Self {
a.min(b)
}
fn as_f64(&self) -> f64 {
*self as f64
}

fn saturating_add(a: Self, b: Self) -> Self {
a + b
}
}

impl NumericProperties for i32 {
const ZERO: Self = 0;

Expand Down Expand Up @@ -82,6 +118,44 @@ impl NumericProperties for i64 {
}
}

impl NumericProperties for u8 {
const ZERO: Self = 0;

fn max(a: Self, b: Self) -> Self {
a.max(b)
}

fn min(a: Self, b: Self) -> Self {
a.min(b)
}

fn as_f64(&self) -> f64 {
*self as f64
}
fn saturating_add(a: Self, b: Self) -> Self {
a.saturating_add(b)
}
}

impl NumericProperties for u16 {
const ZERO: Self = 0;

fn max(a: Self, b: Self) -> Self {
a.max(b)
}

fn min(a: Self, b: Self) -> Self {
a.min(b)
}

fn as_f64(&self) -> f64 {
*self as f64
}
fn saturating_add(a: Self, b: Self) -> Self {
a.saturating_add(b)
}
}

impl NumericProperties for u32 {
const ZERO: Self = 0;

Expand Down
4 changes: 4 additions & 0 deletions crates/sparrow-instructions/src/evaluators/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ macro_rules! create_number_evaluator {
($input_type:expr, $evaluator:ident, $aggf:ident, $info:expr) => {{
use arrow::datatypes::*;
match $input_type {
DataType::Int8 => $evaluator::<$aggf<Int8Type>>::try_new($info),
DataType::Int16 => $evaluator::<$aggf<Int16Type>>::try_new($info),
DataType::Int32 => $evaluator::<$aggf<Int32Type>>::try_new($info),
DataType::Int64 => $evaluator::<$aggf<Int64Type>>::try_new($info),
DataType::UInt8 => $evaluator::<$aggf<UInt8Type>>::try_new($info),
DataType::UInt16 => $evaluator::<$aggf<UInt16Type>>::try_new($info),
DataType::UInt32 => $evaluator::<$aggf<UInt32Type>>::try_new($info),
DataType::UInt64 => $evaluator::<$aggf<UInt64Type>>::try_new($info),
DataType::Float32 => $evaluator::<$aggf<Float32Type>>::try_new($info),
Expand Down
1 change: 0 additions & 1 deletion crates/sparrow-main/tests/e2e/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ mod list_tests;
mod logical_tests;
mod lookup_tests;
mod map_tests;
mod math_tests;
mod multiple_tables;
mod record_tests;
mod resumeable_tests;
Expand Down
Loading

0 comments on commit e807043

Please sign in to comment.