mirror of
https://github.com/rust-lang/rust.git
synced 2025-10-24 14:08:17 +00:00
This also allows reusing the same generator logic between logspace tests and extensive tests, so comes with a nice bit of cleanup. Changes: * Make the generator part of `CheckCtx` since a `Generator` and `CheckCtx` are almost always passed together. * Rename `domain_logspace` to `spaced` since this no longer only operates within a domain and we may want to handle integer spacing. * Domain is now calculated at runtime rather than using traits, which is much easier to work with. * With the above, domains for multidimensional functions are added. * The extensive test generator code tests has been combined with the domain_logspace generator code. With this, the domain tests have just become a subset of extensive tests. These were renamed to "quickspace" since, technically, the extensive tests are also "domain" or "domain logspace" tests. * Edge case generators now handle functions with multiple inputs. * The test runners can be significantly cleaned up and deduplicated.
71 lines
2.3 KiB
Rust
71 lines
2.3 KiB
Rust
//! Test with "infinite precision"
|
|
|
|
#![cfg(feature = "build-mpfr")]
|
|
|
|
use libm_test::gen::{edge_cases, random, spaced};
|
|
use libm_test::mpfloat::MpOp;
|
|
use libm_test::{CheckBasis, CheckCtx, CheckOutput, GeneratorKind, MathOp, TupleCall};
|
|
|
|
const BASIS: CheckBasis = CheckBasis::Mpfr;
|
|
|
|
fn mp_runner<Op: MathOp + MpOp>(ctx: &CheckCtx, cases: impl Iterator<Item = Op::RustArgs>) {
|
|
let mut mp_vals = Op::new_mp();
|
|
for input in cases {
|
|
let mp_res = Op::run(&mut mp_vals, input);
|
|
let crate_res = input.call(Op::ROUTINE);
|
|
|
|
crate_res.validate(mp_res, input, ctx).unwrap();
|
|
}
|
|
}
|
|
|
|
macro_rules! mp_tests {
|
|
(
|
|
fn_name: $fn_name:ident,
|
|
attrs: [$($attr:meta),*],
|
|
) => {
|
|
paste::paste! {
|
|
#[test]
|
|
$(#[$attr])*
|
|
fn [< mp_random_ $fn_name >]() {
|
|
type Op = libm_test::op::$fn_name::Routine;
|
|
let ctx = CheckCtx::new(Op::IDENTIFIER, BASIS, GeneratorKind::Random);
|
|
let cases = random::get_test_cases::<<Op as MathOp>::RustArgs>(&ctx);
|
|
mp_runner::<Op>(&ctx, cases);
|
|
}
|
|
|
|
#[test]
|
|
$(#[$attr])*
|
|
fn [< mp_edge_case_ $fn_name >]() {
|
|
type Op = libm_test::op::$fn_name::Routine;
|
|
let ctx = CheckCtx::new(Op::IDENTIFIER, BASIS, GeneratorKind::EdgeCases);
|
|
let cases = edge_cases::get_test_cases::<Op>(&ctx);
|
|
mp_runner::<Op>(&ctx, cases);
|
|
}
|
|
|
|
#[test]
|
|
$(#[$attr])*
|
|
fn [< mp_quickspace_ $fn_name >]() {
|
|
type Op = libm_test::op::$fn_name::Routine;
|
|
let ctx = CheckCtx::new(Op::IDENTIFIER, BASIS, GeneratorKind::QuickSpaced);
|
|
let cases = spaced::get_test_cases::<Op>(&ctx).0;
|
|
mp_runner::<Op>(&ctx, cases);
|
|
}
|
|
}
|
|
};
|
|
}
|
|
|
|
libm_macros::for_each_function! {
|
|
callback: mp_tests,
|
|
attributes: [
|
|
// Also an assertion failure on i686: at `MPFR_ASSERTN (! mpfr_erangeflag_p ())`
|
|
#[ignore = "large values are infeasible in MPFR"]
|
|
[jn, jnf, yn, ynf],
|
|
],
|
|
skip: [
|
|
// FIXME: test needed, see
|
|
// https://github.com/rust-lang/libm/pull/311#discussion_r1818273392
|
|
nextafter,
|
|
nextafterf,
|
|
],
|
|
}
|