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

Commit

Permalink
Moved tests to tests/ (#389)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecarleitao authored Sep 7, 2021
1 parent f28427d commit b9218a5
Show file tree
Hide file tree
Showing 21 changed files with 1,309 additions and 1,329 deletions.
134 changes: 0 additions & 134 deletions src/compute/boolean_kleene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,137 +183,3 @@ pub fn and(lhs: &BooleanArray, rhs: &BooleanArray) -> Result<BooleanArray> {
validity,
))
}

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

#[test]
fn and_generic() {
let lhs = BooleanArray::from(&[
None,
None,
None,
Some(false),
Some(false),
Some(false),
Some(true),
Some(true),
Some(true),
]);
let rhs = BooleanArray::from(&[
None,
Some(false),
Some(true),
None,
Some(false),
Some(true),
None,
Some(false),
Some(true),
]);
let c = and(&lhs, &rhs).unwrap();

let expected = BooleanArray::from(&[
None,
Some(false),
None,
Some(false),
Some(false),
Some(false),
None,
Some(false),
Some(true),
]);

assert_eq!(c, expected);
}

#[test]
fn or_generic() {
let a = BooleanArray::from(&[
None,
None,
None,
Some(false),
Some(false),
Some(false),
Some(true),
Some(true),
Some(true),
]);
let b = BooleanArray::from(&[
None,
Some(false),
Some(true),
None,
Some(false),
Some(true),
None,
Some(false),
Some(true),
]);
let c = or(&a, &b).unwrap();

let expected = BooleanArray::from(&[
None,
None,
Some(true),
None,
Some(false),
Some(true),
Some(true),
Some(true),
Some(true),
]);

assert_eq!(c, expected);
}

#[test]
fn or_right_nulls() {
let a = BooleanArray::from_slice(&[false, false, false, true, true, true]);

let b = BooleanArray::from(&[Some(true), Some(false), None, Some(true), Some(false), None]);

let c = or(&a, &b).unwrap();

let expected = BooleanArray::from(&[
Some(true),
Some(false),
None,
Some(true),
Some(true),
Some(true),
]);

assert_eq!(c, expected);
}

#[test]
fn or_left_nulls() {
let a = BooleanArray::from(vec![
Some(true),
Some(false),
None,
Some(true),
Some(false),
None,
]);

let b = BooleanArray::from_slice(&[false, false, false, true, true, true]);

let c = or(&a, &b).unwrap();

let expected = BooleanArray::from(vec![
Some(true),
Some(false),
None,
Some(true),
Some(true),
Some(true),
]);

assert_eq!(c, expected);
}
}
92 changes: 0 additions & 92 deletions src/compute/length.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,95 +79,3 @@ pub fn length(array: &dyn Array) -> Result<Box<dyn Array>> {
pub fn can_length(data_type: &DataType) -> bool {
matches!(data_type, DataType::Utf8 | DataType::LargeUtf8)
}

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

fn length_test_string<O: Offset>() {
vec![
(
vec![Some("hello"), Some(" "), None],
vec![Some(5usize), Some(1), None],
),
(vec![Some("💖")], vec![Some(4)]),
]
.into_iter()
.for_each(|(input, expected)| {
let array = Utf8Array::<O>::from(&input);
let result = length(&array).unwrap();

let data_type = if O::is_large() {
DataType::Int64
} else {
DataType::Int32
};

let expected = expected
.into_iter()
.map(|x| x.map(|x| O::from_usize(x).unwrap()))
.collect::<PrimitiveArray<O>>()
.to(data_type);
assert_eq!(expected, result.as_ref());
})
}

#[test]
fn large_utf8() {
length_test_string::<i64>()
}

#[test]
fn utf8() {
length_test_string::<i32>()
}

#[test]
fn consistency() {
use crate::array::new_null_array;
use crate::datatypes::DataType::*;
use crate::datatypes::TimeUnit;

let datatypes = vec![
Null,
Boolean,
UInt8,
UInt16,
UInt32,
UInt64,
Int8,
Int16,
Int32,
Int64,
Float32,
Float64,
Timestamp(TimeUnit::Second, None),
Timestamp(TimeUnit::Millisecond, None),
Timestamp(TimeUnit::Microsecond, None),
Timestamp(TimeUnit::Nanosecond, None),
Time64(TimeUnit::Microsecond),
Time64(TimeUnit::Nanosecond),
Date32,
Time32(TimeUnit::Second),
Time32(TimeUnit::Millisecond),
Date64,
Utf8,
LargeUtf8,
Binary,
LargeBinary,
Duration(TimeUnit::Second),
Duration(TimeUnit::Millisecond),
Duration(TimeUnit::Microsecond),
Duration(TimeUnit::Nanosecond),
];

datatypes.into_iter().for_each(|d1| {
let array = new_null_array(d1.clone(), 10);
if can_length(&d1) {
assert!(length(array.as_ref()).is_ok());
} else {
assert!(length(array.as_ref()).is_err());
}
});
}
}
48 changes: 0 additions & 48 deletions src/compute/like.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,51 +293,3 @@ pub fn like_binary_scalar<O: Offset>(lhs: &BinaryArray<O>, rhs: &[u8]) -> Result
pub fn nlike_binary_scalar<O: Offset>(lhs: &BinaryArray<O>, rhs: &[u8]) -> Result<BooleanArray> {
a_like_binary_scalar(lhs, rhs, |x| !x)
}

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

