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

Move tests from src/compute/ to tests/ #423

Merged
merged 1 commit into from
Sep 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions src/compute/aggregate/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,26 +111,3 @@ pub fn estimated_bytes_size(array: &dyn Array) -> usize {
}),
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn primitive() {
let a = Int32Array::from_slice(&[1, 2, 3, 4, 5]);
assert_eq!(5 * std::mem::size_of::<i32>(), estimated_bytes_size(&a));
}

#[test]
fn boolean() {
let a = BooleanArray::from_slice(&[true]);
assert_eq!(1, estimated_bytes_size(&a));
}

#[test]
fn utf8() {
let a = Utf8Array::<i32>::from_slice(&["aaa"]);
assert_eq!(3 + 2 * std::mem::size_of::<i32>(), estimated_bytes_size(&a));
}
}
189 changes: 0 additions & 189 deletions src/compute/aggregate/min_max.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,192 +425,3 @@ pub fn min(array: &dyn Array) -> Result<Box<dyn Scalar>> {
}
})
}

#[cfg(test)]
mod tests {
use super::*;
use crate::array::*;

#[test]
fn test_primitive_array_min_max() {
let a = Int32Array::from_slice(&[5, 6, 7, 8, 9]);
assert_eq!(5, min_primitive(&a).unwrap());
assert_eq!(9, max_primitive(&a).unwrap());
}

#[test]
fn test_primitive_array_min_max_with_nulls() {
let a = Int32Array::from(&[Some(5), None, None, Some(8), Some(9)]);
assert_eq!(5, min_primitive(&a).unwrap());
assert_eq!(9, max_primitive(&a).unwrap());
}

#[test]
fn test_primitive_min_max_1() {
let a = Int32Array::from(&[None, None, Some(5), Some(2)]);
assert_eq!(Some(2), min_primitive(&a));
assert_eq!(Some(5), max_primitive(&a));
}

#[test]
fn min_max_f32() {
let a = Float32Array::from(&[None, None, Some(5.0), Some(2.0)]);
assert_eq!(Some(2.0), min_primitive(&a));
assert_eq!(Some(5.0), max_primitive(&a));
}

#[test]
fn min_max_f64() {
let a = Float64Array::from(&[None, None, Some(5.0), Some(2.0)]);
assert_eq!(Some(2.0), min_primitive(&a));
assert_eq!(Some(5.0), max_primitive(&a));
}

#[test]
fn min_max_f64_large() {
// in simd, f64 has 8 lanes, thus > 8 covers the branch with lanes
let a = Float64Array::from(&[
None,
None,
Some(8.0),
Some(2.0),
None,
None,
Some(5.0),
Some(2.0),
]);
assert_eq!(Some(2.0), min_primitive(&a));
assert_eq!(Some(8.0), max_primitive(&a));
}

#[test]
fn min_max_f64_nan_only() {
let a = Float64Array::from(&[None, Some(f64::NAN)]);
assert!(min_primitive(&a).unwrap().is_nan());
assert!(max_primitive(&a).unwrap().is_nan());
}

#[test]
fn min_max_f64_nan() {
let a = Float64Array::from(&[None, Some(1.0), Some(f64::NAN)]);
assert_eq!(Some(1.0), min_primitive(&a));
assert_eq!(Some(1.0), max_primitive(&a));
}

#[test]
fn min_max_f64_edge_cases() {
let a: Float64Array = (0..100).map(|_| Some(f64::NEG_INFINITY)).collect();
assert_eq!(Some(f64::NEG_INFINITY), min_primitive(&a));
assert_eq!(Some(f64::NEG_INFINITY), max_primitive(&a));

let a: Float64Array = (0..100).map(|_| Some(f64::MIN)).collect();
assert_eq!(Some(f64::MIN), min_primitive(&a));
assert_eq!(Some(f64::MIN), max_primitive(&a));

let a: Float64Array = (0..100).map(|_| Some(f64::MAX)).collect();
assert_eq!(Some(f64::MAX), min_primitive(&a));
assert_eq!(Some(f64::MAX), max_primitive(&a));

let a: Float64Array = (0..100).map(|_| Some(f64::INFINITY)).collect();
assert_eq!(Some(f64::INFINITY), min_primitive(&a));
assert_eq!(Some(f64::INFINITY), max_primitive(&a));
}

// todo: convert me
#[test]
fn test_string_min_max_with_nulls() {
let a = Utf8Array::<i32>::from(&[Some("b"), None, None, Some("a"), Some("c")]);
assert_eq!("a", min_string(&a).unwrap());
assert_eq!("c", max_string(&a).unwrap());
}

#[test]
fn test_string_min_max_all_nulls() {
let a = Utf8Array::<i32>::from(&[None::<&str>, None]);
assert_eq!(None, min_string(&a));
assert_eq!(None, max_string(&a));
}

#[test]
fn test_string_min_max_1() {
let a = Utf8Array::<i32>::from(&[None, None, Some("b"), Some("a")]);
assert_eq!(Some("a"), min_string(&a));
assert_eq!(Some("b"), max_string(&a));
}

#[test]
fn test_boolean_min_max_empty() {
let a = BooleanArray::new_empty(DataType::Boolean);
assert_eq!(None, min_boolean(&a));
assert_eq!(None, max_boolean(&a));
}

#[test]
fn test_boolean_min_max_all_null() {
let a = BooleanArray::from(&[None, None]);
assert_eq!(None, min_boolean(&a));
assert_eq!(None, max_boolean(&a));
}

#[test]
fn test_boolean_min_max_no_null() {
let a = BooleanArray::from(&[Some(true), Some(false), Some(true)]);
assert_eq!(Some(false), min_boolean(&a));
assert_eq!(Some(true), max_boolean(&a));
}

#[test]
fn test_boolean_min_max() {
let a = BooleanArray::from(&[Some(true), Some(true), None, Some(false), None]);
assert_eq!(Some(false), min_boolean(&a));
assert_eq!(Some(true), max_boolean(&a));

let a = BooleanArray::from(&[None, Some(true), None, Some(false), None]);
assert_eq!(Some(false), min_boolean(&a));
assert_eq!(Some(true), max_boolean(&a));

let a = BooleanArray::from(&[Some(false), Some(true), None, Some(false), None]);
assert_eq!(Some(false), min_boolean(&a));
assert_eq!(Some(true), max_boolean(&a));
}

#[test]
fn test_boolean_min_max_smaller() {
let a = BooleanArray::from(&[Some(false)]);
assert_eq!(Some(false), min_boolean(&a));
assert_eq!(Some(false), max_boolean(&a));

let a = BooleanArray::from(&[None, Some(false)]);
assert_eq!(Some(false), min_boolean(&a));
assert_eq!(Some(false), max_boolean(&a));

let a = BooleanArray::from(&[None, Some(true)]);
assert_eq!(Some(true), min_boolean(&a));
assert_eq!(Some(true), max_boolean(&a));

let a = BooleanArray::from(&[Some(true)]);
assert_eq!(Some(true), min_boolean(&a));
assert_eq!(Some(true), max_boolean(&a));
}

#[test]
fn test_binary_min_max_with_nulls() {
let a = BinaryArray::<i32>::from(&[Some(b"b"), None, None, Some(b"a"), Some(b"c")]);
assert_eq!("a".as_bytes(), min_binary(&a).unwrap());
assert_eq!("c".as_bytes(), max_binary(&a).unwrap());
}

#[test]
fn test_binary_min_max_all_nulls() {
let a = BinaryArray::<i32>::from(&[None::<&[u8]>, None]);
assert_eq!(None, min_binary(&a));
assert_eq!(None, max_binary(&a));
}

#[test]
fn test_binary_min_max_1() {
let a = BinaryArray::<i32>::from(&[None, None, Some(b"b"), Some(b"a")]);
assert_eq!(Some("a".as_bytes()), min_binary(&a));
assert_eq!(Some("b".as_bytes()), max_binary(&a));
}
}
56 changes: 0 additions & 56 deletions src/compute/aggregate/sum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,59 +174,3 @@ pub fn sum(array: &dyn Array) -> Result<Box<dyn Scalar>> {
}
})
}

