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

Commit

Permalink
Moved compute tests to tests/ (#388)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecarleitao authored Sep 7, 2021
1 parent c44760c commit f28427d
Show file tree
Hide file tree
Showing 13 changed files with 1,336 additions and 1,536 deletions.
343 changes: 0 additions & 343 deletions src/compute/boolean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,346 +145,3 @@ pub fn is_not_null(input: &dyn Array) -> BooleanArray {
};
BooleanArray::from_data(DataType::Boolean, values, None)
}

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

use crate::array::*;

#[test]
fn test_bool_array_and() {
let a = BooleanArray::from_slice(vec![false, false, true, true]);
let b = BooleanArray::from_slice(vec![false, true, false, true]);
let c = and(&a, &b).unwrap();

let expected = BooleanArray::from_slice(vec![false, false, false, true]);

assert_eq!(c, expected);
}

#[test]
fn test_bool_array_or() {
let a = BooleanArray::from_slice(vec![false, false, true, true]);
let b = BooleanArray::from_slice(vec![false, true, false, true]);
let c = or(&a, &b).unwrap();

let expected = BooleanArray::from_slice(vec![false, true, true, true]);

assert_eq!(c, expected);
}

#[test]
fn test_bool_array_or_validity() {
let a = BooleanArray::from(vec![
None,
None,
None,
Some(false),
Some(false),
Some(false),
Some(true),
Some(true),
Some(true),
]);
let b = BooleanArray::from(vec![
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(vec![
None,
None,
None,
None,
Some(false),
Some(true),
None,
Some(true),
Some(true),
]);

assert_eq!(c, expected);
}

#[test]
fn test_bool_array_not() {
let a = BooleanArray::from_slice(vec![false, true]);
let c = not(&a);

let expected = BooleanArray::from_slice(vec![true, false]);

assert_eq!(c, expected);
}

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

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

assert_eq!(c, expected);
}

#[test]
fn test_bool_array_and_sliced_same_offset() {
let a = BooleanArray::from_slice(vec![
false, false, false, false, false, false, false, false, false, false, true, true,
]);
let b = BooleanArray::from_slice(vec![
false, false, false, false, false, false, false, false, false, true, false, true,
]);

let a = a.slice(8, 4);
let b = b.slice(8, 4);
let c = and(&a, &b).unwrap();

let expected = BooleanArray::from_slice(vec![false, false, false, true]);

assert_eq!(expected, c);
}

#[test]
fn test_bool_array_and_sliced_same_offset_mod8() {
let a = BooleanArray::from_slice(vec![
false, false, true, true, false, false, false, false, false, false, false, false,
]);
let b = BooleanArray::from_slice(vec![
false, false, false, false, false, false, false, false, false, true, false, true,
]);

let a = a.slice(0, 4);
let b = b.slice(8, 4);

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

let expected = BooleanArray::from_slice(vec![false, false, false, true]);

assert_eq!(expected, c);
}

#[test]
fn test_bool_array_and_sliced_offset1() {
let a = BooleanArray::from_slice(vec![
false, false, false, false, false, false, false, false, false, false, true, true,
]);
let b = BooleanArray::from_slice(vec![false, true, false, true]);

let a = a.slice(8, 4);

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

let expected = BooleanArray::from_slice(vec![false, false, false, true]);

assert_eq!(expected, c);
}

#[test]
fn test_bool_array_and_sliced_offset2() {
let a = BooleanArray::from_slice(vec![false, false, true, true]);
let b = BooleanArray::from_slice(vec![
false, false, false, false, false, false, false, false, false, true, false, true,
]);

let b = b.slice(8, 4);

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

let expected = BooleanArray::from_slice(vec![false, false, false, true]);

assert_eq!(expected, c);
}

#[test]
fn test_bool_array_and_validity_offset() {
let a = BooleanArray::from(vec![None, Some(false), Some(true), None, Some(true)]);
let a = a.slice(1, 4);
let a = a.as_any().downcast_ref::<BooleanArray>().unwrap();

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

let b = b.slice(2, 4);
let b = b.as_any().downcast_ref::<BooleanArray>().unwrap();

let c = and(a, b).unwrap();

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

assert_eq!(expected, c);
}

#[test]
fn test_nonnull_array_is_null() {
let a = Int32Array::from_slice(&[1, 2, 3, 4]);

let res = is_null(&a);

let expected = BooleanArray::from_slice(vec![false, false, false, false]);

assert_eq!(expected, res);
}

#[test]
fn test_nonnull_array_with_offset_is_null() {
let a = Int32Array::from_slice(vec![1, 2, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 3, 2, 1]);
let a = a.slice(8, 4);

let res = is_null(&a);

let expected = BooleanArray::from_slice(vec![false, false, false, false]);

assert_eq!(expected, res);
}

#[test]
fn test_nonnull_array_is_not_null() {
let a = Int32Array::from_slice(&[1, 2, 3, 4]);

let res = is_not_null(&a);

let expected = BooleanArray::from_slice(vec![true, true, true, true]);

assert_eq!(expected, res);
}

#[test]
fn test_nonnull_array_with_offset_is_not_null() {
let a = Int32Array::from_slice(&[1, 2, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 3, 2, 1]);
let a = a.slice(8, 4);

let res = is_not_null(&a);

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

assert_eq!(expected, res);
}

#[test]
fn test_nullable_array_is_null() {
let a = Int32Array::from(vec![Some(1), None, Some(3), None]);

let res = is_null(&a);

let expected = BooleanArray::from_slice(vec![false, true, false, true]);

assert_eq!(expected, res);
}

#[test]
fn test_nullable_array_with_offset_is_null() {
let a = Int32Array::from(vec![
None,
None,
None,
None,
None,
None,
None,
None,
// offset 8, previous None values are skipped by the slice
Some(1),
None,
Some(2),
None,
Some(3),
Some(4),
None,
None,
]);
let a = a.slice(8, 4);

let res = is_null(&a);

let expected = BooleanArray::from_slice(vec![false, true, false, true]);

assert_eq!(expected, res);
}

#[test]
fn test_nullable_array_is_not_null() {
let a = Int32Array::from(vec![Some(1), None, Some(3), None]);

let res = is_not_null(&a);

let expected = BooleanArray::from_slice(vec![true, false, true, false]);

assert_eq!(expected, res);
}

#[test]
fn test_nullable_array_with_offset_is_not_null() {
let a = Int32Array::from(vec![
None,
None,
None,
None,
None,
None,
None,
None,
// offset 8, previous None values are skipped by the slice
Some(1),
None,
Some(2),
None,
Some(3),
Some(4),
None,
None,
]);
let a = a.slice(8, 4);

let res = is_not_null(&a);

let expected = BooleanArray::from_slice(vec![true, false, true, false]);

assert_eq!(expected, res);
}
}
Loading

0 comments on commit f28427d

Please sign in to comment.