1
1
//! A generator that makes use of domain bounds.
2
2
3
- use std:: ops:: Bound ;
4
-
5
3
use libm:: support:: { Float , MinInt } ;
6
4
7
5
use crate :: domain:: { Domain , HasDomain } ;
8
- use crate :: { MathOp , logspace} ;
9
-
10
- /// Number of tests to run.
11
- // FIXME(ntests): replace this with a more logical algorithm
12
- const NTESTS : usize = {
13
- if cfg ! ( optimizations_enabled) {
14
- if crate :: emulated ( )
15
- || !cfg ! ( target_pointer_width = "64" )
16
- || cfg ! ( all( target_arch = "x86_64" , target_vendor = "apple" ) )
17
- {
18
- // Tests are pretty slow on non-64-bit targets, x86 MacOS, and targets that run
19
- // in QEMU.
20
- 100_000
21
- } else {
22
- 5_000_000
23
- }
24
- } else {
25
- // Without optimizations just run a quick check
26
- 800
27
- }
28
- } ;
6
+ use crate :: run_cfg:: { TestAction , TestTy } ;
7
+ use crate :: { MathOp , logspace, op} ;
29
8
30
9
/// Create a range of logarithmically spaced inputs within a function's domain.
31
10
///
@@ -34,26 +13,26 @@ const NTESTS: usize = {
34
13
pub fn get_test_cases < Op > ( ) -> impl Iterator < Item = ( Op :: FTy , ) >
35
14
where
36
15
Op : MathOp + HasDomain < Op :: FTy > ,
37
- <Op :: FTy as Float >:: Int : TryFrom < usize > ,
16
+ <Op :: FTy as Float >:: Int : TryFrom < u64 > ,
38
17
{
39
- get_test_cases_inner :: < Op :: FTy > ( Op :: D )
18
+ get_test_cases_inner :: < Op :: FTy > ( Op :: D , Op :: IDENTIFIER )
40
19
}
41
20
42
- pub fn get_test_cases_inner < F > ( domain : Domain < F > ) -> impl Iterator < Item = ( F , ) >
21
+ pub fn get_test_cases_inner < F > ( domain : Domain < F > , id : op :: Identifier ) -> impl Iterator < Item = ( F , ) >
43
22
where
44
- F : Float < Int : TryFrom < usize > > ,
23
+ F : Float < Int : TryFrom < u64 > > ,
45
24
{
46
- // We generate logspaced inputs within a specific range, excluding values that are out of
47
- // range in order to make iterations useful (random tests still cover the full range).
48
- let range_start = match domain. start {
49
- Bound :: Included ( v) | Bound :: Excluded ( v) => v,
50
- Bound :: Unbounded => F :: NEG_INFINITY ,
51
- } ;
52
- let range_end = match domain. end {
53
- Bound :: Included ( v) | Bound :: Excluded ( v) => v,
54
- Bound :: Unbounded => F :: INFINITY ,
25
+ let action = crate :: run_cfg:: get_iterations ( id, TestTy :: Logspace , 0 ) ;
26
+ let ntests = match action {
27
+ TestAction :: Iterations ( n) => n,
28
+ TestAction :: Run => unimplemented ! ( ) ,
29
+ TestAction :: Skip => unimplemented ! ( ) ,
55
30
} ;
56
31
57
- let steps = F :: Int :: try_from ( NTESTS ) . unwrap_or ( F :: Int :: MAX ) ;
58
- logspace ( range_start, range_end, steps) . map ( |v| ( v, ) )
32
+ // We generate logspaced inputs within a specific range, excluding values that are out of
33
+ // range in order to make iterations useful (random tests still cover the full range).
34
+ let start = domain. range_start ( ) ;
35
+ let end = domain. range_end ( ) ;
36
+ let steps = F :: Int :: try_from ( ntests) . unwrap_or ( F :: Int :: MAX ) ;
37
+ logspace ( start, end, steps) . map ( |v| ( v, ) )
59
38
}
0 commit comments