#[cfg(test)]
mod tests {
use super::super::super::arithmetics;
use super::*;
use crate::array::*;

#[test]
fn test_primitive_array_sum() {
let a = Int32Array::from_slice(&[1, 2, 3, 4, 5]);
assert_eq!(
&PrimitiveScalar::<i32>::from(Some(15)) as &dyn Scalar,
sum(&a).unwrap().as_ref()
);

let a = a.to(DataType::Date32);
assert_eq!(
&PrimitiveScalar::<i32>::from(Some(15)).to(DataType::Date32) as &dyn Scalar,
sum(&a).unwrap().as_ref()
);
}

#[test]
fn test_primitive_array_float_sum() {
let a = Float64Array::from_slice(&[1.1f64, 2.2, 3.3, 4.4, 5.5]);
assert!((16.5 - sum_primitive(&a).unwrap()).abs() < f64::EPSILON);
}

#[test]
fn test_primitive_array_sum_with_nulls() {
let a = Int32Array::from(&[None, Some(2), Some(3), None, Some(5)]);
assert_eq!(10, sum_primitive(&a).unwrap());
}

#[test]
fn test_primitive_array_sum_all_nulls() {
let a = Int32Array::from(&[None, None, None]);
assert_eq!(None, sum_primitive(&a));
}

#[test]
fn test_primitive_array_sum_large_64() {
let a: Int64Array = (1..=100)
.map(|i| if i % 3 == 0 { Some(i) } else { None })
.collect();
let b: Int64Array = (1..=100)
.map(|i| if i % 3 == 0 { Some(0) } else { Some(i) })
.collect();
// create an array that actually has non-zero values at the invalid indices
let c = arithmetics::basic::add::add(&a, &b).unwrap();
assert_eq!(
Some((1..=100).filter(|i| i % 3 == 0).sum()),
sum_primitive(&c)
);
}
}
Loading