assert_eq_all 0.1.1

Accepts any number of arguments and panics if they are not equal.
Documentation
  • Coverage
  • 0%
    0 out of 3 items documented0 out of 0 items with examples
  • Size
  • Source code size: 17.43 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.07 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 9s Average build duration of successful builds.
  • all releases: 9s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • vglinka/assert_eq_all
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • vglinka

assert_eq_all macro

Accepts any number of arguments and panics if they are not equal. The number of arguments can also be odd. Each argument will be compared with the previous and following.

Additionally, the macro prints the names of the arguments that caused the error, not just their values.

This is useful if you want to test whether different implementations actually return the same result.

Hello world!
thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `20`,
 right: `21`: 
(my_func_impl_6(x) != my_func_impl_7(x))', main.rs:18:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

main.rs

use assert_eq_all::{assert_eq_all, assert_ne_all};

// Benchmarked functions
fn my_func_impl_1(x: u32) -> u32 { x }
fn my_func_impl_2(x: u32) -> u32 { x }
fn my_func_impl_3(x: u32) -> u32 { x }
fn my_func_impl_4(x: u32) -> u32 { x }
fn my_func_impl_5(x: u32) -> u32 { x }
fn my_func_impl_6(x: u32) -> u32 { x }
fn my_func_impl_7(x: u32) -> u32 { x + 1 }
//                                   ^^^
// An error in one of the options for an alternative
// implementation of the algorithm.

fn main() {
    println!("Hello world!");              
    let x = 20;
    assert_eq_all!(
        my_func_impl_1(x), // 20
        my_func_impl_2(x), // 20
        my_func_impl_3(x), // 20
        my_func_impl_4(x), // 20
        my_func_impl_5(x), // 20
        my_func_impl_6(x), // 20
        my_func_impl_7(x), // 21 <--
    );

    assert_ne_all!(
        my_func_impl_6(x), // 20
        my_func_impl_7(x), // 21
    );
}