vortex_array/arrays/
assertions.rs1use std::fmt::Display;
5
6use itertools::Itertools;
7
8pub fn format_indices<I: IntoIterator<Item = usize>>(indices: I) -> impl Display {
9 indices.into_iter().format(",")
10}
11
12#[macro_export]
13macro_rules! assert_arrays_eq {
14 ($left:expr, $right:expr) => {{
15 let left = $left.clone();
16 let right = $right.clone();
17 if left.dtype() != right.dtype() {
18 panic!(
19 "assertion left == right failed: arrays differ in type: {} != {}.\n left: {}\n right: {}",
20 left.dtype(),
21 right.dtype(),
22 left.display_values(),
23 right.display_values()
24 )
25 }
26
27 if left.len() != right.len() {
28 panic!(
29 "assertion left == right failed: arrays differ in length: {} != {}.\n left: {}\n right: {}",
30 left.len(),
31 right.len(),
32 left.display_values(),
33 right.display_values()
34 )
35 }
36 let n = left.len();
37 let mismatched_indices = (0..n)
38 .filter(|i| left.scalar_at(*i) != right.scalar_at(*i))
39 .collect::<Vec<_>>();
40 if mismatched_indices.len() != 0 {
41 panic!(
42 "assertion left == right failed: arrays do not match at indices: {}.\n left: {}\n right: {}",
43 $crate::arrays::format_indices(mismatched_indices),
44 left.display_values(),
45 right.display_values()
46 )
47 }
48 }};
49}