Skip to content

Commit a33f05f

Browse files
committed
Add unit tests.
1 parent 3d0efbc commit a33f05f

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

arrow-select/src/take.rs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,6 +1444,71 @@ mod tests {
14441444
assert_eq!(result.as_ref(), &expected);
14451445
}
14461446

1447+
fn _test_byte_view<T>()
1448+
where
1449+
T: ByteViewType,
1450+
str: AsRef<T::Native>,
1451+
T::Native: PartialEq,
1452+
{
1453+
let index = UInt32Array::from(vec![Some(3), None, Some(1), Some(3), Some(4), Some(2)]);
1454+
let array = {
1455+
// ["hello", "world", null, "large payload over 12 bytes", "lulu"]
1456+
let mut builder = GenericByteViewBuilder::<T>::new();
1457+
builder.append_value("hello");
1458+
builder.append_value("world");
1459+
builder.append_null();
1460+
builder.append_value("large payload over 12 bytes");
1461+
builder.append_value("lulu");
1462+
builder.finish()
1463+
};
1464+
1465+
let actual = take(&array, &index, None).unwrap();
1466+
1467+
assert_eq!(actual.len(), index.len());
1468+
1469+
let actual = actual
1470+
.as_any()
1471+
.downcast_ref::<GenericByteViewArray<T>>()
1472+
.unwrap();
1473+
1474+
let expected = {
1475+
// ["large payload over 12 bytes", null, "world", "large payload over 12 bytes", "lulu", null]
1476+
let mut builder = GenericByteViewBuilder::<T>::new();
1477+
builder.append_value("large payload over 12 bytes");
1478+
builder.append_null();
1479+
builder.append_value("world");
1480+
builder.append_value("large payload over 12 bytes");
1481+
builder.append_value("lulu");
1482+
builder.append_null();
1483+
builder.finish()
1484+
};
1485+
1486+
_assert_byte_view_equal(&actual, &expected);
1487+
}
1488+
1489+
fn _assert_byte_view_equal<T>(
1490+
array1: &GenericByteViewArray<T>,
1491+
array2: &GenericByteViewArray<T>,
1492+
) where
1493+
T: ByteViewType,
1494+
T::Native: PartialEq,
1495+
{
1496+
assert_eq!(array1.len(), array2.len());
1497+
for (v1, v2) in array1.iter().zip(array2.iter()) {
1498+
assert_eq!(v1, v2);
1499+
}
1500+
}
1501+
1502+
#[test]
1503+
fn test_take_string_view() {
1504+
_test_byte_view::<StringViewType>()
1505+
}
1506+
1507+
#[test]
1508+
fn test_take_binary_view() {
1509+
_test_byte_view::<BinaryViewType>()
1510+
}
1511+
14471512
macro_rules! test_take_list {
14481513
($offset_type:ty, $list_data_type:ident, $list_array_type:ident) => {{
14491514
// Construct a value array, [[0,0,0], [-1,-2,-1], [], [2,3]]

0 commit comments

Comments
 (0)