diff options
author | Valentin Popov <valentin@popov.link> | 2024-01-08 00:21:28 +0300 |
---|---|---|
committer | Valentin Popov <valentin@popov.link> | 2024-01-08 00:21:28 +0300 |
commit | 1b6a04ca5504955c571d1c97504fb45ea0befee4 (patch) | |
tree | 7579f518b23313e8a9748a88ab6173d5e030b227 /vendor/serde_json/tests/lexical/exponent.rs | |
parent | 5ecd8cf2cba827454317368b68571df0d13d7842 (diff) | |
download | fparkan-1b6a04ca5504955c571d1c97504fb45ea0befee4.tar.xz fparkan-1b6a04ca5504955c571d1c97504fb45ea0befee4.zip |
Initial vendor packages
Signed-off-by: Valentin Popov <valentin@popov.link>
Diffstat (limited to 'vendor/serde_json/tests/lexical/exponent.rs')
-rw-r--r-- | vendor/serde_json/tests/lexical/exponent.rs | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/vendor/serde_json/tests/lexical/exponent.rs b/vendor/serde_json/tests/lexical/exponent.rs new file mode 100644 index 0000000..f7a847b --- /dev/null +++ b/vendor/serde_json/tests/lexical/exponent.rs @@ -0,0 +1,54 @@ +// Adapted from https://github.com/Alexhuszagh/rust-lexical. + +use crate::lexical::exponent::*; + +#[test] +fn scientific_exponent_test() { + // 0 digits in the integer + assert_eq!(scientific_exponent(0, 0, 5), -6); + assert_eq!(scientific_exponent(10, 0, 5), 4); + assert_eq!(scientific_exponent(-10, 0, 5), -16); + + // >0 digits in the integer + assert_eq!(scientific_exponent(0, 1, 5), 0); + assert_eq!(scientific_exponent(0, 2, 5), 1); + assert_eq!(scientific_exponent(0, 2, 20), 1); + assert_eq!(scientific_exponent(10, 2, 20), 11); + assert_eq!(scientific_exponent(-10, 2, 20), -9); + + // Underflow + assert_eq!( + scientific_exponent(i32::min_value(), 0, 0), + i32::min_value() + ); + assert_eq!( + scientific_exponent(i32::min_value(), 0, 5), + i32::min_value() + ); + + // Overflow + assert_eq!( + scientific_exponent(i32::max_value(), 0, 0), + i32::max_value() - 1 + ); + assert_eq!( + scientific_exponent(i32::max_value(), 5, 0), + i32::max_value() + ); +} + +#[test] +fn mantissa_exponent_test() { + assert_eq!(mantissa_exponent(10, 5, 0), 5); + assert_eq!(mantissa_exponent(0, 5, 0), -5); + assert_eq!( + mantissa_exponent(i32::max_value(), 5, 0), + i32::max_value() - 5 + ); + assert_eq!(mantissa_exponent(i32::max_value(), 0, 5), i32::max_value()); + assert_eq!(mantissa_exponent(i32::min_value(), 5, 0), i32::min_value()); + assert_eq!( + mantissa_exponent(i32::min_value(), 0, 5), + i32::min_value() + 5 + ); +} |