Skip to content

Commit 28a2252

Browse files
authored
chore: validate the error type during testing (#6014)
The current test only checks for errors, but doesn't check the error type. Perhaps this could be improved. example ``` fn test_primitive_array_validation_failure_length_mismatch() { // Invalid case: validity length doesn't match buffer length. let buffer = Buffer::from_iter([1i32, 2, 3]); let validity = Validity::from_iter([true, false]); // Length 2, buffer is length 3. let result = PrimitiveArray::try_new(buffer, validity); assert!(matches!(result, Err(VortexError::InvalidArgument(_, _)))); assert!(result.is_err()); } ``` Signed-off-by: cancaicai <[email protected]>
1 parent 7373931 commit 28a2252

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

vortex-array/src/arrays/validation_tests.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ mod tests {
1616
use vortex_dtype::DType;
1717
use vortex_dtype::Nullability;
1818
use vortex_dtype::PType;
19+
use vortex_error::VortexError;
1920
use vortex_vector::binaryview::BinaryView;
2021

2122
use crate::IntoArray;
@@ -37,6 +38,8 @@ mod tests {
3738
let chunk1 = buffer![1i32, 2, 3].into_array();
3839
let chunk2 = buffer![4i64, 5, 6].into_array();
3940
let result = ChunkedArray::try_new(vec![chunk1, chunk2], PType::I32.into());
41+
42+
assert!(matches!(result, Err(VortexError::MismatchedTypes(_, _, _))));
4043
assert!(result.is_err());
4144
}
4245

@@ -56,6 +59,8 @@ mod tests {
5659
let validity = Validity::from_iter([true, false]); // Length 2, buffer is length 3.
5760
let decimal_dtype = vortex_dtype::DecimalDType::new(10, 2);
5861
let result = DecimalArray::try_new(buffer, decimal_dtype, validity);
62+
63+
assert!(matches!(result, Err(VortexError::InvalidArgument(_, _))));
5964
assert!(result.is_err());
6065
}
6166

@@ -73,6 +78,8 @@ mod tests {
7378
let buffer = Buffer::from_iter([1i32, 2, 3]);
7479
let validity = Validity::from_iter([true, false]); // Length 2, buffer is length 3.
7580
let result = PrimitiveArray::try_new(buffer, validity);
81+
82+
assert!(matches!(result, Err(VortexError::InvalidArgument(_, _))));
7683
assert!(result.is_err());
7784
}
7885

@@ -101,6 +108,8 @@ mod tests {
101108
DType::Binary(Nullability::NonNullable),
102109
Validity::NonNullable,
103110
);
111+
112+
assert!(matches!(result, Err(VortexError::InvalidArgument(_, _))));
104113
assert!(result.is_err());
105114
}
106115

@@ -119,6 +128,8 @@ mod tests {
119128
let elements = buffer![1i32, 2, 3].into_array();
120129
let offsets = buffer![0i64, 2, 5].into_array(); // 5 > 3.
121130
let result = ListArray::try_new(elements, offsets, Validity::NonNullable);
131+
132+
assert!(matches!(result, Err(VortexError::InvalidArgument(_, _))));
122133
assert!(result.is_err());
123134
}
124135

@@ -135,6 +146,8 @@ mod tests {
135146
// Invalid case: elements length doesn't match list_size * len.
136147
let elements = buffer![1i32, 2, 3, 4, 5].into_array(); // 5 elements.
137148
let result = FixedSizeListArray::try_new(elements, 2, Validity::NonNullable, 3); // Expects 2 * 3 = 6.
149+
150+
assert!(matches!(result, Err(VortexError::InvalidArgument(_, _))));
138151
assert!(result.is_err());
139152
}
140153

@@ -171,6 +184,8 @@ mod tests {
171184
DType::Binary(Nullability::NonNullable),
172185
Validity::NonNullable,
173186
);
187+
188+
assert!(matches!(result, Err(VortexError::InvalidArgument(_, _))));
174189
assert!(result.is_err());
175190
}
176191

@@ -193,6 +208,8 @@ mod tests {
193208
let fields = vec![field1, field2];
194209
let names = ["a", "b"];
195210
let result = StructArray::try_new(names.into(), fields, 3, Validity::NonNullable);
211+
212+
assert!(matches!(result, Err(VortexError::InvalidArgument(_, _))));
196213
assert!(result.is_err());
197214
}
198215
}

0 commit comments

Comments
 (0)