3
3
use libm:: support:: Float ;
4
4
5
5
use crate :: domain:: HasDomain ;
6
+ use crate :: run_cfg:: { check_near_count, check_point_count} ;
6
7
use crate :: { CheckCtx , FloatExt , MathOp } ;
7
8
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
-
16
9
/// 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 , ) >
18
11
where
19
12
Op : MathOp < FTy = F > + HasDomain < F > ,
20
13
F : Float ,
@@ -25,23 +18,26 @@ where
25
18
let domain_start = domain. range_start ( ) ;
26
19
let domain_end = domain. range_end ( ) ;
27
20
21
+ let check_points = check_point_count ( ctx) ;
22
+ let near_points = check_near_count ( ctx) ;
23
+
28
24
// 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) ;
35
31
values. push ( F :: NEG_ZERO ) ;
36
32
37
33
// 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) ;
45
41
46
42
// Check some special values that aren't included in the above ranges
47
43
values. push ( F :: NAN ) ;
50
46
// Check around asymptotes
51
47
if let Some ( f) = domain. check_points {
52
48
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) ;
56
52
}
57
53
}
58
54
@@ -65,11 +61,11 @@ where
65
61
66
62
/// Add `AROUND` values starting at and including `x` and counting up. Uses the smallest possible
67
63
/// 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 > ) {
69
65
assert ! ( !x. is_nan( ) ) ;
70
66
71
67
let mut count = 0 ;
72
- while x < F :: INFINITY && count < AROUND {
68
+ while x < F :: INFINITY && count < points {
73
69
values. push ( x) ;
74
70
x = x. next_up ( ) ;
75
71
count += 1 ;
@@ -78,11 +74,11 @@ fn count_up<F: Float>(mut x: F, values: &mut Vec<F>) {
78
74
79
75
/// Add `AROUND` values starting at and including `x` and counting down. Uses the smallest possible
80
76
/// 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 > ) {
82
78
assert ! ( !x. is_nan( ) ) ;
83
79
84
80
let mut count = 0 ;
85
- while x > F :: NEG_INFINITY && count < AROUND {
81
+ while x > F :: NEG_INFINITY && count < points {
86
82
values. push ( x) ;
87
83
x = x. next_down ( ) ;
88
84
count += 1 ;
0 commit comments