1 use super::super::*;
2 use core::num::flt2dec::strategy::grisu::*;
3
4 #[test]
5 #[cfg_attr(miri, ignore)] // Miri is too slow
test_cached_power()6 fn test_cached_power() {
7 assert_eq!(CACHED_POW10.first().unwrap().1, CACHED_POW10_FIRST_E);
8 assert_eq!(CACHED_POW10.last().unwrap().1, CACHED_POW10_LAST_E);
9
10 for e in -1137..961 {
11 // full range for f64
12 let low = ALPHA - e - 64;
13 let high = GAMMA - e - 64;
14 let (_k, cached) = cached_power(low, high);
15 assert!(
16 low <= cached.e && cached.e <= high,
17 "cached_power({}, {}) = {:?} is incorrect",
18 low,
19 high,
20 cached
21 );
22 }
23 }
24
25 #[test]
test_max_pow10_no_more_than()26 fn test_max_pow10_no_more_than() {
27 let mut prevtenk = 1;
28 for k in 1..10 {
29 let tenk = prevtenk * 10;
30 assert_eq!(max_pow10_no_more_than(tenk - 1), (k - 1, prevtenk));
31 assert_eq!(max_pow10_no_more_than(tenk), (k, tenk));
32 prevtenk = tenk;
33 }
34 }
35
36 #[test]
shortest_sanity_test()37 fn shortest_sanity_test() {
38 f64_shortest_sanity_test(format_shortest);
39 f32_shortest_sanity_test(format_shortest);
40 more_shortest_sanity_test(format_shortest);
41 }
42
43 #[test]
44 #[cfg_attr(miri, ignore)] // Miri is too slow
exact_sanity_test()45 fn exact_sanity_test() {
46 // See comments in dragon.rs's exact_sanity_test for why this test is
47 // ignored on MSVC
48 if !cfg!(target_env = "msvc") {
49 f64_exact_sanity_test(format_exact);
50 }
51 f32_exact_sanity_test(format_exact);
52 }
53
54 #[test]
test_to_shortest_str()55 fn test_to_shortest_str() {
56 to_shortest_str_test(format_shortest);
57 }
58
59 #[test]
test_to_shortest_exp_str()60 fn test_to_shortest_exp_str() {
61 to_shortest_exp_str_test(format_shortest);
62 }
63
64 #[test]
test_to_exact_exp_str()65 fn test_to_exact_exp_str() {
66 to_exact_exp_str_test(format_exact);
67 }
68
69 #[test]
test_to_exact_fixed_str()70 fn test_to_exact_fixed_str() {
71 to_exact_fixed_str_test(format_exact);
72 }
73