#[test]
fn test_like_binary() -> Result<()> {
let strings = BinaryArray::<i32>::from_slice(&["Arrow", "Arrow", "Arrow", "Arrow", "Ar"]);
let patterns = BinaryArray::<i32>::from_slice(&["A%", "B%", "%r_ow", "A_", "A_"]);
let result = like_binary(&strings, &patterns).unwrap();
assert_eq!(
result,
BooleanArray::from_slice(&[true, false, true, false, true])
);
Ok(())
}

#[test]
fn test_nlike_binary() -> Result<()> {
let strings = BinaryArray::<i32>::from_slice(&["Arrow", "Arrow", "Arrow", "Arrow", "Ar"]);
let patterns = BinaryArray::<i32>::from_slice(&["A%", "B%", "%r_ow", "A_", "A_"]);
let result = nlike_binary(&strings, &patterns).unwrap();
assert_eq!(
result,
BooleanArray::from_slice(&[false, true, false, true, false])
);
Ok(())
}

#[test]
fn test_like_binary_scalar() -> Result<()> {
let array = BinaryArray::<i32>::from_slice(&["Arrow", "Arrow", "Arrow", "BA"]);
let result = like_binary_scalar(&array, b"A%").unwrap();
assert_eq!(result, BooleanArray::from_slice(&[true, true, true, false]));
Ok(())
}

#[test]
fn test_nlike_binary_scalar() -> Result<()> {
let array = BinaryArray::<i32>::from_slice(&["Arrow", "Arrow", "Arrow", "BA"]);
let result = nlike_binary_scalar(&array, "A%".as_bytes()).unwrap();
assert_eq!(
result,
BooleanArray::from_slice(&[false, false, false, true])
);
Ok(())
}
}
15 changes: 0 additions & 15 deletions src/compute/limit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,3 @@ pub fn limit(array: &dyn Array, num_elements: usize) -> Box<dyn Array> {
let lim = num_elements.min(array.len());
array.slice(0, lim)
}

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

#[test]
fn test_limit_array() {
let a = Int32Array::from_slice(&[5, 6, 7, 8, 9]);
let b = limit(&a, 3);
let c = b.as_ref().as_any().downcast_ref::<Int32Array>().unwrap();
let expected = Int32Array::from_slice(&[5, 6, 7]);
assert_eq!(&expected, c);
}
}
Loading

0 comments on commit b9218a5

Please sign in to comment.