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

Commit

Permalink
Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecarleitao committed Sep 26, 2022
1 parent b8d5624 commit 65377eb
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ pub use null::NullArray;
pub use primitive::*;
pub use struct_::{MutableStructArray, StructArray};
pub use union::UnionArray;
pub use utf8::{MutableUtf8Array, Utf8Array, Utf8ValuesIter};
pub use utf8::{MutableUtf8Array, MutableUtf8ValuesArray, Utf8Array, Utf8ValuesIter};

pub(crate) use self::ffi::offset_buffers_children_dictionary;
pub(crate) use self::ffi::FromFfi;
Expand Down
1 change: 1 addition & 0 deletions tests/it/array/utf8/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use arrow2::{array::*, bitmap::Bitmap, buffer::Buffer, datatypes::DataType, error::Result};

mod mutable;
mod mutable_values;
mod to_mutable;

#[test]
Expand Down
81 changes: 81 additions & 0 deletions tests/it/array/utf8/mutable_values.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
use arrow2::array::MutableArray;
use arrow2::array::MutableUtf8ValuesArray;
use arrow2::datatypes::DataType;

#[test]
fn capacity() {
let mut b = MutableUtf8ValuesArray::<i32>::with_capacity(100);

assert_eq!(b.values().capacity(), 0);
assert!(b.offsets().capacity() >= 101);
b.shrink_to_fit();
assert!(b.offsets().capacity() < 101);
}

#[test]
fn offsets_must_be_monotonic_increasing() {
let offsets = vec![0, 5, 4];
let values = b"abbbbb".to_vec();
assert!(MutableUtf8ValuesArray::<i32>::try_new(DataType::Utf8, offsets, values).is_err());
}

#[test]
fn data_type_must_be_consistent() {
let offsets = vec![0, 4];
let values = b"abbb".to_vec();
assert!(MutableUtf8ValuesArray::<i32>::try_new(DataType::Int32, offsets, values).is_err());
}

#[test]
fn must_be_utf8() {
let offsets = vec![0, 2];
let values = vec![207, 128];
assert!(MutableUtf8ValuesArray::<i32>::try_new(DataType::Int32, offsets, values).is_err());
}

#[test]
fn as_box() {
let offsets = vec![0, 2];
let values = b"ab".to_vec();
let mut b = MutableUtf8ValuesArray::<i32>::try_new(DataType::Utf8, offsets, values).unwrap();
let _ = b.as_box();
}

#[test]
fn as_arc() {
let offsets = vec![0, 2];
let values = b"ab".to_vec();
let mut b = MutableUtf8ValuesArray::<i32>::try_new(DataType::Utf8, offsets, values).unwrap();
let _ = b.as_arc();
}

#[test]
fn extend_trusted_len() {
let offsets = vec![0, 2];
let values = b"ab".to_vec();
let mut b = MutableUtf8ValuesArray::<i32>::try_new(DataType::Utf8, offsets, values).unwrap();
b.extend_trusted_len(vec!["a", "b"].into_iter());

let offsets = vec![0, 2, 3, 4];
let values = b"abab".to_vec();
assert_eq!(
b.as_box(),
MutableUtf8ValuesArray::<i32>::try_new(DataType::Utf8, offsets, values)
.unwrap()
.as_box()
)
}

#[test]
fn from_trusted_len() {
let mut b = MutableUtf8ValuesArray::<i32>::from_trusted_len_iter(vec!["a", "b"].into_iter());

let offsets = vec![0, 1, 2];
let values = b"ab".to_vec();
assert_eq!(
b.as_box(),
MutableUtf8ValuesArray::<i32>::try_new(DataType::Utf8, offsets, values)
.unwrap()
.as_box()
)
}

0 comments on commit 65377eb

Please sign in to comment.