vortex_array/arrays/
assertions.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4#[macro_export]
5macro_rules! assert_arrays_eq {
6    ($left:expr, $right:expr) => {{
7       let left = $left.clone();
8       let right = $right.clone();
9       if left.dtype() != right.dtype() {
10            panic!(
11                "assertion left == right failed: arrays differ in type: {} != {}.\n  left: {}\n right: {}",
12                left.dtype(),
13                right.dtype(),
14                left.display_values(),
15                right.display_values()
16            )
17        }
18
19        if left.len() != right.len() {
20            panic!(
21                "assertion left == right failed: arrays differ in length: {} != {}.\n  left: {}\n right: {}",
22                left.len(),
23                right.len(),
24                left.display_values(),
25                right.display_values()
26            )
27        }
28        let n = left.len();
29        let mismatched_indices = (0..n)
30            .filter(|i| left.scalar_at(*i) != right.scalar_at(*i))
31            .collect::<Vec<_>>();
32        if mismatched_indices.len() != 0 {
33            panic!(
34                "assertion left == right failed: arrays do not match at indices: {}.\n  left: {}\n right: {}",
35                itertools::Itertools::format(mismatched_indices.into_iter(), ", "),
36                left.display_values(),
37                right.display_values()
38            )
39        }
40    }};
41}