[][src]Module nikisas_test::utils

Useful utilities that enhance the control over the behavior of the crate.

Examples

Suppose you are testing the quality of the implementation of the tangent function. It is a periodic function with period π and asymptotes at -π/2 and π/2, where its value is -infinity and infinity, respectively. Therefore, we need to exclude these from our input domain:

use nikisas_test::prelude::*;
use nikisas_test::utils::{shift_left, shift_right, avoid_odd_mults};

fn tan(x: f32) -> f32 {
    // your implementation
}

// Make the range boundaries such that -π/2 and π/2 are not included.
let primary_range = UniformSample::with_count(
    shift_right(-core::f32::consts::PI / 2.0),
    shift_left(core::f32::consts::PI / 2.0),
    100000,
)
.error(|x| (tan(x), x.tan()));

// Filter out the odd multipliers of π/2, that is, -π/2, π/2, 3π/2, etc.
let entire_range = UniformSample::with_count(-2.1e+9, 2.1e+9, 10000)
    .filter(avoid_odd_mults(core::f32::consts::PI / 2.0))
    .error(|x| (tan(x), x.tan()));

Functions

avoid

Instructs the iterator to avoid this particular value.

avoid_even_mults

Instructs the iterator to avoid all even multipliers of this particular value. That is, for value x, it's 2x, 4x, but not 3x. See avoid_mults for usage.

avoid_mults

Instructs the iterator to avoid all multipliers of this particular value.

avoid_odd_mults

Instructs the iterator to avoid all odd multipliers of this particular value. That is, for value x, it's x, 3x, but not 2x. See avoid_mults for usage.

shift_left

Returns x - machine epsilon. For finer resolution, use nextdown.

shift_right

Returns x + machine epsilon. For finer resolution, use nextup.