Skip to content

Commit 2c31a75

Browse files
chore: use vx array assert eq macro 2 (#5077)
Signed-off-by: Joe Isaacs <[email protected]>
1 parent 60ce4b5 commit 2c31a75

File tree

12 files changed

+164
-192
lines changed

12 files changed

+164
-192
lines changed

encodings/fastlanes/src/bitpacking/compute/cast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ mod tests {
7979

8080
let decoded = casted.to_primitive();
8181
assert_arrays_eq!(
82-
decoded,
82+
decoded.as_ref(),
8383
PrimitiveArray::from_iter([10u32, 20, 30, 40, 50, 60])
8484
);
8585
}

encodings/fastlanes/src/rle/compress.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -285,15 +285,13 @@ mod test {
285285
fn test_partial_last_chunk() {
286286
// Test array with partial last chunk (not divisible by 1024)
287287
let values: Buffer<u32> = (0..1500).map(|i| (i / 100) as u32).collect();
288-
let expected: Vec<u32> = (0..1500).map(|i| (i / 100) as u32).collect();
289288
let array = values.into_array();
290289

291290
let encoded = RLEArray::encode(&array.to_primitive()).unwrap();
292291
let decoded = encoded.to_primitive();
293292

294293
assert_eq!(encoded.len(), 1500);
295-
let expected_array = PrimitiveArray::from_iter(expected);
296-
assert_arrays_eq!(decoded, expected_array);
294+
assert_arrays_eq!(decoded, array);
297295
// 2 chunks: 1024 + 476 elements
298296
assert_eq!(encoded.values_idx_offsets().len(), 2);
299297
}
@@ -302,15 +300,13 @@ mod test {
302300
fn test_two_full_chunks() {
303301
// Array that spans exactly 2 chunks (2048 elements)
304302
let values: Buffer<u32> = (0..2048).map(|i| (i / 100) as u32).collect();
305-
let expected: Vec<u32> = (0..2048).map(|i| (i / 100) as u32).collect();
306303
let array = values.into_array();
307304

308305
let encoded = RLEArray::encode(&array.to_primitive()).unwrap();
309306
let decoded = encoded.to_primitive();
310307

311308
assert_eq!(encoded.len(), 2048);
312-
let expected_array = PrimitiveArray::from_iter(expected);
313-
assert_arrays_eq!(decoded, expected_array);
309+
assert_arrays_eq!(decoded, array);
314310
assert_eq!(encoded.values_idx_offsets().len(), 2);
315311
}
316312

vortex-btrblocks/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ vortex-zigzag = { workspace = true }
4141
[dev-dependencies]
4242
divan = { workspace = true }
4343
env_logger = "0.11"
44+
vortex-array = { workspace = true, features = ["test-harness"] }
4445

4546
[features]
4647
# This feature enabled unstable encodings for which we don't guarantee stability.

vortex-btrblocks/src/float.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ mod tests {
379379

380380
use vortex_array::arrays::PrimitiveArray;
381381
use vortex_array::validity::Validity;
382-
use vortex_array::{Array, IntoArray, ToCanonical};
382+
use vortex_array::{Array, IntoArray, ToCanonical, assert_arrays_eq};
383383
use vortex_buffer::{Buffer, buffer_mut};
384384

385385
use crate::float::{FloatCompressor, RLE_FLOAT_SCHEME};
@@ -426,7 +426,8 @@ mod tests {
426426
let stats = crate::float::FloatStats::generate(&array);
427427
let compressed = RLE_FLOAT_SCHEME.compress(&stats, false, 3, &[]).unwrap();
428428

429-
let decoded = compressed.to_primitive();
430-
assert_eq!(decoded.as_slice::<f32>(), values.as_slice());
429+
let decoded = compressed;
430+
let expected = Buffer::copy_from(&values).into_array();
431+
assert_arrays_eq!(decoded.as_ref(), expected.as_ref());
431432
}
432433
}

vortex-btrblocks/src/float/dictionary.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ impl_encode!(f64, u64);
9797
mod tests {
9898
use vortex_array::arrays::{BoolArray, PrimitiveArray};
9999
use vortex_array::validity::Validity;
100-
use vortex_array::{Array, IntoArray, ToCanonical};
100+
use vortex_array::{Array, IntoArray, assert_arrays_eq};
101101
use vortex_buffer::buffer;
102102

103103
use crate::CompressorStats;
@@ -117,10 +117,15 @@ mod tests {
117117
assert_eq!(dict_array.values().len(), 2);
118118
assert_eq!(dict_array.codes().len(), 5);
119119

120-
let undict = dict_array.to_primitive();
120+
let undict = dict_array;
121121

122122
// We just use code zero but it doesn't really matter.
123123
// We can just shove a whole validity buffer in there instead.
124-
assert_eq!(undict.as_slice::<f32>(), &[1f32, 2f32, 2f32, 1f32, 1f32]);
124+
let expected = PrimitiveArray::new(
125+
buffer![1f32, 2f32, 2f32, 1f32, 1f32],
126+
Validity::Array(BoolArray::from_iter([true, true, true, false, true]).into_array()),
127+
)
128+
.into_array();
129+
assert_arrays_eq!(undict.as_ref(), expected.as_ref());
125130
}
126131
}

vortex-btrblocks/src/integer.rs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ mod tests {
758758
use vortex_array::arrays::PrimitiveArray;
759759
use vortex_array::validity::Validity;
760760
use vortex_array::vtable::ValidityHelper;
761-
use vortex_array::{Array, IntoArray, ToCanonical};
761+
use vortex_array::{Array, IntoArray, ToCanonical, assert_arrays_eq};
762762
use vortex_buffer::{Buffer, BufferMut, buffer, buffer_mut};
763763
use vortex_dict::DictEncoding;
764764
use vortex_sequence::SequenceEncoding;
@@ -845,10 +845,11 @@ mod tests {
845845
.compress(&IntegerStats::generate(&array), false, 3, &[])
846846
.unwrap();
847847
assert_eq!(compressed.encoding_id(), SparseEncoding.id());
848-
let decoded = compressed.to_primitive();
849-
let expected = [189u8, 189, 189, 0, 0];
850-
assert_eq!(decoded.as_slice::<u8>(), &expected);
851-
assert_eq!(decoded.validity(), array.validity());
848+
let decoded = compressed.clone();
849+
let expected =
850+
PrimitiveArray::new(buffer![189u8, 189, 189, 0, 0], array.validity().clone())
851+
.into_array();
852+
assert_arrays_eq!(decoded.as_ref(), expected.as_ref());
852853
}
853854

854855
#[test]
@@ -863,10 +864,13 @@ mod tests {
863864
.compress(&IntegerStats::generate(&array), false, 3, &[])
864865
.unwrap();
865866
assert_eq!(compressed.encoding_id(), SparseEncoding.id());
866-
let decoded = compressed.to_primitive();
867-
let expected = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 46];
868-
assert_eq!(decoded.as_slice::<u8>(), &expected);
869-
assert_eq!(decoded.validity(), array.validity());
867+
let decoded = compressed.clone();
868+
let expected = PrimitiveArray::new(
869+
buffer![0u8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 46],
870+
array.validity().clone(),
871+
)
872+
.into_array();
873+
assert_arrays_eq!(decoded.as_ref(), expected.as_ref());
870874
}
871875

872876
#[test]
@@ -877,8 +881,9 @@ mod tests {
877881
.compress(&IntegerStats::generate(&array), false, 3, &[])
878882
.unwrap();
879883
assert_eq!(compressed.encoding_id(), SequenceEncoding.id());
880-
let decoded = compressed.to_primitive();
881-
assert_eq!(decoded.as_slice::<i32>(), values.as_slice());
884+
let decoded = compressed;
885+
let expected = PrimitiveArray::from_option_iter(values.into_iter().map(Some)).into_array();
886+
assert_arrays_eq!(decoded.as_ref(), expected.as_ref());
882887
}
883888

884889
#[test]
@@ -893,7 +898,8 @@ mod tests {
893898
.compress(&IntegerStats::generate(&array), false, 3, &[])
894899
.unwrap();
895900

896-
let decoded = compressed.to_primitive();
897-
assert_eq!(decoded.as_slice::<i32>(), values.as_slice());
901+
let decoded = compressed;
902+
let expected = Buffer::copy_from(&values).into_array();
903+
assert_arrays_eq!(decoded.as_ref(), expected.as_ref());
898904
}
899905
}

vortex-btrblocks/src/integer/dictionary.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ impl_encode!(i64);
111111
mod tests {
112112
use vortex_array::arrays::{BoolArray, PrimitiveArray};
113113
use vortex_array::validity::Validity;
114-
use vortex_array::{Array, IntoArray, ToCanonical};
114+
use vortex_array::{Array, IntoArray, assert_arrays_eq};
115115
use vortex_buffer::buffer;
116116

117117
use crate::CompressorStats;
@@ -131,10 +131,15 @@ mod tests {
131131
assert_eq!(dict_array.values().len(), 2);
132132
assert_eq!(dict_array.codes().len(), 5);
133133

134-
let undict = dict_array.to_primitive();
134+
let undict = dict_array;
135135

136136
// We just use code zero, but it doesn't really matter.
137137
// We can just shove a whole validity buffer in there instead.
138-
assert_eq!(undict.as_slice::<i32>(), &[100i32, 200, 100, 100, 100]);
138+
let expected = PrimitiveArray::new(
139+
buffer![100i32, 200, 100, 100, 100],
140+
Validity::Array(BoolArray::from_iter([true, true, true, false, true]).into_array()),
141+
)
142+
.into_array();
143+
assert_arrays_eq!(undict.as_ref(), expected.as_ref());
139144
}
140145
}

0 commit comments

Comments
 (0)