1 // Adapted from https://github.com/Alexhuszagh/rust-lexical.
2 
3 use crate::lexical::exponent::*;
4 
5 #[test]
scientific_exponent_test()6 fn scientific_exponent_test() {
7     // 0 digits in the integer
8     assert_eq!(scientific_exponent(0, 0, 5), -6);
9     assert_eq!(scientific_exponent(10, 0, 5), 4);
10     assert_eq!(scientific_exponent(-10, 0, 5), -16);
11 
12     // >0 digits in the integer
13     assert_eq!(scientific_exponent(0, 1, 5), 0);
14     assert_eq!(scientific_exponent(0, 2, 5), 1);
15     assert_eq!(scientific_exponent(0, 2, 20), 1);
16     assert_eq!(scientific_exponent(10, 2, 20), 11);
17     assert_eq!(scientific_exponent(-10, 2, 20), -9);
18 
19     // Underflow
20     assert_eq!(
21         scientific_exponent(i32::min_value(), 0, 0),
22         i32::min_value()
23     );
24     assert_eq!(
25         scientific_exponent(i32::min_value(), 0, 5),
26         i32::min_value()
27     );
28 
29     // Overflow
30     assert_eq!(
31         scientific_exponent(i32::max_value(), 0, 0),
32         i32::max_value() - 1
33     );
34     assert_eq!(
35         scientific_exponent(i32::max_value(), 5, 0),
36         i32::max_value()
37     );
38 }
39 
40 #[test]
mantissa_exponent_test()41 fn mantissa_exponent_test() {
42     assert_eq!(mantissa_exponent(10, 5, 0), 5);
43     assert_eq!(mantissa_exponent(0, 5, 0), -5);
44     assert_eq!(
45         mantissa_exponent(i32::max_value(), 5, 0),
46         i32::max_value() - 5
47     );
48     assert_eq!(mantissa_exponent(i32::max_value(), 0, 5), i32::max_value());
49     assert_eq!(mantissa_exponent(i32::min_value(), 5, 0), i32::min_value());
50     assert_eq!(
51         mantissa_exponent(i32::min_value(), 0, 5),
52         i32::min_value() + 5
53     );
54 }
55