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

Commit

Permalink
Added more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecarleitao committed May 31, 2022
1 parent 0dbe922 commit 72601b6
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 8 deletions.
7 changes: 3 additions & 4 deletions src/array/fixed_size_binary/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@ impl<'a, T: FixedSizeBinaryValues> Iterator for FixedSizeBinaryValuesIter<'a, T>
}
let index = self.index;
let r = Some(unsafe {
std::slice::from_raw_parts(
self.array.values().as_ptr().add(index * self.array.size()),
self.array.size(),
)
self.array
.values()
.get_unchecked(index * self.array.size()..(index + 1) * self.array.size())
});
self.index += 1;
r
Expand Down
22 changes: 19 additions & 3 deletions tests/it/array/primitive/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ fn from_and_into_data() {
assert_eq!(c, Some(MutableBitmap::from([true, false])));
}

#[test]
fn from_vec() {
let a = MutablePrimitiveArray::from_vec(Vec::from([1i32, 0]));
assert_eq!(a.len(), 2);
}

#[test]
fn to() {
let a = MutablePrimitiveArray::from_data(
Expand Down Expand Up @@ -152,9 +158,10 @@ fn as_box() {
fn shrink_to_fit_and_capacity() {
let mut a = MutablePrimitiveArray::<i32>::with_capacity(100);
a.push(Some(1));
a.try_push(None).unwrap();
assert!(a.capacity() >= 100);
a.shrink_to_fit();
assert_eq!(a.capacity(), 1);
(&mut a as &mut dyn MutableArray).shrink_to_fit();
assert_eq!(a.capacity(), 2);
}

#[test]
Expand All @@ -168,7 +175,16 @@ fn only_nulls() {

#[test]
fn from_trusted_len() {
let a = MutablePrimitiveArray::<i32>::from_trusted_len_iter(vec![Some(1), None].into_iter());
let a =
MutablePrimitiveArray::<i32>::from_trusted_len_iter(vec![Some(1), None, None].into_iter());
let a: PrimitiveArray<i32> = a.into();
assert_eq!(a.validity(), Some(&Bitmap::from([true, false, false])));

let a = unsafe {
MutablePrimitiveArray::<i32>::from_trusted_len_iter_unchecked(
vec![Some(1), None].into_iter(),
)
};
let a: PrimitiveArray<i32> = a.into();
assert_eq!(a.validity(), Some(&Bitmap::from([true, false])));
}
Expand Down
78 changes: 77 additions & 1 deletion tests/it/ffi/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ fn bool() -> Result<()> {
test_round_trip(data)
}

#[test]
fn bool_nullable_sliced() -> Result<()> {
let bitmap = Bitmap::from([true, false, false, true]).slice(1, 3);
let data = BooleanArray::try_new(DataType::Boolean, [true, true, false].into(), Some(bitmap))?;
test_round_trip(data)
}

#[test]
fn u32_nullable() -> Result<()> {
let data = Int32Array::from(&[Some(2), None, Some(1), None]);
Expand All @@ -81,6 +88,13 @@ fn u32() -> Result<()> {
test_round_trip(data)
}

#[test]
fn u32_sliced() -> Result<()> {
let bitmap = Bitmap::from([true, false, false, true]).slice(1, 3);
let data = Int32Array::try_new(DataType::Int32, vec![1, 2, 3].into(), Some(bitmap))?;
test_round_trip(data)
}

#[test]
fn decimal() -> Result<()> {
let data = Int128Array::from_slice(&[1, 0, 2, 0]);
Expand Down Expand Up @@ -114,6 +128,18 @@ fn utf8() -> Result<()> {
test_round_trip(data)
}

#[test]
fn utf8_sliced() -> Result<()> {
let bitmap = Bitmap::from([true, false, false, true]).slice(1, 3);
let data = Utf8Array::<i32>::try_new(
DataType::Utf8,
vec![0, 1, 1, 2].into(),
b"ab".to_vec().into(),
Some(bitmap),
)?;
test_round_trip(data)
}

#[test]
fn large_utf8() -> Result<()> {
let data = Utf8Array::<i64>::from(&vec![Some("a"), None, Some("bb"), None]);
Expand All @@ -133,6 +159,18 @@ fn binary() -> Result<()> {
test_round_trip(data)
}

#[test]
fn binary_sliced() -> Result<()> {
let bitmap = Bitmap::from([true, false, false, true]).slice(1, 3);
let data = BinaryArray::<i32>::try_new(
DataType::Binary,
vec![0, 1, 1, 2].into(),
b"ab".to_vec().into(),
Some(bitmap),
)?;
test_round_trip(data)
}

#[test]
fn large_binary() -> Result<()> {
let data =
Expand Down Expand Up @@ -160,6 +198,17 @@ fn fixed_size_binary_nullable() -> Result<()> {
test_round_trip(data)
}

#[test]
fn fixed_size_binary_sliced() -> Result<()> {
let bitmap = Bitmap::from([true, false, false, true]).slice(1, 3);
let data = FixedSizeBinaryArray::try_new(
DataType::FixedSizeBinary(2),
b"ababab".to_vec().into(),
Some(bitmap),
)?;
test_round_trip(data)
}

#[test]
fn list() -> Result<()> {
let data = vec![
Expand All @@ -176,6 +225,20 @@ fn list() -> Result<()> {
test_round_trip(array)
}

#[test]
fn list_sliced() -> Result<()> {
let bitmap = Bitmap::from([true, false, false, true]).slice(1, 3);

let array = ListArray::<i32>::try_new(
DataType::List(Box::new(Field::new("a", DataType::Int32, true))),
vec![0, 1, 1, 2].into(),
Arc::new(PrimitiveArray::<i32>::from_vec(vec![1, 2])),
Some(bitmap),
)?;

test_round_trip(array)
}

#[test]
fn large_list() -> Result<()> {
let data = vec![
Expand All @@ -193,7 +256,7 @@ fn large_list() -> Result<()> {
}

#[test]
fn fixed_list() -> Result<()> {
fn fixed_size_list() -> Result<()> {
let data = vec![
Some(vec![Some(1i32), Some(2), Some(3)]),
None,
Expand All @@ -208,6 +271,19 @@ fn fixed_list() -> Result<()> {
test_round_trip(array)
}

#[test]
fn fixed_size_list_sliced() -> Result<()> {
let bitmap = Bitmap::from([true, false, false, true]).slice(1, 3);

let array = FixedSizeListArray::try_new(
DataType::FixedSizeList(Box::new(Field::new("a", DataType::Int32, true)), 2),
Arc::new(PrimitiveArray::<i32>::from_vec(vec![1, 2, 3, 4, 5, 6])),
Some(bitmap),
)?;

test_round_trip(array)
}

#[test]
fn list_list() -> Result<()> {
let data = vec![
Expand Down

0 comments on commit 72601b6

Please sign in to comment.