33use libm:: support:: Float ;
44
55use crate :: domain:: HasDomain ;
6+ use crate :: run_cfg:: { check_near_count, check_point_count} ;
67use crate :: { CheckCtx , FloatExt , MathOp } ;
78
8- /// Number of values near an interesting point to check.
9- // FIXME(ntests): replace this with a more logical algorithm
10- const AROUND : usize = 100 ;
11-
12- /// Functions have infinite asymptotes, limit how many we check.
13- // FIXME(ntests): replace this with a more logical algorithm
14- const MAX_CHECK_POINTS : usize = 10 ;
15-
169/// Create a list of values around interesting points (infinities, zeroes, NaNs).
17- pub fn get_test_cases < Op , F > ( _ctx : & CheckCtx ) -> impl Iterator < Item = ( F , ) >
10+ pub fn get_test_cases < Op , F > ( ctx : & CheckCtx ) -> impl Iterator < Item = ( F , ) >
1811where
1912 Op : MathOp < FTy = F > + HasDomain < F > ,
2013 F : Float ,
@@ -25,23 +18,26 @@ where
2518 let domain_start = domain. range_start ( ) ;
2619 let domain_end = domain. range_end ( ) ;
2720
21+ let check_points = check_point_count ( ctx) ;
22+ let near_points = check_near_count ( ctx) ;
23+
2824 // Check near some notable constants
29- count_up ( F :: ONE , values) ;
30- count_up ( F :: ZERO , values) ;
31- count_up ( F :: NEG_ONE , values) ;
32- count_down ( F :: ONE , values) ;
33- count_down ( F :: ZERO , values) ;
34- count_down ( F :: NEG_ONE , values) ;
25+ count_up ( F :: ONE , near_points , values) ;
26+ count_up ( F :: ZERO , near_points , values) ;
27+ count_up ( F :: NEG_ONE , near_points , values) ;
28+ count_down ( F :: ONE , near_points , values) ;
29+ count_down ( F :: ZERO , near_points , values) ;
30+ count_down ( F :: NEG_ONE , near_points , values) ;
3531 values. push ( F :: NEG_ZERO ) ;
3632
3733 // Check values near the extremes
38- count_up ( F :: NEG_INFINITY , values) ;
39- count_down ( F :: INFINITY , values) ;
40- count_down ( domain_end, values) ;
41- count_up ( domain_start, values) ;
42- count_down ( domain_start, values) ;
43- count_up ( domain_end, values) ;
44- count_down ( domain_end, values) ;
34+ count_up ( F :: NEG_INFINITY , near_points , values) ;
35+ count_down ( F :: INFINITY , near_points , values) ;
36+ count_down ( domain_end, near_points , values) ;
37+ count_up ( domain_start, near_points , values) ;
38+ count_down ( domain_start, near_points , values) ;
39+ count_up ( domain_end, near_points , values) ;
40+ count_down ( domain_end, near_points , values) ;
4541
4642 // Check some special values that aren't included in the above ranges
4743 values. push ( F :: NAN ) ;
5046 // Check around asymptotes
5147 if let Some ( f) = domain. check_points {
5248 let iter = f ( ) ;
53- for x in iter. take ( MAX_CHECK_POINTS ) {
54- count_up ( x, values) ;
55- count_down ( x, values) ;
49+ for x in iter. take ( check_points ) {
50+ count_up ( x, near_points , values) ;
51+ count_down ( x, near_points , values) ;
5652 }
5753 }
5854
@@ -65,11 +61,11 @@ where
6561
6662/// Add `AROUND` values starting at and including `x` and counting up. Uses the smallest possible
6763/// increments (1 ULP).
68- fn count_up < F : Float > ( mut x : F , values : & mut Vec < F > ) {
64+ fn count_up < F : Float > ( mut x : F , points : u64 , values : & mut Vec < F > ) {
6965 assert ! ( !x. is_nan( ) ) ;
7066
7167 let mut count = 0 ;
72- while x < F :: INFINITY && count < AROUND {
68+ while x < F :: INFINITY && count < points {
7369 values. push ( x) ;
7470 x = x. next_up ( ) ;
7571 count += 1 ;
@@ -78,11 +74,11 @@ fn count_up<F: Float>(mut x: F, values: &mut Vec<F>) {
7874
7975/// Add `AROUND` values starting at and including `x` and counting down. Uses the smallest possible
8076/// increments (1 ULP).
81- fn count_down < F : Float > ( mut x : F , values : & mut Vec < F > ) {
77+ fn count_down < F : Float > ( mut x : F , points : u64 , values : & mut Vec < F > ) {
8278 assert ! ( !x. is_nan( ) ) ;
8379
8480 let mut count = 0 ;
85- while x > F :: NEG_INFINITY && count < AROUND {
81+ while x > F :: NEG_INFINITY && count < points {
8682 values. push ( x) ;
8783 x = x. next_down ( ) ;
8884 count += 1 ;
0 commit comments