Move CheckBasis and CheckCtx to a new run_cfg module
These are used more places than just test traits, so this new module should be a better home. `run_cfg` will also be expanded in the near future.
This commit is contained in:
parent
e3a58da4f8
commit
86aeee818b
3 changed files with 55 additions and 39 deletions
|
|
@ -8,6 +8,7 @@ pub mod mpfloat;
|
|||
mod num;
|
||||
pub mod op;
|
||||
mod precision;
|
||||
mod run_cfg;
|
||||
mod test_traits;
|
||||
|
||||
pub use f8_impl::f8;
|
||||
|
|
@ -15,7 +16,8 @@ pub use libm::support::{Float, Int, IntTy, MinInt};
|
|||
pub use num::{FloatExt, logspace};
|
||||
pub use op::{BaseName, FloatTy, Identifier, MathOp, OpCFn, OpFTy, OpRustFn, OpRustRet, Ty};
|
||||
pub use precision::{MaybeOverride, SpecialCase, default_ulp};
|
||||
pub use test_traits::{CheckBasis, CheckCtx, CheckOutput, GenerateInput, Hex, TupleCall};
|
||||
pub use run_cfg::{CheckBasis, CheckCtx};
|
||||
pub use test_traits::{CheckOutput, GenerateInput, Hex, TupleCall};
|
||||
|
||||
/// Result type for tests is usually from `anyhow`. Most times there is no success value to
|
||||
/// propagate.
|
||||
|
|
|
|||
|
|
@ -0,0 +1,51 @@
|
|||
//! Configuration for how tests get run.
|
||||
|
||||
#![allow(unused)]
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use std::env;
|
||||
use std::sync::LazyLock;
|
||||
|
||||
use crate::{BaseName, FloatTy, Identifier, op};
|
||||
|
||||
pub const EXTENSIVE_ENV: &str = "LIBM_EXTENSIVE_TESTS";
|
||||
|
||||
/// Context passed to [`CheckOutput`].
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct CheckCtx {
|
||||
/// Allowed ULP deviation
|
||||
pub ulp: u32,
|
||||
pub fn_ident: Identifier,
|
||||
pub base_name: BaseName,
|
||||
/// Function name.
|
||||
pub fn_name: &'static str,
|
||||
/// Return the unsuffixed version of the function name.
|
||||
pub base_name_str: &'static str,
|
||||
/// Source of truth for tests.
|
||||
pub basis: CheckBasis,
|
||||
}
|
||||
|
||||
impl CheckCtx {
|
||||
/// Create a new check context, using the default ULP for the function.
|
||||
pub fn new(fn_ident: Identifier, basis: CheckBasis) -> Self {
|
||||
let mut ret = Self {
|
||||
ulp: 0,
|
||||
fn_ident,
|
||||
fn_name: fn_ident.as_str(),
|
||||
base_name: fn_ident.base_name(),
|
||||
base_name_str: fn_ident.base_name().as_str(),
|
||||
basis,
|
||||
};
|
||||
ret.ulp = crate::default_ulp(&ret);
|
||||
ret
|
||||
}
|
||||
}
|
||||
|
||||
/// Possible items to test against
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub enum CheckBasis {
|
||||
/// Check against Musl's math sources.
|
||||
Musl,
|
||||
/// Check against infinite precision (MPFR).
|
||||
Mpfr,
|
||||
}
|
||||
|
|
@ -11,44 +11,7 @@ use std::fmt;
|
|||
|
||||
use anyhow::{Context, bail, ensure};
|
||||
|
||||
use crate::{BaseName, Float, Identifier, Int, MaybeOverride, SpecialCase, TestResult};
|
||||
|
||||
/// Context passed to [`CheckOutput`].
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct CheckCtx {
|
||||
/// Allowed ULP deviation
|
||||
pub ulp: u32,
|
||||
pub fn_ident: Identifier,
|
||||
pub base_name: BaseName,
|
||||
/// Function name.
|
||||
pub fn_name: &'static str,
|
||||
/// Source of truth for tests.
|
||||
pub basis: CheckBasis,
|
||||
}
|
||||
|
||||
impl CheckCtx {
|
||||
/// Create a new check context, using the default ULP for the function.
|
||||
pub fn new(fn_ident: Identifier, basis: CheckBasis) -> Self {
|
||||
let mut ret = Self {
|
||||
ulp: 0,
|
||||
fn_ident,
|
||||
fn_name: fn_ident.as_str(),
|
||||
base_name: fn_ident.base_name(),
|
||||
basis,
|
||||
};
|
||||
ret.ulp = crate::default_ulp(&ret);
|
||||
ret
|
||||
}
|
||||
}
|
||||
|
||||
/// Possible items to test against
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub enum CheckBasis {
|
||||
/// Check against Musl's math sources.
|
||||
Musl,
|
||||
/// Check against infinite precision (MPFR).
|
||||
Mpfr,
|
||||
}
|
||||
use crate::{CheckCtx, Float, Int, MaybeOverride, SpecialCase, TestResult};
|
||||
|
||||
/// Implement this on types that can generate a sequence of tuples for test input.
|
||||
pub trait GenerateInput<TupleArgs> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue