Skip to content

Commit

Permalink
rust: Add more test macros for complex
Browse files Browse the repository at this point in the history
  • Loading branch information
felixhekhorn committed Feb 3, 2025
1 parent 0a4717e commit 938378a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 22 deletions.
30 changes: 8 additions & 22 deletions crates/ekore/src/anomalous_dimensions/unpolarized/spacelike.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ pub fn gamma_valence_qed(
#[cfg(test)]
mod tests {
use super::*;
use crate::{assert_approx_eq_cmplx, cmplx};
use crate::{assert_approx_eq_cmplx, assert_approx_eq_cmplx_2d, cmplx};
use num::complex::Complex;

#[test]
Expand Down Expand Up @@ -292,28 +292,14 @@ mod tests {
const N: Complex<f64> = cmplx!(2., 0.);
let mut c = Cache::new(N);

assert_approx_eq_cmplx!(
f64,
gamma_valence_qed(3, 2, &mut c, NF)[3][0][0][0],
cmplx!(459.646893789751, 0.),
epsilon = 1e-5
);
assert_approx_eq_cmplx!(
f64,
gamma_valence_qed(3, 2, &mut c, NF)[3][0][1][1],
cmplx!(437.60340375, 0.),
epsilon = 1e-5
);
assert_approx_eq_cmplx!(
assert_approx_eq_cmplx_2d!(
f64,
gamma_valence_qed(3, 2, &mut c, NF)[3][0][1][0],
cmplx!(0., 0.),
epsilon = 1e-5
);
assert_approx_eq_cmplx!(
f64,
gamma_valence_qed(3, 2, &mut c, NF)[3][0][0][1],
cmplx!(0., 0.),
gamma_valence_qed(3, 2, &mut c, NF)[3][0],
[
[cmplx!(459.646893789751, 0.), cmplx!(0., 0.)],
[cmplx!(0., 0.), cmplx!(437.60340375, 0.)]
],
2,
epsilon = 1e-5
);
}
Expand Down
13 changes: 13 additions & 0 deletions crates/ekore/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,16 @@ macro_rules! assert_approx_eq_cmplx {
float_cmp::assert_approx_eq!($size, $ref.im, $target.im $(, $set = $val)*);
};
}

/// Shorthand complex matrix comparators.
#[cfg(test)]
#[macro_export]
macro_rules! assert_approx_eq_cmplx_2d {
($size:ty, $ref:expr, $target:expr, $d:expr $(, $set:ident = $val:expr)*) => {
for j in 0..$d {
for k in 0..$d {
assert_approx_eq_cmplx!($size, $ref[j][k], $target[j][k] $(, $set = $val)*);
}
}
}
}

0 comments on commit 938378a

Please sign in to comment.