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

Commit

Permalink
More tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecarleitao committed Oct 20, 2021
1 parent 71c6f8f commit 54a2265
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions tests/it/ffi.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use arrow2::array::*;
use arrow2::bitmap::Bitmap;
use arrow2::datatypes::{DataType, Field, TimeUnit};
use arrow2::{error::Result, ffi};
use std::collections::BTreeMap;
use std::sync::Arc;

fn test_round_trip(expected: impl Array + Clone + 'static) -> Result<()> {
let array: Arc<dyn Array> = Arc::new(expected.clone());
fn _test_round_trip(array: Arc<dyn Array>, expected: Box<dyn Array>) -> Result<()> {
let field = Field::new("a", array.data_type().clone(), true);
let expected = Box::new(expected) as Box<dyn Array>;

let array_ptr = Box::new(ffi::Ffi_ArrowArray::empty());
let schema_ptr = Box::new(ffi::Ffi_ArrowSchema::empty());
Expand All @@ -32,6 +31,15 @@ fn test_round_trip(expected: impl Array + Clone + 'static) -> Result<()> {
Ok(())
}

fn test_round_trip(expected: impl Array + Clone + 'static) -> Result<()> {
let array: Arc<dyn Array> = Arc::new(expected.clone());
let expected = Box::new(expected) as Box<dyn Array>;
_test_round_trip(array.clone(), clone(expected.as_ref()))?;

// sliced
_test_round_trip(array.slice(1, 2).into(), expected.slice(1, 2))
}

fn test_round_trip_schema(field: Field) -> Result<()> {
// create a `ArrowArray` from the data.
let schema_ptr = Box::new(ffi::Ffi_ArrowSchema::empty());
Expand Down Expand Up @@ -138,6 +146,17 @@ fn list_list() -> Result<()> {
test_round_trip(array)
}

#[test]
fn struct_() -> Result<()> {
let data_type = DataType::Struct(vec![Field::new("a", DataType::Int32, true)]);
let values = vec![Arc::new(Int32Array::from([Some(1), None, Some(3)])) as Arc<dyn Array>];
let validity = Bitmap::from([true, false, true]);

let array = StructArray::from_data(data_type, values, validity.into());

test_round_trip(array)
}

#[test]
fn dict() -> Result<()> {
let data = vec![Some("a"), Some("a"), None, Some("b")];
Expand Down

0 comments on commit 54a2265

Please sign in to comment.