From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- .../rust/minimal-lexical/tests/number_tests.rs | 88 ++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 third_party/rust/minimal-lexical/tests/number_tests.rs (limited to 'third_party/rust/minimal-lexical/tests/number_tests.rs') diff --git a/third_party/rust/minimal-lexical/tests/number_tests.rs b/third_party/rust/minimal-lexical/tests/number_tests.rs new file mode 100644 index 0000000000..947be394c9 --- /dev/null +++ b/third_party/rust/minimal-lexical/tests/number_tests.rs @@ -0,0 +1,88 @@ +use minimal_lexical::number::Number; + +#[test] +fn is_fast_path_test() { + let mut number = Number { + exponent: -4, + mantissa: 12345, + many_digits: false, + }; + assert_eq!(number.is_fast_path::(), true); + assert_eq!(number.is_fast_path::(), true); + + number.exponent = -15; + assert_eq!(number.is_fast_path::(), false); + assert_eq!(number.is_fast_path::(), true); + + number.exponent = -25; + assert_eq!(number.is_fast_path::(), false); + assert_eq!(number.is_fast_path::(), false); + + number.exponent = 25; + assert_eq!(number.is_fast_path::(), false); + assert_eq!(number.is_fast_path::(), true); + + number.exponent = 36; + assert_eq!(number.is_fast_path::(), false); + assert_eq!(number.is_fast_path::(), true); + + number.exponent = 38; + assert_eq!(number.is_fast_path::(), false); + assert_eq!(number.is_fast_path::(), false); + + number.mantissa = 1 << 25; + number.exponent = 0; + assert_eq!(number.is_fast_path::(), false); + assert_eq!(number.is_fast_path::(), true); + + number.mantissa = 1 << 54; + assert_eq!(number.is_fast_path::(), false); + assert_eq!(number.is_fast_path::(), false); + + number.mantissa = 1 << 52; + assert_eq!(number.is_fast_path::(), false); + assert_eq!(number.is_fast_path::(), true); + + number.many_digits = true; + assert_eq!(number.is_fast_path::(), false); + assert_eq!(number.is_fast_path::(), false); +} + +#[test] +fn try_fast_path_test() { + let mut number = Number { + exponent: -4, + mantissa: 12345, + many_digits: false, + }; + assert_eq!(number.try_fast_path::(), Some(1.2345)); + assert_eq!(number.try_fast_path::(), Some(1.2345)); + + number.exponent = -10; + assert_eq!(number.try_fast_path::(), Some(1.2345e-6)); + assert_eq!(number.try_fast_path::(), Some(1.2345e-6)); + + number.exponent = -20; + assert_eq!(number.try_fast_path::(), None); + assert_eq!(number.try_fast_path::(), Some(1.2345e-16)); + + number.exponent = -25; + assert_eq!(number.try_fast_path::(), None); + assert_eq!(number.try_fast_path::(), None); + + number.exponent = 12; + assert_eq!(number.try_fast_path::(), Some(1.2345e16)); + assert_eq!(number.try_fast_path::(), Some(1.2345e16)); + + number.exponent = 25; + assert_eq!(number.try_fast_path::(), None); + assert_eq!(number.try_fast_path::(), Some(1.2345e29)); + + number.exponent = 32; + assert_eq!(number.try_fast_path::(), None); + assert_eq!(number.try_fast_path::(), Some(1.2345e36)); + + number.exponent = 36; + assert_eq!(number.try_fast_path::(), None); + assert_eq!(number.try_fast_path::(), None); +} -- cgit v1.2.3