| 1 |
mod macros; |
| 2 |
|
| 3 |
use core::{cmp::Ordering::*, str::FromStr}; |
| 4 |
use num_traits::{Inv, Signed, ToPrimitive}; |
| 5 |
use rust_decimal::{Decimal, Error, RoundingStrategy}; |
| 6 |
|
| 7 |
#[test] |
| 8 |
#[cfg(feature = "c-repr")] |
| 9 |
fn layout_is_correct() { |
| 10 |
assert_eq!(std::mem::size_of::<Decimal>(), std::mem::size_of::<u128>()); |
| 11 |
} |
| 12 |
|
| 13 |
#[test] |
| 14 |
fn it_can_extract_the_mantissa() { |
| 15 |
let tests = [ |
| 16 |
("1", 1i128, 0), |
| 17 |
("1.123456", 1123456i128, 6), |
| 18 |
("-0.123456", -123456i128, 6), |
| 19 |
]; |
| 20 |
for &(input, mantissa, scale) in &tests { |
| 21 |
let num = Decimal::from_str(input).unwrap(); |
| 22 |
assert_eq!(num.mantissa(), mantissa, "Mantissa for {}", input); |
| 23 |
assert_eq!(num.scale(), scale, "Scale for {}", input); |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 27 |
// Parsing |
| 28 |
|
| 29 |
#[test] |
| 30 |
fn it_creates_a_new_negative_decimal() { |
| 31 |
let a = Decimal::new(-100, 2); |
| 32 |
assert_eq!(a.is_sign_negative(), true); |
| 33 |
assert_eq!(a.scale(), 2); |
| 34 |
assert_eq!("-1.00", a.to_string()); |
| 35 |
} |
| 36 |
|
| 37 |
#[test] |
| 38 |
fn it_creates_a_new_decimal_using_numeric_boundaries() { |
| 39 |
let a = Decimal::new(i64::MAX, 2); |
| 40 |
assert_eq!(a.is_sign_negative(), false); |
| 41 |
assert_eq!(a.scale(), 2); |
| 42 |
assert_eq!("92233720368547758.07", a.to_string()); |
| 43 |
|
| 44 |
let b = Decimal::new(i64::MIN, 2); |
| 45 |
assert_eq!(b.is_sign_negative(), true); |
| 46 |
assert_eq!(b.scale(), 2); |
| 47 |
assert_eq!("-92233720368547758.08", b.to_string()); |
| 48 |
} |
| 49 |
|
| 50 |
#[test] |
| 51 |
fn it_parses_empty_string() { |
| 52 |
assert!(Decimal::from_str("").is_err()); |
| 53 |
assert!(Decimal::from_str(" ").is_err()); |
| 54 |
} |
| 55 |
|
| 56 |
#[test] |
| 57 |
fn it_parses_positive_int_string() { |
| 58 |
let a = Decimal::from_str("233").unwrap(); |
| 59 |
assert_eq!(a.is_sign_negative(), false); |
| 60 |
assert_eq!(a.scale(), 0); |
| 61 |
assert_eq!("233", a.to_string()); |
| 62 |
} |
| 63 |
|
| 64 |
#[test] |
| 65 |
fn it_parses_negative_int_string() { |
| 66 |
let a = Decimal::from_str("-233").unwrap(); |
| 67 |
assert_eq!(a.is_sign_negative(), true); |
| 68 |
assert_eq!(a.scale(), 0); |
| 69 |
assert_eq!("-233", a.to_string()); |
| 70 |
} |
| 71 |
|
| 72 |
#[test] |
| 73 |
fn it_parses_positive_float_string() { |
| 74 |
let a = Decimal::from_str("233.323223").unwrap(); |
| 75 |
assert_eq!(a.is_sign_negative(), false); |
| 76 |
assert_eq!(a.scale(), 6); |
| 77 |
assert_eq!("233.323223", a.to_string()); |
| 78 |
} |
| 79 |
|
| 80 |
#[test] |
| 81 |
fn it_parses_negative_float_string() { |
| 82 |
let a = Decimal::from_str("-233.43343").unwrap(); |
| 83 |
assert_eq!(a.is_sign_negative(), true); |
| 84 |
assert_eq!(a.scale(), 5); |
| 85 |
assert_eq!("-233.43343", a.to_string()); |
| 86 |
} |
| 87 |
|
| 88 |
#[test] |
| 89 |
fn it_parses_positive_tiny_float_string() { |
| 90 |
let a = Decimal::from_str(".000001").unwrap(); |
| 91 |
assert_eq!(a.is_sign_negative(), false); |
| 92 |
assert_eq!(a.scale(), 6); |
| 93 |
assert_eq!("0.000001", a.to_string()); |
| 94 |
} |
| 95 |
|
| 96 |
#[test] |
| 97 |
fn it_parses_negative_tiny_float_string() { |
| 98 |
let a = Decimal::from_str("-0.000001").unwrap(); |
| 99 |
assert_eq!(a.is_sign_negative(), true); |
| 100 |
assert_eq!(a.scale(), 6); |
| 101 |
assert_eq!("-0.000001", a.to_string()); |
| 102 |
} |
| 103 |
|
| 104 |
#[test] |
| 105 |
fn it_parses_big_integer_string() { |
| 106 |
let a = Decimal::from_str("79228162514264337593543950330").unwrap(); |
| 107 |
assert_eq!("79228162514264337593543950330", a.to_string()); |
| 108 |
} |
| 109 |
|
| 110 |
#[test] |
| 111 |
fn it_parses_big_float_string() { |
| 112 |
let a = Decimal::from_str("79.228162514264337593543950330").unwrap(); |
| 113 |
assert_eq!("79.228162514264337593543950330", a.to_string()); |
| 114 |
} |
| 115 |
|
| 116 |
#[test] |
| 117 |
fn it_can_serialize_deserialize() { |
| 118 |
let tests = [ |
| 119 |
"12.3456789", |
| 120 |
"5233.9008808150288439427720175", |
| 121 |
"-5233.9008808150288439427720175", |
| 122 |
]; |
| 123 |
for test in &tests { |
| 124 |
let a = Decimal::from_str(test).unwrap(); |
| 125 |
let bytes = a.serialize(); |
| 126 |
let b = Decimal::deserialize(bytes); |
| 127 |
assert_eq!(test.to_string(), b.to_string()); |
| 128 |
} |
| 129 |
} |
| 130 |
|
| 131 |
#[test] |
| 132 |
#[cfg(feature = "borsh")] |
| 133 |
fn it_can_serialize_deserialize_borsh() { |
| 134 |
let tests = [ |
| 135 |
"12.3456789", |
| 136 |
"5233.9008808150288439427720175", |
| 137 |
"-5233.9008808150288439427720175", |
| 138 |
]; |
| 139 |
for test in &tests { |
| 140 |
let a = Decimal::from_str(test).unwrap(); |
| 141 |
let mut bytes: Vec<u8> = Vec::new(); |
| 142 |
borsh::BorshSerialize::serialize(&a, &mut bytes).unwrap(); |
| 143 |
let b: Decimal = borsh::BorshDeserialize::deserialize(&mut bytes.as_slice()).unwrap(); |
| 144 |
assert_eq!(test.to_string(), b.to_string()); |
| 145 |
let bytes = borsh::try_to_vec_with_schema(&a); |
| 146 |
assert!(bytes.is_ok(), "try_to_vec_with_schema.is_ok()"); |
| 147 |
let bytes = bytes.unwrap(); |
| 148 |
let result = borsh::try_from_slice_with_schema(&bytes); |
| 149 |
assert!(result.is_ok(), "try_from_slice_with_schema.is_ok()"); |
| 150 |
let b: Decimal = result.unwrap(); |
| 151 |
assert_eq!(test.to_string(), b.to_string()); |
| 152 |
} |
| 153 |
} |
| 154 |
|
| 155 |
#[test] |
| 156 |
#[cfg(feature = "rkyv")] |
| 157 |
fn it_can_serialize_deserialize_rkyv() { |
| 158 |
use rkyv::Deserialize; |
| 159 |
let tests = [ |
| 160 |
"12.3456789", |
| 161 |
"5233.9008808150288439427720175", |
| 162 |
"-5233.9008808150288439427720175", |
| 163 |
]; |
| 164 |
for test in &tests { |
| 165 |
let a = Decimal::from_str(test).unwrap(); |
| 166 |
let bytes = rkyv::to_bytes::<_, 256>(&a).unwrap(); |
| 167 |
|
| 168 |
#[cfg(feature = "rkyv-safe")] |
| 169 |
{ |
| 170 |
let archived = rkyv::check_archived_root::<Decimal>(&bytes[..]).unwrap(); |
| 171 |
assert_eq!(archived, &a); |
| 172 |
} |
| 173 |
|
| 174 |
let archived = unsafe { rkyv::archived_root::<Decimal>(&bytes[..]) }; |
| 175 |
assert_eq!(archived, &a); |
| 176 |
|
| 177 |
let deserialized: Decimal = archived.deserialize(&mut rkyv::Infallible).unwrap(); |
| 178 |
assert_eq!(deserialized, a); |
| 179 |
} |
| 180 |
} |
| 181 |
|
| 182 |
#[test] |
| 183 |
fn it_can_deserialize_unbounded_values() { |
| 184 |
// Mantissa for these: 19393111376951473493673267553 |
| 185 |
let tests = [ |
| 186 |
( |
| 187 |
[1u8, 0, 28, 206, 97, 81, 216, 182, 20, 30, 165, 78, 18, 155, 169, 62], |
| 188 |
// Scale 28: -1.9393111376951473493673267553 |
| 189 |
"-1.9393111376951473493673267553", |
| 190 |
), |
| 191 |
( |
| 192 |
[1u8, 0, 29, 206, 97, 81, 216, 182, 20, 30, 165, 78, 18, 155, 169, 62], |
| 193 |
// Scale 29: -0.19393111376951473493673267553 |
| 194 |
"-0.1939311137695147349367326755", |
| 195 |
), |
| 196 |
( |
| 197 |
[1u8, 0, 30, 206, 97, 81, 216, 182, 20, 30, 165, 78, 18, 155, 169, 62], |
| 198 |
// Scale 30: -0.019393111376951473493673267553 |
| 199 |
"-0.0193931113769514734936732676", |
| 200 |
), |
| 201 |
( |
| 202 |
[1u8, 0, 31, 206, 97, 81, 216, 182, 20, 30, 165, 78, 18, 155, 169, 62], |
| 203 |
// Scale 31: -0.0019393111376951473493673267553 |
| 204 |
"-0.0019393111376951473493673268", |
| 205 |
), |
| 206 |
]; |
| 207 |
for &(bytes, expected) in &tests { |
| 208 |
let dec = Decimal::deserialize(bytes); |
| 209 |
let string = format!("{:.9999}", dec); |
| 210 |
let dec2 = Decimal::from_str(&string).unwrap(); |
| 211 |
assert_eq!(dec, dec2); |
| 212 |
assert_eq!(dec.to_string(), expected, "dec.to_string()"); |
| 213 |
assert_eq!(dec2.to_string(), expected, "dec2.to_string()"); |
| 214 |
} |
| 215 |
} |
| 216 |
|
| 217 |
// Formatting |
| 218 |
|
| 219 |
#[test] |
| 220 |
fn it_formats() { |
| 221 |
let a = Decimal::from_str("233.323223").unwrap(); |
| 222 |
assert_eq!(format!("{}", a), "233.323223"); |
| 223 |
assert_eq!(format!("{:.9}", a), "233.323223000"); |
| 224 |
assert_eq!(format!("{:.0}", a), "233"); |
| 225 |
assert_eq!(format!("{:.2}", a), "233.32"); |
| 226 |
assert_eq!(format!("{:010.2}", a), "0000233.32"); |
| 227 |
assert_eq!(format!("{:0<10.2}", a), "233.320000"); |
| 228 |
} |
| 229 |
#[test] |
| 230 |
fn it_formats_neg() { |
| 231 |
let a = Decimal::from_str("-233.323223").unwrap(); |
| 232 |
assert_eq!(format!("{}", a), "-233.323223"); |
| 233 |
assert_eq!(format!("{:.9}", a), "-233.323223000"); |
| 234 |
assert_eq!(format!("{:.0}", a), "-233"); |
| 235 |
assert_eq!(format!("{:.2}", a), "-233.32"); |
| 236 |
assert_eq!(format!("{:010.2}", a), "-000233.32"); |
| 237 |
assert_eq!(format!("{:0<10.2}", a), "-233.32000"); |
| 238 |
} |
| 239 |
#[test] |
| 240 |
fn it_formats_small() { |
| 241 |
let a = Decimal::from_str("0.2223").unwrap(); |
| 242 |
assert_eq!(format!("{}", a), "0.2223"); |
| 243 |
assert_eq!(format!("{:.9}", a), "0.222300000"); |
| 244 |
assert_eq!(format!("{:.0}", a), "0"); |
| 245 |
assert_eq!(format!("{:.2}", a), "0.22"); |
| 246 |
assert_eq!(format!("{:010.2}", a), "0000000.22"); |
| 247 |
assert_eq!(format!("{:0<10.2}", a), "0.22000000"); |
| 248 |
} |
| 249 |
#[test] |
| 250 |
fn it_formats_small_leading_zeros() { |
| 251 |
let a = Decimal::from_str("0.0023554701772169").unwrap(); |
| 252 |
assert_eq!(format!("{}", a), "0.0023554701772169"); |
| 253 |
assert_eq!(format!("{:.9}", a), "0.002355470"); |
| 254 |
assert_eq!(format!("{:.0}", a), "0"); |
| 255 |
assert_eq!(format!("{:.2}", a), "0.00"); |
| 256 |
assert_eq!(format!("{:010.2}", a), "0000000.00"); |
| 257 |
assert_eq!(format!("{:0<10.2}", a), "0.00000000"); |
| 258 |
} |
| 259 |
#[test] |
| 260 |
fn it_formats_small_neg() { |
| 261 |
let a = Decimal::from_str("-0.2223").unwrap(); |
| 262 |
assert_eq!(format!("{}", a), "-0.2223"); |
| 263 |
assert_eq!(format!("{:.9}", a), "-0.222300000"); |
| 264 |
assert_eq!(format!("{:.0}", a), "-0"); |
| 265 |
assert_eq!(format!("{:.2}", a), "-0.22"); |
| 266 |
assert_eq!(format!("{:010.2}", a), "-000000.22"); |
| 267 |
assert_eq!(format!("{:0<10.2}", a), "-0.2200000"); |
| 268 |
} |
| 269 |
|
| 270 |
#[test] |
| 271 |
fn it_formats_zero() { |
| 272 |
let a = Decimal::from_str("0").unwrap(); |
| 273 |
assert_eq!(format!("{}", a), "0"); |
| 274 |
assert_eq!(format!("{:.9}", a), "0.000000000"); |
| 275 |
assert_eq!(format!("{:.0}", a), "0"); |
| 276 |
assert_eq!(format!("{:.2}", a), "0.00"); |
| 277 |
assert_eq!(format!("{:010.2}", a), "0000000.00"); |
| 278 |
assert_eq!(format!("{:0<10.2}", a), "0.00000000"); |
| 279 |
} |
| 280 |
|
| 281 |
#[test] |
| 282 |
fn it_formats_int() { |
| 283 |
let a = Decimal::from_str("5").unwrap(); |
| 284 |
assert_eq!(format!("{}", a), "5"); |
| 285 |
assert_eq!(format!("{:.9}", a), "5.000000000"); |
| 286 |
assert_eq!(format!("{:.0}", a), "5"); |
| 287 |
assert_eq!(format!("{:.2}", a), "5.00"); |
| 288 |
assert_eq!(format!("{:010.2}", a), "0000005.00"); |
| 289 |
assert_eq!(format!("{:0<10.2}", a), "5.00000000"); |
| 290 |
} |
| 291 |
|
| 292 |
#[test] |
| 293 |
fn it_formats_lower_exp() { |
| 294 |
let tests = [ |
| 295 |
("0.00001", "1e-5"), |
| 296 |
("-0.00001", "-1e-5"), |
| 297 |
("42.123", "4.2123e1"), |
| 298 |
("-42.123", "-4.2123e1"), |
| 299 |
("100", "1e2"), |
| 300 |
]; |
| 301 |
for (value, expected) in &tests { |
| 302 |
let a = Decimal::from_str(value).unwrap(); |
| 303 |
assert_eq!(&format!("{:e}", a), *expected, "format!(\"{{:e}}\", {})", a); |
| 304 |
} |
| 305 |
} |
| 306 |
|
| 307 |
#[test] |
| 308 |
fn it_formats_lower_exp_padding() { |
| 309 |
let tests = [ |
| 310 |
("0.00001", "01e-5"), |
| 311 |
("-0.00001", "-1e-5"), |
| 312 |
("42.123", "4.2123e1"), |
| 313 |
("-42.123", "-4.2123e1"), |
| 314 |
("100", "001e2"), |
| 315 |
]; |
| 316 |
for (value, expected) in &tests { |
| 317 |
let a = Decimal::from_str(value).unwrap(); |
| 318 |
assert_eq!(&format!("{:05e}", a), *expected, "format!(\"{{:05e}}\", {})", a); |
| 319 |
} |
| 320 |
} |
| 321 |
|
| 322 |
#[test] |
| 323 |
fn it_formats_scientific_precision() { |
| 324 |
for (num, scale, expected_no_precision, expected_precision) in [ |
| 325 |
( |
| 326 |
123456, |
| 327 |
10, |
| 328 |
"1.23456e-5", |
| 329 |
[ |
| 330 |
"1e-5", |
| 331 |
"1.2e-5", |
| 332 |
"1.23e-5", |
| 333 |
"1.234e-5", |
| 334 |
"1.2345e-5", |
| 335 |
"1.23456e-5", |
| 336 |
"1.234560e-5", |
| 337 |
"1.2345600e-5", |
| 338 |
], |
| 339 |
), |
| 340 |
( |
| 341 |
123456, |
| 342 |
0, |
| 343 |
"1.23456e5", |
| 344 |
[ |
| 345 |
"1e5", |
| 346 |
"1.2e5", |
| 347 |
"1.23e5", |
| 348 |
"1.234e5", |
| 349 |
"1.2345e5", |
| 350 |
"1.23456e5", |
| 351 |
"1.234560e5", |
| 352 |
"1.2345600e5", |
| 353 |
], |
| 354 |
), |
| 355 |
( |
| 356 |
1, |
| 357 |
0, |
| 358 |
"1e0", |
| 359 |
[ |
| 360 |
"1e0", |
| 361 |
"1.0e0", |
| 362 |
"1.00e0", |
| 363 |
"1.000e0", |
| 364 |
"1.0000e0", |
| 365 |
"1.00000e0", |
| 366 |
"1.000000e0", |
| 367 |
"1.0000000e0", |
| 368 |
], |
| 369 |
), |
| 370 |
( |
| 371 |
-123456, |
| 372 |
10, |
| 373 |
"-1.23456e-5", |
| 374 |
[ |
| 375 |
"-1e-5", |
| 376 |
"-1.2e-5", |
| 377 |
"-1.23e-5", |
| 378 |
"-1.234e-5", |
| 379 |
"-1.2345e-5", |
| 380 |
"-1.23456e-5", |
| 381 |
"-1.234560e-5", |
| 382 |
"-1.2345600e-5", |
| 383 |
], |
| 384 |
), |
| 385 |
( |
| 386 |
-100000, |
| 387 |
10, |
| 388 |
"-1e-5", |
| 389 |
[ |
| 390 |
"-1e-5", |
| 391 |
"-1.0e-5", |
| 392 |
"-1.00e-5", |
| 393 |
"-1.000e-5", |
| 394 |
"-1.0000e-5", |
| 395 |
"-1.00000e-5", |
| 396 |
"-1.000000e-5", |
| 397 |
"-1.0000000e-5", |
| 398 |
], |
| 399 |
), |
| 400 |
] { |
| 401 |
assert_eq!(format!("{:e}", Decimal::new(num, scale)), expected_no_precision); |
| 402 |
for i in 0..expected_precision.len() { |
| 403 |
assert_eq!( |
| 404 |
format!("{:.prec$e}", Decimal::new(num, scale), prec = i), |
| 405 |
expected_precision[i] |
| 406 |
); |
| 407 |
} |
| 408 |
} |
| 409 |
} |
| 410 |
|
| 411 |
// Negation |
| 412 |
#[test] |
| 413 |
fn it_negates_decimals() { |
| 414 |
fn neg(a: &str, b: &str) { |
| 415 |
let a = Decimal::from_str(a).unwrap(); |
| 416 |
let result = -a; |
| 417 |
assert_eq!(b, result.to_string(), "- {}", a.to_string()); |
| 418 |
} |
| 419 |
|
| 420 |
let tests = &[ |
| 421 |
("1", "-1"), |
| 422 |
("2", "-2"), |
| 423 |
("2454495034", "-2454495034"), |
| 424 |
("0.1", "-0.1"), |
| 425 |
("11.815126050420168067226890757", "-11.815126050420168067226890757"), |
| 426 |
]; |
| 427 |
|
| 428 |
for &(a, b) in tests { |
| 429 |
neg(a, b); |
| 430 |
neg(b, a); |
| 431 |
} |
| 432 |
} |
| 433 |
|
| 434 |
// Addition |
| 435 |
|
| 436 |
#[test] |
| 437 |
fn it_can_add_simple() { |
| 438 |
// This is the most basic test for addition, intended largely for micro-optimization. |
| 439 |
let two = Decimal::ONE + Decimal::ONE; |
| 440 |
assert_eq!(two.to_u32(), Some(2)); |
| 441 |
} |
| 442 |
|
| 443 |
#[test] |
| 444 |
fn it_adds_decimals() { |
| 445 |
fn add(a: &str, b: &str, c: &str) { |
| 446 |
let a = Decimal::from_str(a).unwrap(); |
| 447 |
let b = Decimal::from_str(b).unwrap(); |
| 448 |
let result = a + b; |
| 449 |
assert_eq!(c, result.to_string(), "{} + {}", a.to_string(), b.to_string()); |
| 450 |
let result = b + a; |
| 451 |
assert_eq!(c, result.to_string(), "{} + {}", b.to_string(), a.to_string()); |
| 452 |
} |
| 453 |
|
| 454 |
let tests = &[ |
| 455 |
("0", "0", "0"), |
| 456 |
("0", "-0", "0"), |
| 457 |
("-0", "0", "0"), |
| 458 |
("-0", "-0", "0"), |
| 459 |
("2", "3", "5"), |
| 460 |
("2454495034", "3451204593", "5905699627"), |
| 461 |
("24544.95034", ".3451204593", "24545.2954604593"), |
| 462 |
(".1", ".1", "0.2"), |
| 463 |
(".10", ".1", "0.20"), |
| 464 |
(".1", "-.1", "0.0"), |
| 465 |
("0", "1.001", "1.001"), |
| 466 |
("2", "-3", "-1"), |
| 467 |
("-2", "3", "1"), |
| 468 |
("-2", "-3", "-5"), |
| 469 |
("3", "-2", "1"), |
| 470 |
("-3", "2", "-1"), |
| 471 |
("1.234", "2.4567", "3.6907"), |
| 472 |
( |
| 473 |
"11.815126050420168067226890757", |
| 474 |
"0.6386554621848739495798319328", |
| 475 |
"12.453781512605042016806722690", |
| 476 |
), |
| 477 |
( |
| 478 |
"-11.815126050420168067226890757", |
| 479 |
"0.6386554621848739495798319328", |
| 480 |
"-11.176470588235294117647058824", |
| 481 |
), |
| 482 |
( |
| 483 |
"11.815126050420168067226890757", |
| 484 |
"-0.6386554621848739495798319328", |
| 485 |
"11.176470588235294117647058824", |
| 486 |
), |
| 487 |
( |
| 488 |
"-11.815126050420168067226890757", |
| 489 |
"-0.6386554621848739495798319328", |
| 490 |
"-12.453781512605042016806722690", |
| 491 |
), |
| 492 |
( |
| 493 |
"11815126050420168067226890757", |
| 494 |
"0.4386554621848739495798319328", |
| 495 |
"11815126050420168067226890757", |
| 496 |
), |
| 497 |
( |
| 498 |
"-11815126050420168067226890757", |
| 499 |
"0.4386554621848739495798319328", |
| 500 |
"-11815126050420168067226890757", |
| 501 |
), |
| 502 |
( |
| 503 |
"11815126050420168067226890757", |
| 504 |
"-0.4386554621848739495798319328", |
| 505 |
"11815126050420168067226890757", |
| 506 |
), |
| 507 |
( |
| 508 |
"-11815126050420168067226890757", |
| 509 |
"-0.4386554621848739495798319328", |
| 510 |
"-11815126050420168067226890757", |
| 511 |
), |
| 512 |
( |
| 513 |
"0.0872727272727272727272727272", |
| 514 |
"843.65000000", |
| 515 |
"843.7372727272727272727272727", |
| 516 |
), |
| 517 |
( |
| 518 |
"7314.6229858868828353570724702", |
| 519 |
"1000", |
| 520 |
// Overflow causes this to round |
| 521 |
"8314.622985886882835357072470", |
| 522 |
), |
| 523 |
( |
| 524 |
"108053.27500000000000000000000", |
| 525 |
"0.00000000000000000000000", |
| 526 |
"108053.27500000000000000000000", |
| 527 |
), |
| 528 |
( |
| 529 |
"108053.27500000000000000000000", |
| 530 |
// This zero value has too high precision and will be trimmed |
| 531 |
"0.000000000000000000000000", |
| 532 |
"108053.27500000000000000000000", |
| 533 |
), |
| 534 |
( |
| 535 |
"108053.27500000000000000000000", |
| 536 |
// This value has too high precision and will be rounded |
| 537 |
"0.000000000000000000000001", |
| 538 |
"108053.27500000000000000000000", |
| 539 |
), |
| 540 |
( |
| 541 |
"108053.27500000000000000000000", |
| 542 |
// This value has too high precision and will be rounded |
| 543 |
"0.000000000000000000000005", |
| 544 |
either!("108053.27500000000000000000000", "108053.27500000000000000000001"), |
| 545 |
), |
| 546 |
( |
| 547 |
"8097370036018690744.2590371109596744091", |
| 548 |
"3807285637671831400.15346897797550749555", |
| 549 |
"11904655673690522144.412506089", |
| 550 |
), |
| 551 |
]; |
| 552 |
for &(a, b, c) in tests { |
| 553 |
add(a, b, c); |
| 554 |
} |
| 555 |
} |
| 556 |
|
| 557 |
#[test] |
| 558 |
fn it_can_addassign() { |
| 559 |
let mut a = Decimal::from_str("1.01").unwrap(); |
| 560 |
let b = Decimal::from_str("0.99").unwrap(); |
| 561 |
a += b; |
| 562 |
assert_eq!("2.00", a.to_string()); |
| 563 |
|
| 564 |
a += &b; |
| 565 |
assert_eq!("2.99", a.to_string()); |
| 566 |
|
| 567 |
let mut c = &mut a; |
| 568 |
c += b; |
| 569 |
assert_eq!("3.98", a.to_string()); |
| 570 |
|
| 571 |
let mut c = &mut a; |
| 572 |
c += &b; |
| 573 |
assert_eq!("4.97", a.to_string()); |
| 574 |
} |
| 575 |
|
| 576 |
// Subtraction |
| 577 |
|
| 578 |
#[test] |
| 579 |
fn it_subtracts_decimals() { |
| 580 |
fn sub(a: &str, b: &str, c: &str) { |
| 581 |
let a = Decimal::from_str(a).unwrap(); |
| 582 |
let b = Decimal::from_str(b).unwrap(); |
| 583 |
let result = a - b; |
| 584 |
assert_eq!(c, result.to_string(), "{} - {}", a.to_string(), b.to_string()); |
| 585 |
} |
| 586 |
|
| 587 |
let tests = &[ |
| 588 |
("0", "0", "0"), |
| 589 |
("0", "-0", "0"), |
| 590 |
("-0", "0", "0"), |
| 591 |
("-0", "-0", "0"), |
| 592 |
("2", "3", "-1"), |
| 593 |
("3451204593", "2323322332", "1127882261"), |
| 594 |
("24544.95034", ".3451204593", "24544.6052195407"), |
| 595 |
(".1", ".1", "0.0"), |
| 596 |
(".1", "-.1", "0.2"), |
| 597 |
("1.001", "0", "1.001"), |
| 598 |
("2", "-3", "5"), |
| 599 |
("-2", "3", "-5"), |
| 600 |
("-2", "-3", "1"), |
| 601 |
("3", "-2", "5"), |
| 602 |
("-3", "2", "-5"), |
| 603 |
("1.234", "2.4567", "-1.2227"), |
| 604 |
("844.13000000", "843.65000000", "0.48000000"), |
| 605 |
("79228162514264337593543950335", "79228162514264337593543950335", "0"), // 0xFFFF_FFFF_FFFF_FFFF_FFF_FFFF - 0xFFFF_FFFF_FFFF_FFFF_FFF_FFFF |
| 606 |
("79228162514264337593543950335", "0", "79228162514264337593543950335"), |
| 607 |
("79228162514264337593543950335", "79228162514264337593543950333", "2"), |
| 608 |
("4951760157141521099596496896", "1", "4951760157141521099596496895"), // 0x1000_0000_0000_0000_0000_0000 - 1 = 0x0FFF_FFFF_FFFF_FFFF_FFF_FFFF |
| 609 |
("79228162514264337593543950334", "79228162514264337593543950335", "-1"), |
| 610 |
("1", "4951760157141521099596496895", "-4951760157141521099596496894"), |
| 611 |
("18446744073709551615", "-18446744073709551615", "36893488147419103230"), // 0xFFFF_FFFF_FFFF_FFFF - -0xFFFF_FFFF_FFFF_FFFF |
| 612 |
]; |
| 613 |
for &(a, b, c) in tests { |
| 614 |
sub(a, b, c); |
| 615 |
} |
| 616 |
} |
| 617 |
|
| 618 |
#[test] |
| 619 |
fn it_can_subassign() { |
| 620 |
let mut a = Decimal::from_str("1.01").unwrap(); |
| 621 |
let b = Decimal::from_str("0.51").unwrap(); |
| 622 |
a -= b; |
| 623 |
assert_eq!("0.50", a.to_string()); |
| 624 |
|
| 625 |
a -= &b; |
| 626 |
assert_eq!("-0.01", a.to_string()); |
| 627 |
|
| 628 |
let mut c = &mut a; |
| 629 |
c -= b; |
| 630 |
assert_eq!("-0.52", a.to_string()); |
| 631 |
|
| 632 |
let mut c = &mut a; |
| 633 |
c -= &b; |
| 634 |
assert_eq!("-1.03", a.to_string()); |
| 635 |
} |
| 636 |
|
| 637 |
// Multiplication |
| 638 |
|
| 639 |
#[test] |
| 640 |
fn it_multiplies_decimals() { |
| 641 |
fn mul(a: &str, b: &str, c: &str) { |
| 642 |
let a = Decimal::from_str(a).unwrap(); |
| 643 |
let b = Decimal::from_str(b).unwrap(); |
| 644 |
let result = a * b; |
| 645 |
assert_eq!(c, result.to_string(), "{} * {}", a.to_string(), b.to_string()); |
| 646 |
let result = b * a; |
| 647 |
assert_eq!(c, result.to_string(), "{} * {}", b.to_string(), a.to_string()); |
| 648 |
} |
| 649 |
|
| 650 |
let tests = &[ |
| 651 |
("2", "3", "6"), |
| 652 |
("2454495034", "3451204593", "8470964534836491162"), |
| 653 |
("24544.95034", ".3451204593", "8470.964534836491162"), |
| 654 |
(".1", ".1", "0.01"), |
| 655 |
("0", "1.001", "0"), |
| 656 |
("2", "-3", "-6"), |
| 657 |
("-2", "3", "-6"), |
| 658 |
("-2", "-3", "6"), |
| 659 |
("1", "2.01", "2.01"), |
| 660 |
("1.0", "2.01", "2.010"), // Scale is always additive |
| 661 |
( |
| 662 |
"0.00000000000000001", |
| 663 |
"0.00000000000000001", |
| 664 |
"0.0000000000000000000000000000", |
| 665 |
), |
| 666 |
("0.0000000000000000000000000001", "0.0000000000000000000000000001", "0"), |
| 667 |
( |
| 668 |
"0.6386554621848739495798319328", |
| 669 |
"11.815126050420168067226890757", |
| 670 |
"7.5457947885036367488171739292", |
| 671 |
), |
| 672 |
( |
| 673 |
"2123456789012345678901234567.8", |
| 674 |
"11.815126050420168067226890757", |
| 675 |
"25088909624801327937270048761", |
| 676 |
), |
| 677 |
( |
| 678 |
"2123456789012345678901234567.8", |
| 679 |
"-11.815126050420168067226890757", |
| 680 |
"-25088909624801327937270048761", |
| 681 |
), |
| 682 |
( |
| 683 |
"2.1234567890123456789012345678", |
| 684 |
"2.1234567890123456789012345678", |
| 685 |
"4.5090687348026215523554336227", |
| 686 |
), |
| 687 |
( |
| 688 |
"0.48000000", |
| 689 |
"0.1818181818181818181818181818", |
| 690 |
either!("0.0872727272727272727272727273", "0.0872727272727272727272727272"), |
| 691 |
), |
| 692 |
]; |
| 693 |
for &(a, b, c) in tests { |
| 694 |
mul(a, b, c); |
| 695 |
} |
| 696 |
} |
| 697 |
|
| 698 |
#[test] |
| 699 |
#[should_panic(expected = "Multiplication overflowed")] |
| 700 |
fn it_panics_when_multiply_with_overflow() { |
| 701 |
let a = Decimal::from_str("2000000000000000000001").unwrap(); |
| 702 |
let b = Decimal::from_str("3000000000000000000001").unwrap(); |
| 703 |
let _ = a * b; |
| 704 |
} |
| 705 |
|
| 706 |
#[test] |
| 707 |
fn it_can_mulassign() { |
| 708 |
let mut a = Decimal::from_str("1.25").unwrap(); |
| 709 |
let b = Decimal::from_str("0.01").unwrap(); |
| 710 |
|
| 711 |
a *= b; |
| 712 |
assert_eq!("0.0125", a.to_string()); |
| 713 |
|
| 714 |
a *= &b; |
| 715 |
assert_eq!("0.000125", a.to_string()); |
| 716 |
|
| 717 |
let mut c = &mut a; |
| 718 |
c *= b; |
| 719 |
assert_eq!("0.00000125", a.to_string()); |
| 720 |
|
| 721 |
let mut c = &mut a; |
| 722 |
c *= &b; |
| 723 |
assert_eq!("0.0000000125", a.to_string()); |
| 724 |
} |
| 725 |
|
| 726 |
// Division |
| 727 |
|
| 728 |
#[test] |
| 729 |
fn it_divides_decimals() { |
| 730 |
fn div(a: &str, b: &str, c: &str) { |
| 731 |
let a = Decimal::from_str(a).unwrap(); |
| 732 |
let b = Decimal::from_str(b).unwrap(); |
| 733 |
let result = a / b; |
| 734 |
assert_eq!(c, result.to_string(), "{} / {}", a.to_string(), b.to_string()); |
| 735 |
} |
| 736 |
|
| 737 |
let tests = &[ |
| 738 |
("6", "3", "2"), |
| 739 |
("10", "2", "5"), |
| 740 |
("2.2", "1.1", "2"), |
| 741 |
("-2.2", "-1.1", "2"), |
| 742 |
("12.88", "5.6", "2.3"), |
| 743 |
( |
| 744 |
"1023427554493", |
| 745 |
"43432632", |
| 746 |
either!("23563.562864276795382789603909", "23563.562864276795382789603908"), |
| 747 |
), |
| 748 |
("10000", "3", "3333.3333333333333333333333333"), |
| 749 |
("2", "3", "0.6666666666666666666666666667"), |
| 750 |
("1", "3", "0.3333333333333333333333333333"), |
| 751 |
("-2", "3", "-0.6666666666666666666666666667"), |
| 752 |
("2", "-3", "-0.6666666666666666666666666667"), |
| 753 |
("-2", "-3", "0.6666666666666666666666666667"), |
| 754 |
( |
| 755 |
"1234.5678", |
| 756 |
"0.1234567890123456", |
| 757 |
either!("9999.99926999999982999953127", "9999.999269999999829999531269"), |
| 758 |
), |
| 759 |
("1234.567890123456789012345678", "1.234567890123456789012345678", "1000"), |
| 760 |
( |
| 761 |
"32.91625929004387114334488", |
| 762 |
"3.27629537", |
| 763 |
either!("10.046792359274942644546996384", "10.046792359274942644546996383"), |
| 764 |
), |
| 765 |
("5000", "1000.26957490549", "4.9986524887277738570721416846"), |
| 766 |
("6142.6941216127122745222131114", "2", "3071.3470608063561372611065557"), |
| 767 |
( |
| 768 |
"3071.3470608063561372611065557", |
| 769 |
"1228.87000756", |
| 770 |
either!("2.4993262443638869285360708423", "2.4993262443638869285360708422"), |
| 771 |
), |
| 772 |
( |
| 773 |
"590.3274854004009467754255123", |
| 774 |
"53.68997202826239", |
| 775 |
"10.995116277759516850521689988", |
| 776 |
), |
| 777 |
]; |
| 778 |
for &(a, b, c) in tests { |
| 779 |
div(a, b, c); |
| 780 |
} |
| 781 |
} |
| 782 |
|
| 783 |
#[test] |
| 784 |
#[should_panic(expected = "Division by zero")] |
| 785 |
fn it_can_divide_by_zero() { |
| 786 |
let a = Decimal::from_str("2").unwrap(); |
| 787 |
let _ = a / Decimal::ZERO; |
| 788 |
} |
| 789 |
|
| 790 |
#[test] |
| 791 |
fn it_can_divassign() { |
| 792 |
let mut a = Decimal::from_str("1.25").unwrap(); |
| 793 |
let b = Decimal::from_str("0.01").unwrap(); |
| 794 |
|
| 795 |
a /= b; |
| 796 |
assert_eq!("125", a.to_string()); |
| 797 |
|
| 798 |
a /= &b; |
| 799 |
assert_eq!("12500", a.to_string()); |
| 800 |
|
| 801 |
let mut c = &mut a; |
| 802 |
c /= b; |
| 803 |
assert_eq!("1250000", a.to_string()); |
| 804 |
|
| 805 |
let mut c = &mut a; |
| 806 |
c /= &b; |
| 807 |
assert_eq!("125000000", a.to_string()); |
| 808 |
} |
| 809 |
|
| 810 |
// Modulus and Remainder are not the same thing! |
| 811 |
// https://math.stackexchange.com/q/801962/82277 |
| 812 |
|
| 813 |
#[test] |
| 814 |
fn it_rems_decimals() { |
| 815 |
fn rem(a: &str, b: &str, c: &str) { |
| 816 |
let a = Decimal::from_str(a).unwrap(); |
| 817 |
let b = Decimal::from_str(b).unwrap(); |
| 818 |
// a = qb + r |
| 819 |
let result = a % b; |
| 820 |
assert_eq!(c, result.to_string(), "{} % {}", a.to_string(), b.to_string()); |
| 821 |
} |
| 822 |
|
| 823 |
let tests = &[ |
| 824 |
("2", "3", "2"), |
| 825 |
("-2", "3", "-2"), |
| 826 |
("2", "-3", "2"), |
| 827 |
("-2", "-3", "-2"), |
| 828 |
("6", "3", "0"), |
| 829 |
("42.2", "11.9", "6.5"), |
| 830 |
("2.1", "3", "2.1"), |
| 831 |
("2", "3.1", "2"), |
| 832 |
("2.0", "3.1", "2.0"), |
| 833 |
("4", "3.1", "0.9"), |
| 834 |
("2", "2", "0"), |
| 835 |
("2", "-2", "0"), |
| 836 |
// Legacy keeps sign from lhs operand |
| 837 |
("-2", "2", "0"), |
| 838 |
("-2", "-2", "0"), |
| 839 |
]; |
| 840 |
for &(a, b, c) in tests { |
| 841 |
rem(a, b, c); |
| 842 |
} |
| 843 |
} |
| 844 |
|
| 845 |
#[test] |
| 846 |
fn it_can_remassign() { |
| 847 |
let mut a = Decimal::from_str("5").unwrap(); |
| 848 |
let b = Decimal::from_str("2").unwrap(); |
| 849 |
|
| 850 |
a %= b; |
| 851 |
assert_eq!("1", a.to_string()); |
| 852 |
|
| 853 |
a %= &b; |
| 854 |
assert_eq!("1", a.to_string()); |
| 855 |
|
| 856 |
let mut c = &mut a; |
| 857 |
c %= b; |
| 858 |
assert_eq!("1", a.to_string()); |
| 859 |
|
| 860 |
let mut c = &mut a; |
| 861 |
c %= &b; |
| 862 |
assert_eq!("1", a.to_string()); |
| 863 |
} |
| 864 |
|
| 865 |
#[test] |
| 866 |
fn it_eqs_decimals() { |
| 867 |
fn eq(a: &str, b: &str, c: bool) { |
| 868 |
let a = Decimal::from_str(a).unwrap(); |
| 869 |
let b = Decimal::from_str(b).unwrap(); |
| 870 |
assert_eq!(c, a.eq(&b), "{} == {}", a.to_string(), b.to_string()); |
| 871 |
assert_eq!(c, b.eq(&a), "{} == {}", b.to_string(), a.to_string()); |
| 872 |
} |
| 873 |
|
| 874 |
let tests = &[ |
| 875 |
("1", "1", true), |
| 876 |
("1", "-1", false), |
| 877 |
("1", "1.00", true), |
| 878 |
("1.2345000000000", "1.2345", true), |
| 879 |
("1.0000000000000000000000000000", "1.0000000000000000000000000000", true), |
| 880 |
( |
| 881 |
"1.0000000000000000000000000001", |
| 882 |
"1.0000000000000000000000000000", |
| 883 |
false, |
| 884 |
), |
| 885 |
]; |
| 886 |
for &(a, b, c) in tests { |
| 887 |
eq(a, b, c); |
| 888 |
} |
| 889 |
} |
| 890 |
|
| 891 |
#[test] |
| 892 |
fn it_cmps_decimals() { |
| 893 |
fn cmp(a: &str, b: &str, c: core::cmp::Ordering) { |
| 894 |
let a = Decimal::from_str(a).unwrap(); |
| 895 |
let b = Decimal::from_str(b).unwrap(); |
| 896 |
assert_eq!( |
| 897 |
c, |
| 898 |
a.cmp(&b), |
| 899 |
"{} {} {}", |
| 900 |
a.to_string(), |
| 901 |
match c { |
| 902 |
Less => "<", |
| 903 |
Equal => "==", |
| 904 |
Greater => ">", |
| 905 |
}, |
| 906 |
b.to_string() |
| 907 |
); |
| 908 |
} |
| 909 |
|
| 910 |
let tests = &[ |
| 911 |
("1", "1", Equal), |
| 912 |
("1", "-1", Greater), |
| 913 |
("1", "1.00", Equal), |
| 914 |
("1.2345000000000", "1.2345", Equal), |
| 915 |
( |
| 916 |
"1.0000000000000000000000000001", |
| 917 |
"1.0000000000000000000000000000", |
| 918 |
Greater, |
| 919 |
), |
| 920 |
("1.0000000000000000000000000000", "1.0000000000000000000000000001", Less), |
| 921 |
("-1", "100", Less), |
| 922 |
("-100", "1", Less), |
| 923 |
("0", "0.5", Less), |
| 924 |
("0.5", "0", Greater), |
| 925 |
("100", "0.0098", Greater), |
| 926 |
("1000000000000000", "999000000000000.0001", Greater), |
| 927 |
("2.0001", "2.0001", Equal), |
| 928 |
( |
| 929 |
"11.815126050420168067226890757", |
| 930 |
"0.6386554621848739495798319328", |
| 931 |
Greater, |
| 932 |
), |
| 933 |
("0.6386554621848739495798319328", "11.815126050420168067226890757", Less), |
| 934 |
("-0.5", "-0.01", Less), |
| 935 |
("-0.5", "-0.1", Less), |
| 936 |
("-0.01", "-0.5", Greater), |
| 937 |
("-0.1", "-0.5", Greater), |
| 938 |
// 000 equality |
| 939 |
("0.00000000", "0.00000000", Equal), |
| 940 |
// 000 000 same scale |
| 941 |
("0.00000000", "0.00000000", Equal), |
| 942 |
("-0.00000000", "0.00000000", Equal), |
| 943 |
("0.00000000", "-0.00000000", Equal), |
| 944 |
("-0.00000000", "-0.00000000", Equal), |
| 945 |
// 000 000 different scale |
| 946 |
("0.000000000", "0.00000000000000000000000", Equal), |
| 947 |
("-0.000000000", "0.00000000000000000000000", Equal), |
| 948 |
("0.000000000", "-0.00000000000000000000000", Equal), |
| 949 |
("-0.000000000", "-0.00000000000000000000000", Equal), |
| 950 |
// 000 100 same scale |
| 951 |
("0.00000000", "6.56792910", Less), |
| 952 |
("-0.00000000", "6.56792910", Less), |
| 953 |
("0.00000000", "-6.56792910", Greater), |
| 954 |
("-0.00000000", "-6.56792910", Greater), |
| 955 |
// 000 100 different scale |
| 956 |
("0.0000000000000000000", "0.00000000000000001916236746", Less), |
| 957 |
("-0.0000000000000000000", "0.00000000000000001916236746", Less), |
| 958 |
("0.0000000000000000000", "-0.00000000000000001916236746", Greater), |
| 959 |
("-0.0000000000000000000", "-0.00000000000000001916236746", Greater), |
| 960 |
// 000 010 same scale |
| 961 |
("0.00000000", "49037796231.72571136", Less), |
| 962 |
("-0.00000000", "49037796231.72571136", Less), |
| 963 |
("0.00000000", "-49037796231.72571136", Greater), |
| 964 |
("-0.00000000", "-49037796231.72571136", Greater), |
| 965 |
// 000 010 different scale |
| 966 |
("0", "14459264155.12895488", Less), |
| 967 |
("-0", "14459264155.12895488", Less), |
| 968 |
("0", "-14459264155.12895488", Greater), |
| 969 |
("-0", "-14459264155.12895488", Greater), |
| 970 |
// 000 110 same scale |
| 971 |
("0.00000000", "38675108055.09052783", Less), |
| 972 |
("-0.00000000", "38675108055.09052783", Less), |
| 973 |
("0.00000000", "-38675108055.09052783", Greater), |
| 974 |
("-0.00000000", "-38675108055.09052783", Greater), |
| 975 |
// 000 110 different scale |
| 976 |
("0.00", "1495767034080324868", Less), |
| 977 |
("-0.00", "1495767034080324868", Less), |
| 978 |
("0.00", "-1495767034080324868", Greater), |
| 979 |
("-0.00", "-1495767034080324868", Greater), |
| 980 |
// 000 001 same scale |
| 981 |
("0.00000000", "359299289270893106016.81305600", Less), |
| 982 |
("-0.00000000", "359299289270893106016.81305600", Less), |
| 983 |
("0.00000000", "-359299289270893106016.81305600", Greater), |
| 984 |
("-0.00000000", "-359299289270893106016.81305600", Greater), |
| 985 |
// 000 001 different scale |
| 986 |
("0.00000000000000000000000000", "261631091689.9518486763536384", Less), |
| 987 |
("-0.00000000000000000000000000", "261631091689.9518486763536384", Less), |
| 988 |
( |
| 989 |
"0.00000000000000000000000000", |
| 990 |
"-261631091689.9518486763536384", |
| 991 |
Greater, |
| 992 |
), |
| 993 |
( |
| 994 |
"-0.00000000000000000000000000", |
| 995 |
"-261631091689.9518486763536384", |
| 996 |
Greater, |
| 997 |
), |
| 998 |
// 000 101 same scale |
| 999 |
("0.00000000", "184137107696737410476.63166815", Less), |
| 1000 |
("-0.00000000", "184137107696737410476.63166815", Less), |
| 1001 |
("0.00000000", "-184137107696737410476.63166815", Greater), |
| 1002 |
("-0.00000000", "-184137107696737410476.63166815", Greater), |
| 1003 |
// 000 101 different scale |
| 1004 |
("0.000000000", "2286857871088.7514840434334478", Less), |
| 1005 |
("-0.000000000", "2286857871088.7514840434334478", Less), |
| 1006 |
("0.000000000", "-2286857871088.7514840434334478", Greater), |
| 1007 |
("-0.000000000", "-2286857871088.7514840434334478", Greater), |
| 1008 |
// 000 011 same scale |
| 1009 |
("0.00000000", "169194696640288819908.07715840", Less), |
| 1010 |
("-0.00000000", "169194696640288819908.07715840", Less), |
| 1011 |
("0.00000000", "-169194696640288819908.07715840", Greater), |
| 1012 |
("-0.00000000", "-169194696640288819908.07715840", Greater), |
| 1013 |
// 000 011 different scale |
| 1014 |
("0.00000000", "2757550691.7650076909569048576", Less), |
| 1015 |
("-0.00000000", "2757550691.7650076909569048576", Less), |
| 1016 |
("0.00000000", "-2757550691.7650076909569048576", Greater), |
| 1017 |
("-0.00000000", "-2757550691.7650076909569048576", Greater), |
| 1018 |
// 000 111 same scale |
| 1019 |
("0.00000000", "133610725292915899001.10059212", Less), |
| 1020 |
("-0.00000000", "133610725292915899001.10059212", Less), |
| 1021 |
("0.00000000", "-133610725292915899001.10059212", Greater), |
| 1022 |
("-0.00000000", "-133610725292915899001.10059212", Greater), |
| 1023 |
// 000 111 different scale |
| 1024 |
("0.00000000000000000000", "86.25432767926620368822165265", Less), |
| 1025 |
("-0.00000000000000000000", "86.25432767926620368822165265", Less), |
| 1026 |
("0.00000000000000000000", "-86.25432767926620368822165265", Greater), |
| 1027 |
("-0.00000000000000000000", "-86.25432767926620368822165265", Greater), |
| 1028 |
// 100 equality |
| 1029 |
("0.0000000000598992228", "0.0000000000598992228", Equal), |
| 1030 |
// 100 000 same scale |
| 1031 |
("0.0000000000598992228", "0.0000000000000000000", Greater), |
| 1032 |
("-0.0000000000598992228", "0.0000000000000000000", Less), |
| 1033 |
("0.0000000000598992228", "-0.0000000000000000000", Greater), |
| 1034 |
("-0.0000000000598992228", "-0.0000000000000000000", Less), |
| 1035 |
// 100 000 different scale |
| 1036 |
("0.1797407597", "0.0000000000000000000", Greater), |
| 1037 |
("-0.1797407597", "0.0000000000000000000", Less), |
| 1038 |
("0.1797407597", "-0.0000000000000000000", Greater), |
| 1039 |
("-0.1797407597", "-0.0000000000000000000", Less), |
| 1040 |
// 100 100 same scale |
| 1041 |
("0.0000000000598992228", "0.0000000000064510789", Greater), |
| 1042 |
("-0.0000000000598992228", "0.0000000000064510789", Less), |
| 1043 |
("0.0000000000598992228", "-0.0000000000064510789", Greater), |
| 1044 |
("-0.0000000000598992228", "-0.0000000000064510789", Less), |
| 1045 |
// 100 100 different scale |
| 1046 |
("0.000000000000011217354", "0.0000000000217735186", Less), |
| 1047 |
("-0.000000000000011217354", "0.0000000000217735186", Less), |
| 1048 |
("0.000000000000011217354", "-0.0000000000217735186", Greater), |
| 1049 |
("-0.000000000000011217354", "-0.0000000000217735186", Greater), |
| 1050 |
// 100 010 same scale |
| 1051 |
("0.0000000000598992228", "0.0659116848159129600", Less), |
| 1052 |
("-0.0000000000598992228", "0.0659116848159129600", Less), |
| 1053 |
("0.0000000000598992228", "-0.0659116848159129600", Greater), |
| 1054 |
("-0.0000000000598992228", "-0.0659116848159129600", Greater), |
| 1055 |
// 100 010 different scale |
| 1056 |
("0.00042035421", "0.004709460588143575040", Less), |
| 1057 |
("-0.00042035421", "0.004709460588143575040", Less), |
| 1058 |
("0.00042035421", "-0.004709460588143575040", Greater), |
| 1059 |
("-0.00042035421", "-0.004709460588143575040", Greater), |
| 1060 |
// 100 110 same scale |
| 1061 |
("0.0000000000598992228", "0.0755686585127091375", Less), |
| 1062 |
("-0.0000000000598992228", "0.0755686585127091375", Less), |
| 1063 |
("0.0000000000598992228", "-0.0755686585127091375", Greater), |
| 1064 |
("-0.0000000000598992228", "-0.0755686585127091375", Greater), |
| 1065 |
// 100 110 different scale |
| 1066 |
("14872.94465", "1284707831905.854085", Less), |
| 1067 |
("-14872.94465", "1284707831905.854085", Less), |
| 1068 |
("14872.94465", "-1284707831905.854085", Greater), |
| 1069 |
("-14872.94465", "-1284707831905.854085", Greater), |
| 1070 |
// 100 001 same scale |
| 1071 |
("0.0000000000598992228", "888767595.6145376468836286464", Less), |
| 1072 |
("-0.0000000000598992228", "888767595.6145376468836286464", Less), |
| 1073 |
("0.0000000000598992228", "-888767595.6145376468836286464", Greater), |
| 1074 |
("-0.0000000000598992228", "-888767595.6145376468836286464", Greater), |
| 1075 |
// 100 001 different scale |
| 1076 |
("0.0002108155975", "36.07555527243968476014968832", Less), |
| 1077 |
("-0.0002108155975", "36.07555527243968476014968832", Less), |
| 1078 |
("0.0002108155975", "-36.07555527243968476014968832", Greater), |
| 1079 |
("-0.0002108155975", "-36.07555527243968476014968832", Greater), |
| 1080 |
// 100 101 same scale |
| 1081 |
("0.0000000000598992228", "125730345.7412344676309569911", Less), |
| 1082 |
("-0.0000000000598992228", "125730345.7412344676309569911", Less), |
| 1083 |
("0.0000000000598992228", "-125730345.7412344676309569911", Greater), |
| 1084 |
("-0.0000000000598992228", "-125730345.7412344676309569911", Greater), |
| 1085 |
// 100 101 different scale |
| 1086 |
("0.0000000000871576741", "1.7283925558865766140690239662", Less), |
| 1087 |
("-0.0000000000871576741", "1.7283925558865766140690239662", Less), |
| 1088 |
("0.0000000000871576741", "-1.7283925558865766140690239662", Greater), |
| 1089 |
("-0.0000000000871576741", "-1.7283925558865766140690239662", Greater), |
| 1090 |
// 100 011 same scale |
| 1091 |
("0.0000000000598992228", "645513262.9193254090737451008", Less), |
| 1092 |
("-0.0000000000598992228", "645513262.9193254090737451008", Less), |
| 1093 |
("0.0000000000598992228", "-645513262.9193254090737451008", Greater), |
| 1094 |
("-0.0000000000598992228", "-645513262.9193254090737451008", Greater), |
| 1095 |
// 100 011 different scale |
| 1096 |
("0.000000000000000760885021", "3718370638.2004059326675681280", Less), |
| 1097 |
("-0.000000000000000760885021", "3718370638.2004059326675681280", Less), |
| 1098 |
("0.000000000000000760885021", "-3718370638.2004059326675681280", Greater), |
| 1099 |
( |
| 1100 |
"-0.000000000000000760885021", |
| 1101 |
"-3718370638.2004059326675681280", |
| 1102 |
Greater, |
| 1103 |
), |
| 1104 |
// 100 111 same scale |
| 1105 |
("0.0000000000598992228", "422482675.5515775479939306437", Less), |
| 1106 |
("-0.0000000000598992228", "422482675.5515775479939306437", Less), |
| 1107 |
("0.0000000000598992228", "-422482675.5515775479939306437", Greater), |
| 1108 |
("-0.0000000000598992228", "-422482675.5515775479939306437", Greater), |
| 1109 |
// 100 111 different scale |
| 1110 |
("0.000000044182898", "25.452953262109919998605674045", Less), |
| 1111 |
("-0.000000044182898", "25.452953262109919998605674045", Less), |
| 1112 |
("0.000000044182898", "-25.452953262109919998605674045", Greater), |
| 1113 |
("-0.000000044182898", "-25.452953262109919998605674045", Greater), |
| 1114 |
// 010 equality |
| 1115 |
("423.1744746042687488", "423.1744746042687488", Equal), |
| 1116 |
// 010 000 same scale |
| 1117 |
("423.1744746042687488", "0.0000000000000000", Greater), |
| 1118 |
("-423.1744746042687488", "0.0000000000000000", Less), |
| 1119 |
("423.1744746042687488", "-0.0000000000000000", Greater), |
| 1120 |
("-423.1744746042687488", "-0.0000000000000000", Less), |
| 1121 |
// 010 000 different scale |
| 1122 |
("9002354991.192604672", "0.00000000000000000000000000", Greater), |
| 1123 |
("-9002354991.192604672", "0.00000000000000000000000000", Less), |
| 1124 |
("9002354991.192604672", "-0.00000000000000000000000000", Greater), |
| 1125 |
("-9002354991.192604672", "-0.00000000000000000000000000", Less), |
| 1126 |
// 010 100 same scale |
| 1127 |
("423.1744746042687488", "0.0000000981820809", Greater), |
| 1128 |
("-423.1744746042687488", "0.0000000981820809", Less), |
| 1129 |
("423.1744746042687488", "-0.0000000981820809", Greater), |
| 1130 |
("-423.1744746042687488", "-0.0000000981820809", Less), |
| 1131 |
// 010 100 different scale |
| 1132 |
("4327019125101559.808", "0.00484846050", Greater), |
| 1133 |
("-4327019125101559.808", "0.00484846050", Less), |
| 1134 |
("4327019125101559.808", "-0.00484846050", Greater), |
| 1135 |
("-4327019125101559.808", "-0.00484846050", Less), |
| 1136 |
// 010 010 same scale |
| 1137 |
("423.1744746042687488", "786.9082854590775296", Less), |
| 1138 |
("-423.1744746042687488", "786.9082854590775296", Less), |
| 1139 |
("423.1744746042687488", "-786.9082854590775296", Greater), |
| 1140 |
("-423.1744746042687488", "-786.9082854590775296", Greater), |
| 1141 |
// 010 010 different scale |
| 1142 |
("793.0067125291450368", "0.0001587297248335626240", Greater), |
| 1143 |
("-793.0067125291450368", "0.0001587297248335626240", Less), |
| 1144 |
("793.0067125291450368", "-0.0001587297248335626240", Greater), |
| 1145 |
("-793.0067125291450368", "-0.0001587297248335626240", Less), |
| 1146 |
// 010 110 same scale |
| 1147 |
("423.1744746042687488", "300.0541360230572049", Greater), |
| 1148 |
("-423.1744746042687488", "300.0541360230572049", Less), |
| 1149 |
("423.1744746042687488", "-300.0541360230572049", Greater), |
| 1150 |
("-423.1744746042687488", "-300.0541360230572049", Less), |
| 1151 |
// 010 110 different scale |
| 1152 |
("90627.2042582540288", "4472414566654924.741", Less), |
| 1153 |
("-90627.2042582540288", "4472414566654924.741", Less), |
| 1154 |
("90627.2042582540288", "-4472414566654924.741", Greater), |
| 1155 |
("-90627.2042582540288", "-4472414566654924.741", Greater), |
| 1156 |
// 010 001 same scale |
| 1157 |
("423.1744746042687488", "3960577151543.5796707636412416", Less), |
| 1158 |
("-423.1744746042687488", "3960577151543.5796707636412416", Less), |
| 1159 |
("423.1744746042687488", "-3960577151543.5796707636412416", Greater), |
| 1160 |
("-423.1744746042687488", "-3960577151543.5796707636412416", Greater), |
| 1161 |
// 010 001 different scale |
| 1162 |
("0.000008867461591822499840", "185286.04378228713249986052096", Less), |
| 1163 |
("-0.000008867461591822499840", "185286.04378228713249986052096", Less), |
| 1164 |
("0.000008867461591822499840", "-185286.04378228713249986052096", Greater), |
| 1165 |
( |
| 1166 |
"-0.000008867461591822499840", |
| 1167 |
"-185286.04378228713249986052096", |
| 1168 |
Greater, |
| 1169 |
), |
| 1170 |
// 010 101 same scale |
| 1171 |
("423.1744746042687488", "2825958416017.6213507229869501", Less), |
| 1172 |
("-423.1744746042687488", "2825958416017.6213507229869501", Less), |
| 1173 |
("423.1744746042687488", "-2825958416017.6213507229869501", Greater), |
| 1174 |
("-423.1744746042687488", "-2825958416017.6213507229869501", Greater), |
| 1175 |
// 010 101 different scale |
| 1176 |
("0.01901870767742648320", "37662082383021542232.529651212", Less), |
| 1177 |
("-0.01901870767742648320", "37662082383021542232.529651212", Less), |
| 1178 |
("0.01901870767742648320", "-37662082383021542232.529651212", Greater), |
| 1179 |
("-0.01901870767742648320", "-37662082383021542232.529651212", Greater), |
| 1180 |
// 010 011 same scale |
| 1181 |
("423.1744746042687488", "3628063966991.6759417059016704", Less), |
| 1182 |
("-423.1744746042687488", "3628063966991.6759417059016704", Less), |
| 1183 |
("423.1744746042687488", "-3628063966991.6759417059016704", Greater), |
| 1184 |
("-423.1744746042687488", "-3628063966991.6759417059016704", Greater), |
| 1185 |
// 010 011 different scale |
| 1186 |
("45359904.32470925312", "2.4203452488052342918570049536", Greater), |
| 1187 |
("-45359904.32470925312", "2.4203452488052342918570049536", Less), |
| 1188 |
("45359904.32470925312", "-2.4203452488052342918570049536", Greater), |
| 1189 |
("-45359904.32470925312", "-2.4203452488052342918570049536", Less), |
| 1190 |
// 010 111 same scale |
| 1191 |
("423.1744746042687488", "2629665172331.9610693820109120", Less), |
| 1192 |
("-423.1744746042687488", "2629665172331.9610693820109120", Less), |
| 1193 |
("423.1744746042687488", "-2629665172331.9610693820109120", Greater), |
| 1194 |
("-423.1744746042687488", "-2629665172331.9610693820109120", Greater), |
| 1195 |
// 010 111 different scale |
| 1196 |
("0.0006420803252266205184", "8172.032417576265900588945489", Less), |
| 1197 |
("-0.0006420803252266205184", "8172.032417576265900588945489", Less), |
| 1198 |
("0.0006420803252266205184", "-8172.032417576265900588945489", Greater), |
| 1199 |
("-0.0006420803252266205184", "-8172.032417576265900588945489", Greater), |
| 1200 |
// 110 equality |
| 1201 |
("844.5530620517286511", "844.5530620517286511", Equal), |
| 1202 |
// 110 000 same scale |
| 1203 |
("844.5530620517286511", "0.0000000000000000", Greater), |
| 1204 |
("-844.5530620517286511", "0.0000000000000000", Less), |
| 1205 |
("844.5530620517286511", "-0.0000000000000000", Greater), |
| 1206 |
("-844.5530620517286511", "-0.0000000000000000", Less), |
| 1207 |
// 110 000 different scale |
| 1208 |
("3285.530033386074797", "0.00000000000000000000", Greater), |
| 1209 |
("-3285.530033386074797", "0.00000000000000000000", Less), |
| 1210 |
("3285.530033386074797", "-0.00000000000000000000", Greater), |
| 1211 |
("-3285.530033386074797", "-0.00000000000000000000", Less), |
| 1212 |
// 110 100 same scale |
| 1213 |
("844.5530620517286511", "0.0000001953470063", Greater), |
| 1214 |
("-844.5530620517286511", "0.0000001953470063", Less), |
| 1215 |
("844.5530620517286511", "-0.0000001953470063", Greater), |
| 1216 |
("-844.5530620517286511", "-0.0000001953470063", Less), |
| 1217 |
// 110 100 different scale |
| 1218 |
("371284.0210972493371", "0.000000000000001307794657", Greater), |
| 1219 |
("-371284.0210972493371", "0.000000000000001307794657", Less), |
| 1220 |
("371284.0210972493371", "-0.000000000000001307794657", Greater), |
| 1221 |
("-371284.0210972493371", "-0.000000000000001307794657", Less), |
| 1222 |
// 110 010 same scale |
| 1223 |
("844.5530620517286511", "612.1542773033140224", Greater), |
| 1224 |
("-844.5530620517286511", "612.1542773033140224", Less), |
| 1225 |
("844.5530620517286511", "-612.1542773033140224", Greater), |
| 1226 |
("-844.5530620517286511", "-612.1542773033140224", Less), |
| 1227 |
// 110 010 different scale |
| 1228 |
("0.00004869219159821525572", "23341676485159.15776", Less), |
| 1229 |
("-0.00004869219159821525572", "23341676485159.15776", Less), |
| 1230 |
("0.00004869219159821525572", "-23341676485159.15776", Greater), |
| 1231 |
("-0.00004869219159821525572", "-23341676485159.15776", Greater), |
| 1232 |
// 110 110 same scale |
| 1233 |
("844.5530620517286511", "326.6132818317622015", Greater), |
| 1234 |
("-844.5530620517286511", "326.6132818317622015", Less), |
| 1235 |
("844.5530620517286511", "-326.6132818317622015", Greater), |
| 1236 |
("-844.5530620517286511", "-326.6132818317622015", Less), |
| 1237 |
// 110 110 different scale |
| 1238 |
("4752139369958.820619", "1330851022882027.972", Less), |
| 1239 |
("-4752139369958.820619", "1330851022882027.972", Less), |
| 1240 |
("4752139369958.820619", "-1330851022882027.972", Greater), |
| 1241 |
("-4752139369958.820619", "-1330851022882027.972", Greater), |
| 1242 |
// 110 001 same scale |
| 1243 |
("844.5530620517286511", "3585610241942.1922435648192512", Less), |
| 1244 |
("-844.5530620517286511", "3585610241942.1922435648192512", Less), |
| 1245 |
("844.5530620517286511", "-3585610241942.1922435648192512", Greater), |
| 1246 |
("-844.5530620517286511", "-3585610241942.1922435648192512", Greater), |
| 1247 |
// 110 001 different scale |
| 1248 |
("539313715923.4424678", "12410950080603997079634706432", Less), |
| 1249 |
("-539313715923.4424678", "12410950080603997079634706432", Less), |
| 1250 |
("539313715923.4424678", "-12410950080603997079634706432", Greater), |
| 1251 |
("-539313715923.4424678", "-12410950080603997079634706432", Greater), |
| 1252 |
// 110 101 same scale |
| 1253 |
("844.5530620517286511", "1947825396031.6933708908343230", Less), |
| 1254 |
("-844.5530620517286511", "1947825396031.6933708908343230", Less), |
| 1255 |
("844.5530620517286511", "-1947825396031.6933708908343230", Greater), |
| 1256 |
("-844.5530620517286511", "-1947825396031.6933708908343230", Greater), |
| 1257 |
// 110 101 different scale |
| 1258 |
("0.2301405445512525317", "245433629587.71206426704897154", Less), |
| 1259 |
("-0.2301405445512525317", "245433629587.71206426704897154", Less), |
| 1260 |
("0.2301405445512525317", "-245433629587.71206426704897154", Greater), |
| 1261 |
("-0.2301405445512525317", "-245433629587.71206426704897154", Greater), |
| 1262 |
// 110 011 same scale |
| 1263 |
("844.5530620517286511", "3637850451015.0843464291450880", Less), |
| 1264 |
("-844.5530620517286511", "3637850451015.0843464291450880", Less), |
| 1265 |
("844.5530620517286511", "-3637850451015.0843464291450880", Greater), |
| 1266 |
("-844.5530620517286511", "-3637850451015.0843464291450880", Greater), |
| 1267 |
// 110 011 different scale |
| 1268 |
("0.00000000717944802566514691", "18143443615.480512395717115904", Less), |
| 1269 |
("-0.00000000717944802566514691", "18143443615.480512395717115904", Less), |
| 1270 |
( |
| 1271 |
"0.00000000717944802566514691", |
| 1272 |
"-18143443615.480512395717115904", |
| 1273 |
Greater, |
| 1274 |
), |
| 1275 |
( |
| 1276 |
"-0.00000000717944802566514691", |
| 1277 |
"-18143443615.480512395717115904", |
| 1278 |
Greater, |
| 1279 |
), |
| 1280 |
// 110 111 same scale |
| 1281 |
("844.5530620517286511", "2738424264600.4917875777303163", Less), |
| 1282 |
("-844.5530620517286511", "2738424264600.4917875777303163", Less), |
| 1283 |
("844.5530620517286511", "-2738424264600.4917875777303163", Greater), |
| 1284 |
("-844.5530620517286511", "-2738424264600.4917875777303163", Greater), |
| 1285 |
// 110 111 different scale |
| 1286 |
("0.0000000007762706076409491335", "2489879185787497651.6458518595", Less), |
| 1287 |
( |
| 1288 |
"-0.0000000007762706076409491335", |
| 1289 |
"2489879185787497651.6458518595", |
| 1290 |
Less, |
| 1291 |
), |
| 1292 |
( |
| 1293 |
"0.0000000007762706076409491335", |
| 1294 |
"-2489879185787497651.6458518595", |
| 1295 |
Greater, |
| 1296 |
), |
| 1297 |
( |
| 1298 |
"-0.0000000007762706076409491335", |
| 1299 |
"-2489879185787497651.6458518595", |
| 1300 |
Greater, |
| 1301 |
), |
| 1302 |
// 001 equality |
| 1303 |
("316007568232.9263258873102336", "316007568232.9263258873102336", Equal), |
| 1304 |
// 001 000 same scale |
| 1305 |
("316007568232.9263258873102336", "0.0000000000000000", Greater), |
| 1306 |
("-316007568232.9263258873102336", "0.0000000000000000", Less), |
| 1307 |
("316007568232.9263258873102336", "-0.0000000000000000", Greater), |
| 1308 |
("-316007568232.9263258873102336", "-0.0000000000000000", Less), |
| 1309 |
// 001 000 different scale |
| 1310 |
("3522055990024364385815547084.8", "0.000000000000", Greater), |
| 1311 |
("-3522055990024364385815547084.8", "0.000000000000", Less), |
| 1312 |
("3522055990024364385815547084.8", "-0.000000000000", Greater), |
| 1313 |
("-3522055990024364385815547084.8", "-0.000000000000", Less), |
| 1314 |
// 001 100 same scale |
| 1315 |
("316007568232.9263258873102336", "0.0000001073412971", Greater), |
| 1316 |
("-316007568232.9263258873102336", "0.0000001073412971", Less), |
| 1317 |
("316007568232.9263258873102336", "-0.0000001073412971", Greater), |
| 1318 |
("-316007568232.9263258873102336", "-0.0000001073412971", Less), |
| 1319 |
// 001 100 different scale |
| 1320 |
("1319006.0491408208640440532992", "0.00000000000000611866432", Greater), |
| 1321 |
("-1319006.0491408208640440532992", "0.00000000000000611866432", Less), |
| 1322 |
("1319006.0491408208640440532992", "-0.00000000000000611866432", Greater), |
| 1323 |
("-1319006.0491408208640440532992", "-0.00000000000000611866432", Less), |
| 1324 |
// 001 010 same scale |
| 1325 |
("316007568232.9263258873102336", "159.1054215143227392", Greater), |
| 1326 |
("-316007568232.9263258873102336", "159.1054215143227392", Less), |
| 1327 |
("316007568232.9263258873102336", "-159.1054215143227392", Greater), |
| 1328 |
("-316007568232.9263258873102336", "-159.1054215143227392", Less), |
| 1329 |
// 001 010 different scale |
| 1330 |
("2470144.7146711063666704252928", "211.0186916505714688", Greater), |
| 1331 |
("-2470144.7146711063666704252928", "211.0186916505714688", Less), |
| 1332 |
("2470144.7146711063666704252928", "-211.0186916505714688", Greater), |
| 1333 |
("-2470144.7146711063666704252928", "-211.0186916505714688", Less), |
| 1334 |
// 001 110 same scale |
| 1335 |
("316007568232.9263258873102336", "15.1186658969096112", Greater), |
| 1336 |
("-316007568232.9263258873102336", "15.1186658969096112", Less), |
| 1337 |
("316007568232.9263258873102336", "-15.1186658969096112", Greater), |
| 1338 |
("-316007568232.9263258873102336", "-15.1186658969096112", Less), |
| 1339 |
// 001 110 different scale |
| 1340 |
("3840504199004148630832.3360768", "7581138850996748864", Greater), |
| 1341 |
("-3840504199004148630832.3360768", "7581138850996748864", Less), |
| 1342 |
("3840504199004148630832.3360768", "-7581138850996748864", Greater), |
| 1343 |
("-3840504199004148630832.3360768", "-7581138850996748864", Less), |
| 1344 |
// 001 001 same scale |
| 1345 |
("316007568232.9263258873102336", "810157633226.6053390856880128", Less), |
| 1346 |
("-316007568232.9263258873102336", "810157633226.6053390856880128", Less), |
| 1347 |
( |
| 1348 |
"316007568232.9263258873102336", |
| 1349 |
"-810157633226.6053390856880128", |
| 1350 |
Greater, |
| 1351 |
), |
| 1352 |
( |
| 1353 |
"-316007568232.9263258873102336", |
| 1354 |
"-810157633226.6053390856880128", |
| 1355 |
Greater, |
| 1356 |
), |
| 1357 |
// 001 001 different scale |
| 1358 |
("1951046382014.4037956952260608", "3626102772868740412010083.1232", Less), |
| 1359 |
( |
| 1360 |
"-1951046382014.4037956952260608", |
| 1361 |
"3626102772868740412010083.1232", |
| 1362 |
Less, |
| 1363 |
), |
| 1364 |
( |
| 1365 |
"1951046382014.4037956952260608", |
| 1366 |
"-3626102772868740412010083.1232", |
| 1367 |
Greater, |
| 1368 |
), |
| 1369 |
( |
| 1370 |
"-1951046382014.4037956952260608", |
| 1371 |
"-3626102772868740412010083.1232", |
| 1372 |
Greater, |
| 1373 |
), |
| 1374 |
// 001 101 same scale |
| 1375 |
("316007568232.9263258873102336", "3258394380359.1965879291312453", Less), |
| 1376 |
("-316007568232.9263258873102336", "3258394380359.1965879291312453", Less), |
| 1377 |
( |
| 1378 |
"316007568232.9263258873102336", |
| 1379 |
"-3258394380359.1965879291312453", |
| 1380 |
Greater, |
| 1381 |
), |
| 1382 |
( |
| 1383 |
"-316007568232.9263258873102336", |
| 1384 |
"-3258394380359.1965879291312453", |
| 1385 |
Greater, |
| 1386 |
), |
| 1387 |
// 001 101 different scale |
| 1388 |
( |
| 1389 |
"17580513970289834.943527780352", |
| 1390 |
"3.7977957031395371036126086595", |
| 1391 |
Greater, |
| 1392 |
), |
| 1393 |
( |
| 1394 |
"-17580513970289834.943527780352", |
| 1395 |
"3.7977957031395371036126086595", |
| 1396 |
Less, |
| 1397 |
), |
| 1398 |
( |
| 1399 |
"17580513970289834.943527780352", |
| 1400 |
"-3.7977957031395371036126086595", |
| 1401 |
Greater, |
| 1402 |
), |
| 1403 |
( |
| 1404 |
"-17580513970289834.943527780352", |
| 1405 |
"-3.7977957031395371036126086595", |
| 1406 |
Less, |
| 1407 |
), |
| 1408 |
// 001 011 same scale |
| 1409 |
("316007568232.9263258873102336", "1154574080460.9867510617997312", Less), |
| 1410 |
("-316007568232.9263258873102336", "1154574080460.9867510617997312", Less), |
| 1411 |
( |
| 1412 |
"316007568232.9263258873102336", |
| 1413 |
"-1154574080460.9867510617997312", |
| 1414 |
Greater, |
| 1415 |
), |
| 1416 |
( |
| 1417 |
"-316007568232.9263258873102336", |
| 1418 |
"-1154574080460.9867510617997312", |
| 1419 |
Greater, |
| 1420 |
), |
| 1421 |
// 001 011 different scale |
| 1422 |
("2008379587.5525351789031325696", "32824109460554.341800487157760", Less), |
| 1423 |
( |
| 1424 |
"-2008379587.5525351789031325696", |
| 1425 |
"32824109460554.341800487157760", |
| 1426 |
Less, |
| 1427 |
), |
| 1428 |
( |
| 1429 |
"2008379587.5525351789031325696", |
| 1430 |
"-32824109460554.341800487157760", |
| 1431 |
Greater, |
| 1432 |
), |
| 1433 |
( |
| 1434 |
"-2008379587.5525351789031325696", |
| 1435 |
"-32824109460554.341800487157760", |
| 1436 |
Greater, |
| 1437 |
), |
| 1438 |
// 001 111 same scale |
| 1439 |
("316007568232.9263258873102336", "2816795479724.6069787794805311", Less), |
| 1440 |
("-316007568232.9263258873102336", "2816795479724.6069787794805311", Less), |
| 1441 |
( |
| 1442 |
"316007568232.9263258873102336", |
| 1443 |
"-2816795479724.6069787794805311", |
| 1444 |
Greater, |
| 1445 |
), |
| 1446 |
( |
| 1447 |
"-316007568232.9263258873102336", |
| 1448 |
"-2816795479724.6069787794805311", |
| 1449 |
Greater, |
| 1450 |
), |
| 1451 |
// 001 111 different scale |
| 1452 |
( |
| 1453 |
"3536806574745420013541890.4576", |
| 1454 |
"9793146.81730411145833529126", |
| 1455 |
Greater, |
| 1456 |
), |
| 1457 |
("-3536806574745420013541890.4576", "9793146.81730411145833529126", Less), |
| 1458 |
( |
| 1459 |
"3536806574745420013541890.4576", |
| 1460 |
"-9793146.81730411145833529126", |
| 1461 |
Greater, |
| 1462 |
), |
| 1463 |
("-3536806574745420013541890.4576", "-9793146.81730411145833529126", Less), |
| 1464 |
// 101 equality |
| 1465 |
( |
| 1466 |
"254208186622762823842.71629992", |
| 1467 |
"254208186622762823842.71629992", |
| 1468 |
Equal, |
| 1469 |
), |
| 1470 |
// 101 000 same scale |
| 1471 |
("254208186622762823842.71629992", "0.00000000", Greater), |
| 1472 |
("-254208186622762823842.71629992", "0.00000000", Less), |
| 1473 |
("254208186622762823842.71629992", "-0.00000000", Greater), |
| 1474 |
("-254208186622762823842.71629992", "-0.00000000", Less), |
| 1475 |
// 101 000 different scale |
| 1476 |
("975421950664039.3614304091804", "0.0000000000000000", Greater), |
| 1477 |
("-975421950664039.3614304091804", "0.0000000000000000", Less), |
| 1478 |
("975421950664039.3614304091804", "-0.0000000000000000", Greater), |
| 1479 |
("-975421950664039.3614304091804", "-0.0000000000000000", Less), |
| 1480 |
// 101 100 same scale |
| 1481 |
("254208186622762823842.71629992", "10.74141379", Greater), |
| 1482 |
("-254208186622762823842.71629992", "10.74141379", Less), |
| 1483 |
("254208186622762823842.71629992", "-10.74141379", Greater), |
| 1484 |
("-254208186622762823842.71629992", "-10.74141379", Less), |
| 1485 |
// 101 100 different scale |
| 1486 |
("2552221405032275.8358630506229", "0.000000000000000592656995", Greater), |
| 1487 |
("-2552221405032275.8358630506229", "0.000000000000000592656995", Less), |
| 1488 |
("2552221405032275.8358630506229", "-0.000000000000000592656995", Greater), |
| 1489 |
("-2552221405032275.8358630506229", "-0.000000000000000592656995", Less), |
| 1490 |
// 101 010 same scale |
| 1491 |
("254208186622762823842.71629992", "62767493748.48499712", Greater), |
| 1492 |
("-254208186622762823842.71629992", "62767493748.48499712", Less), |
| 1493 |
("254208186622762823842.71629992", "-62767493748.48499712", Greater), |
| 1494 |
("-254208186622762823842.71629992", "-62767493748.48499712", Less), |
| 1495 |
// 101 010 different scale |
| 1496 |
("197346074219.25327589999174264", "0.7623493575178715136", Greater), |
| 1497 |
("-197346074219.25327589999174264", "0.7623493575178715136", Less), |
| 1498 |
("197346074219.25327589999174264", "-0.7623493575178715136", Greater), |
| 1499 |
("-197346074219.25327589999174264", "-0.7623493575178715136", Less), |
| 1500 |
// 101 110 same scale |
| 1501 |
("254208186622762823842.71629992", "76597126194.51389094", Greater), |
| 1502 |
("-254208186622762823842.71629992", "76597126194.51389094", Less), |
| 1503 |
("254208186622762823842.71629992", "-76597126194.51389094", Greater), |
| 1504 |
("-254208186622762823842.71629992", "-76597126194.51389094", Less), |
| 1505 |
// 101 110 different scale |
| 1506 |
("25899773651648.380071130043467", "61306258142804903.38", Less), |
| 1507 |
("-25899773651648.380071130043467", "61306258142804903.38", Less), |
| 1508 |
("25899773651648.380071130043467", "-61306258142804903.38", Greater), |
| 1509 |
("-25899773651648.380071130043467", "-61306258142804903.38", Greater), |
| 1510 |
// 101 001 same scale |
| 1511 |
( |
| 1512 |
"254208186622762823842.71629992", |
| 1513 |
"83547191565151621967.28086528", |
| 1514 |
Greater, |
| 1515 |
), |
| 1516 |
("-254208186622762823842.71629992", "83547191565151621967.28086528", Less), |
| 1517 |
( |
| 1518 |
"254208186622762823842.71629992", |
| 1519 |
"-83547191565151621967.28086528", |
| 1520 |
Greater, |
| 1521 |
), |
| 1522 |
( |
| 1523 |
"-254208186622762823842.71629992", |
| 1524 |
"-83547191565151621967.28086528", |
| 1525 |
Less, |
| 1526 |
), |
| 1527 |
// 101 001 different scale |
| 1528 |
("244762.90302171293318719286219", "9964072.600255221193011888128", Less), |
| 1529 |
("-244762.90302171293318719286219", "9964072.600255221193011888128", Less), |
| 1530 |
( |
| 1531 |
"244762.90302171293318719286219", |
| 1532 |
"-9964072.600255221193011888128", |
| 1533 |
Greater, |
| 1534 |
), |
| 1535 |
( |
| 1536 |
"-244762.90302171293318719286219", |
| 1537 |
"-9964072.600255221193011888128", |
| 1538 |
Greater, |
| 1539 |
), |
| 1540 |
// 101 101 same scale |
| 1541 |
( |
| 1542 |
"254208186622762823842.71629992", |
| 1543 |
"106541875981662806348.63716235", |
| 1544 |
Greater, |
| 1545 |
), |
| 1546 |
( |
| 1547 |
"-254208186622762823842.71629992", |
| 1548 |
"106541875981662806348.63716235", |
| 1549 |
Less, |
| 1550 |
), |
| 1551 |
( |
| 1552 |
"254208186622762823842.71629992", |
| 1553 |
"-106541875981662806348.63716235", |
| 1554 |
Greater, |
| 1555 |
), |
| 1556 |
( |
| 1557 |
"-254208186622762823842.71629992", |
| 1558 |
"-106541875981662806348.63716235", |
| 1559 |
Less, |
| 1560 |
), |
| 1561 |
// 101 101 different scale |
| 1562 |
("362319.18250030256385507568342", "3619454249020577423546109236", Less), |
| 1563 |
("-362319.18250030256385507568342", "3619454249020577423546109236", Less), |
| 1564 |
( |
| 1565 |
"362319.18250030256385507568342", |
| 1566 |
"-3619454249020577423546109236", |
| 1567 |
Greater, |
| 1568 |
), |
| 1569 |
( |
| 1570 |
"-362319.18250030256385507568342", |
| 1571 |
"-3619454249020577423546109236", |
| 1572 |
Greater, |
| 1573 |
), |
| 1574 |
// 101 011 same scale |
| 1575 |
( |
| 1576 |
"254208186622762823842.71629992", |
| 1577 |
"156781478378762688050.06557184", |
| 1578 |
Greater, |
| 1579 |
), |
| 1580 |
( |
| 1581 |
"-254208186622762823842.71629992", |
| 1582 |
"156781478378762688050.06557184", |
| 1583 |
Less, |
| 1584 |
), |
| 1585 |
( |
| 1586 |
"254208186622762823842.71629992", |
| 1587 |
"-156781478378762688050.06557184", |
| 1588 |
Greater, |
| 1589 |
), |
| 1590 |
( |
| 1591 |
"-254208186622762823842.71629992", |
| 1592 |
"-156781478378762688050.06557184", |
| 1593 |
Less, |
| 1594 |
), |
| 1595 |
// 101 011 different scale |
| 1596 |
("2486073465266.0337130589931876", "153874906950888902858.19691008", Less), |
| 1597 |
( |
| 1598 |
"-2486073465266.0337130589931876", |
| 1599 |
"153874906950888902858.19691008", |
| 1600 |
Less, |
| 1601 |
), |
| 1602 |
( |
| 1603 |
"2486073465266.0337130589931876", |
| 1604 |
"-153874906950888902858.19691008", |
| 1605 |
Greater, |
| 1606 |
), |
| 1607 |
( |
| 1608 |
"-2486073465266.0337130589931876", |
| 1609 |
"-153874906950888902858.19691008", |
| 1610 |
Greater, |
| 1611 |
), |
| 1612 |
// 101 111 same scale |
| 1613 |
( |
| 1614 |
"254208186622762823842.71629992", |
| 1615 |
"10101645723744656462.08148676", |
| 1616 |
Greater, |
| 1617 |
), |
| 1618 |
("-254208186622762823842.71629992", "10101645723744656462.08148676", Less), |
| 1619 |
( |
| 1620 |
"254208186622762823842.71629992", |
| 1621 |
"-10101645723744656462.08148676", |
| 1622 |
Greater, |
| 1623 |
), |
| 1624 |
( |
| 1625 |
"-254208186622762823842.71629992", |
| 1626 |
"-10101645723744656462.08148676", |
| 1627 |
Less, |
| 1628 |
), |
| 1629 |
// 101 111 different scale |
| 1630 |
("14107601965.909635434653634526", "111238758546502973973477.99454", Less), |
| 1631 |
( |
| 1632 |
"-14107601965.909635434653634526", |
| 1633 |
"111238758546502973973477.99454", |
| 1634 |
Less, |
| 1635 |
), |
| 1636 |
( |
| 1637 |
"14107601965.909635434653634526", |
| 1638 |
"-111238758546502973973477.99454", |
| 1639 |
Greater, |
| 1640 |
), |
| 1641 |
( |
| 1642 |
"-14107601965.909635434653634526", |
| 1643 |
"-111238758546502973973477.99454", |
| 1644 |
Greater, |
| 1645 |
), |
| 1646 |
// 011 equality |
| 1647 |
( |
| 1648 |
"272322.48219624218537039495168", |
| 1649 |
"272322.48219624218537039495168", |
| 1650 |
Equal, |
| 1651 |
), |
| 1652 |
// 011 000 same scale |
| 1653 |
("272322.48219624218537039495168", "0.00000000000000000000000", Greater), |
| 1654 |
("-272322.48219624218537039495168", "0.00000000000000000000000", Less), |
| 1655 |
("272322.48219624218537039495168", "-0.00000000000000000000000", Greater), |
| 1656 |
("-272322.48219624218537039495168", "-0.00000000000000000000000", Less), |
| 1657 |
// 011 000 different scale |
| 1658 |
("3214885516.0787854158246969344", "0.00000000000000000", Greater), |
| 1659 |
("-3214885516.0787854158246969344", "0.00000000000000000", Less), |
| 1660 |
("3214885516.0787854158246969344", "-0.00000000000000000", Greater), |
| 1661 |
("-3214885516.0787854158246969344", "-0.00000000000000000", Less), |
| 1662 |
// 011 100 same scale |
| 1663 |
("272322.48219624218537039495168", "0.00000000000000379487994", Greater), |
| 1664 |
("-272322.48219624218537039495168", "0.00000000000000379487994", Less), |
| 1665 |
("272322.48219624218537039495168", "-0.00000000000000379487994", Greater), |
| 1666 |
("-272322.48219624218537039495168", "-0.00000000000000379487994", Less), |
| 1667 |
// 011 100 different scale |
| 1668 |
("388166715906.19371912596291584", "0.000000000000001996700736", Greater), |
| 1669 |
("-388166715906.19371912596291584", "0.000000000000001996700736", Less), |
| 1670 |
("388166715906.19371912596291584", "-0.000000000000001996700736", Greater), |
| 1671 |
("-388166715906.19371912596291584", "-0.000000000000001996700736", Less), |
| 1672 |
// 011 010 same scale |
| 1673 |
("272322.48219624218537039495168", "0.00000175873997328613376", Greater), |
| 1674 |
("-272322.48219624218537039495168", "0.00000175873997328613376", Less), |
| 1675 |
("272322.48219624218537039495168", "-0.00000175873997328613376", Greater), |
| 1676 |
("-272322.48219624218537039495168", "-0.00000175873997328613376", Less), |
| 1677 |
// 011 010 different scale |
| 1678 |
( |
| 1679 |
"17963864.0946434527121637376", |
| 1680 |
"0.0000000001112699367808040960", |
| 1681 |
Greater, |
| 1682 |
), |
| 1683 |
("-17963864.0946434527121637376", "0.0000000001112699367808040960", Less), |
| 1684 |
( |
| 1685 |
"17963864.0946434527121637376", |
| 1686 |
"-0.0000000001112699367808040960", |
| 1687 |
Greater, |
| 1688 |
), |
| 1689 |
("-17963864.0946434527121637376", "-0.0000000001112699367808040960", Less), |
| 1690 |
// 011 110 same scale |
| 1691 |
("272322.48219624218537039495168", "0.00009168252278596474115", Greater), |
| 1692 |
("-272322.48219624218537039495168", "0.00009168252278596474115", Less), |
| 1693 |
("272322.48219624218537039495168", "-0.00009168252278596474115", Greater), |
| 1694 |
("-272322.48219624218537039495168", "-0.00009168252278596474115", Less), |
| 1695 |
// 011 110 different scale |
| 1696 |
("3.1530040332824324172729548800", "0.05636139104712652784", Greater), |
| 1697 |
("-3.1530040332824324172729548800", "0.05636139104712652784", Less), |
| 1698 |
("3.1530040332824324172729548800", "-0.05636139104712652784", Greater), |
| 1699 |
("-3.1530040332824324172729548800", "-0.05636139104712652784", Less), |
| 1700 |
// 011 001 same scale |
| 1701 |
( |
| 1702 |
"272322.48219624218537039495168", |
| 1703 |
"78956.15667671475190631497728", |
| 1704 |
Greater, |
| 1705 |
), |
| 1706 |
("-272322.48219624218537039495168", "78956.15667671475190631497728", Less), |
| 1707 |
( |
| 1708 |
"272322.48219624218537039495168", |
| 1709 |
"-78956.15667671475190631497728", |
| 1710 |
Greater, |
| 1711 |
), |
| 1712 |
( |
| 1713 |
"-272322.48219624218537039495168", |
| 1714 |
"-78956.15667671475190631497728", |
| 1715 |
Less, |
| 1716 |
), |
| 1717 |
// 011 001 different scale |
| 1718 |
( |
| 1719 |
"247159638929.90774677497446400", |
| 1720 |
"18573048.37697991870462820352", |
| 1721 |
Greater, |
| 1722 |
), |
| 1723 |
("-247159638929.90774677497446400", "18573048.37697991870462820352", Less), |
| 1724 |
( |
| 1725 |
"247159638929.90774677497446400", |
| 1726 |
"-18573048.37697991870462820352", |
| 1727 |
Greater, |
| 1728 |
), |
| 1729 |
( |
| 1730 |
"-247159638929.90774677497446400", |
| 1731 |
"-18573048.37697991870462820352", |
| 1732 |
Less, |
| 1733 |
), |
| 1734 |
// 011 101 same scale |
| 1735 |
("272322.48219624218537039495168", "311953.28803357654172947915942", Less), |
| 1736 |
( |
| 1737 |
"-272322.48219624218537039495168", |
| 1738 |
"311953.28803357654172947915942", |
| 1739 |
Less, |
| 1740 |
), |
| 1741 |
( |
| 1742 |
"272322.48219624218537039495168", |
| 1743 |
"-311953.28803357654172947915942", |
| 1744 |
Greater, |
| 1745 |
), |
| 1746 |
( |
| 1747 |
"-272322.48219624218537039495168", |
| 1748 |
"-311953.28803357654172947915942", |
| 1749 |
Greater, |
| 1750 |
), |
| 1751 |
// 011 101 different scale |
| 1752 |
("2922696937234119470.0273745920", "22441101906503785827606686629", Less), |
| 1753 |
("-2922696937234119470.0273745920", "22441101906503785827606686629", Less), |
| 1754 |
( |
| 1755 |
"2922696937234119470.0273745920", |
| 1756 |
"-22441101906503785827606686629", |
| 1757 |
Greater, |
| 1758 |
), |
| 1759 |
( |
| 1760 |
"-2922696937234119470.0273745920", |
| 1761 |
"-22441101906503785827606686629", |
| 1762 |
Greater, |
| 1763 |
), |
| 1764 |
// 011 011 same scale |
| 1765 |
("272322.48219624218537039495168", "348316.28306497394164006649856", Less), |
| 1766 |
( |
| 1767 |
"-272322.48219624218537039495168", |
| 1768 |
"348316.28306497394164006649856", |
| 1769 |
Less, |
| 1770 |
), |
| 1771 |
( |
| 1772 |
"272322.48219624218537039495168", |
| 1773 |
"-348316.28306497394164006649856", |
| 1774 |
Greater, |
| 1775 |
), |
| 1776 |
( |
| 1777 |
"-272322.48219624218537039495168", |
| 1778 |
"-348316.28306497394164006649856", |
| 1779 |
Greater, |
| 1780 |
), |
| 1781 |
// 011 011 different scale |
| 1782 |
("178190346.76624086261395619840", "62208030746.22038852927225856", Less), |
| 1783 |
("-178190346.76624086261395619840", "62208030746.22038852927225856", Less), |
| 1784 |
( |
| 1785 |
"178190346.76624086261395619840", |
| 1786 |
"-62208030746.22038852927225856", |
| 1787 |
Greater, |
| 1788 |
), |
| 1789 |
( |
| 1790 |
"-178190346.76624086261395619840", |
| 1791 |
"-62208030746.22038852927225856", |
| 1792 |
Greater, |
| 1793 |
), |
| 1794 |
// 011 111 same scale |
| 1795 |
( |
| 1796 |
"272322.48219624218537039495168", |
| 1797 |
"41534.52021391898039335355927", |
| 1798 |
Greater, |
| 1799 |
), |
| 1800 |
("-272322.48219624218537039495168", "41534.52021391898039335355927", Less), |
| 1801 |
( |
| 1802 |
"272322.48219624218537039495168", |
| 1803 |
"-41534.52021391898039335355927", |
| 1804 |
Greater, |
| 1805 |
), |
| 1806 |
( |
| 1807 |
"-272322.48219624218537039495168", |
| 1808 |
"-41534.52021391898039335355927", |
| 1809 |
Less, |
| 1810 |
), |
| 1811 |
// 011 111 different scale |
| 1812 |
("11.959910518519677083499626496", "2844684364802261541879551.2259", Less), |
| 1813 |
( |
| 1814 |
"-11.959910518519677083499626496", |
| 1815 |
"2844684364802261541879551.2259", |
| 1816 |
Less, |
| 1817 |
), |
| 1818 |
( |
| 1819 |
"11.959910518519677083499626496", |
| 1820 |
"-2844684364802261541879551.2259", |
| 1821 |
Greater, |
| 1822 |
), |
| 1823 |
( |
| 1824 |
"-11.959910518519677083499626496", |
| 1825 |
"-2844684364802261541879551.2259", |
| 1826 |
Greater, |
| 1827 |
), |
| 1828 |
// 111 equality |
| 1829 |
( |
| 1830 |
"3836286746260530032892706.6174", |
| 1831 |
"3836286746260530032892706.6174", |
| 1832 |
Equal, |
| 1833 |
), |
| 1834 |
// 111 000 same scale |
| 1835 |
("3836286746260530032892706.6174", "0.0000", Greater), |
| 1836 |
("-3836286746260530032892706.6174", "0.0000", Less), |
| 1837 |
("3836286746260530032892706.6174", "-0.0000", Greater), |
| 1838 |
("-3836286746260530032892706.6174", "-0.0000", Less), |
| 1839 |
// 111 000 different scale |
| 1840 |
("4401861854803552.033657814547", "0.0000000", Greater), |
| 1841 |
("-4401861854803552.033657814547", "0.0000000", Less), |
| 1842 |
("4401861854803552.033657814547", "-0.0000000", Greater), |
| 1843 |
("-4401861854803552.033657814547", "-0.0000000", Less), |
| 1844 |
// 111 100 same scale |
| 1845 |
("3836286746260530032892706.6174", "68758.6561", Greater), |
| 1846 |
("-3836286746260530032892706.6174", "68758.6561", Less), |
| 1847 |
("3836286746260530032892706.6174", "-68758.6561", Greater), |
| 1848 |
("-3836286746260530032892706.6174", "-68758.6561", Less), |
| 1849 |
// 111 100 different scale |
| 1850 |
( |
| 1851 |
"18794337354296131695536777.153", |
| 1852 |
"0.000000000000000001563875977", |
| 1853 |
Greater, |
| 1854 |
), |
| 1855 |
("-18794337354296131695536777.153", "0.000000000000000001563875977", Less), |
| 1856 |
( |
| 1857 |
"18794337354296131695536777.153", |
| 1858 |
"-0.000000000000000001563875977", |
| 1859 |
Greater, |
| 1860 |
), |
| 1861 |
( |
| 1862 |
"-18794337354296131695536777.153", |
| 1863 |
"-0.000000000000000001563875977", |
| 1864 |
Less, |
| 1865 |
), |
| 1866 |
// 111 010 same scale |
| 1867 |
("3836286746260530032892706.6174", "439097665563236.7616", Greater), |
| 1868 |
("-3836286746260530032892706.6174", "439097665563236.7616", Less), |
| 1869 |
("3836286746260530032892706.6174", "-439097665563236.7616", Greater), |
| 1870 |
("-3836286746260530032892706.6174", "-439097665563236.7616", Less), |
| 1871 |
// 111 010 different scale |
| 1872 |
("219364497389.57405761662363679", "0.6569644274462228480", Greater), |
| 1873 |
("-219364497389.57405761662363679", "0.6569644274462228480", Less), |
| 1874 |
("219364497389.57405761662363679", "-0.6569644274462228480", Greater), |
| 1875 |
("-219364497389.57405761662363679", "-0.6569644274462228480", Less), |
| 1876 |
// 111 110 same scale |
| 1877 |
("3836286746260530032892706.6174", "100013274294974.8269", Greater), |
| 1878 |
("-3836286746260530032892706.6174", "100013274294974.8269", Less), |
| 1879 |
("3836286746260530032892706.6174", "-100013274294974.8269", Greater), |
| 1880 |
("-3836286746260530032892706.6174", "-100013274294974.8269", Less), |
| 1881 |
// 111 110 different scale |
| 1882 |
("76072704083682.85472479207171", "50.52437989651117182", Greater), |
| 1883 |
("-76072704083682.85472479207171", "50.52437989651117182", Less), |
| 1884 |
("76072704083682.85472479207171", "-50.52437989651117182", Greater), |
| 1885 |
("-76072704083682.85472479207171", "-50.52437989651117182", Less), |
| 1886 |
// 111 001 same scale |
| 1887 |
( |
| 1888 |
"3836286746260530032892706.6174", |
| 1889 |
"2766133872545894272402142.0032", |
| 1890 |
Greater, |
| 1891 |
), |
| 1892 |
( |
| 1893 |
"-3836286746260530032892706.6174", |
| 1894 |
"2766133872545894272402142.0032", |
| 1895 |
Less, |
| 1896 |
), |
| 1897 |
( |
| 1898 |
"3836286746260530032892706.6174", |
| 1899 |
"-2766133872545894272402142.0032", |
| 1900 |
Greater, |
| 1901 |
), |
| 1902 |
( |
| 1903 |
"-3836286746260530032892706.6174", |
| 1904 |
"-2766133872545894272402142.0032", |
| 1905 |
Less, |
| 1906 |
), |
| 1907 |
// 111 001 different scale |
| 1908 |
( |
| 1909 |
"38199979438250010.80610984395", |
| 1910 |
"31104752430710.408848162684928", |
| 1911 |
Greater, |
| 1912 |
), |
| 1913 |
("-38199979438250010.80610984395", "31104752430710.408848162684928", Less), |
| 1914 |
( |
| 1915 |
"38199979438250010.80610984395", |
| 1916 |
"-31104752430710.408848162684928", |
| 1917 |
Greater, |
| 1918 |
), |
| 1919 |
( |
| 1920 |
"-38199979438250010.80610984395", |
| 1921 |
"-31104752430710.408848162684928", |
| 1922 |
Less, |
| 1923 |
), |
| 1924 |
// 111 101 same scale |
| 1925 |
( |
| 1926 |
"3836286746260530032892706.6174", |
| 1927 |
"441847458119168110406908.6115", |
| 1928 |
Greater, |
| 1929 |
), |
| 1930 |
("-3836286746260530032892706.6174", "441847458119168110406908.6115", Less), |
| 1931 |
( |
| 1932 |
"3836286746260530032892706.6174", |
| 1933 |
"-441847458119168110406908.6115", |
| 1934 |
Greater, |
| 1935 |
), |
| 1936 |
( |
| 1937 |
"-3836286746260530032892706.6174", |
| 1938 |
"-441847458119168110406908.6115", |
| 1939 |
Less, |
| 1940 |
), |
| 1941 |
// 111 101 different scale |
| 1942 |
("255945012905633524.15746865235", "1005021647855597114428453997.8", Less), |
| 1943 |
( |
| 1944 |
"-255945012905633524.15746865235", |
| 1945 |
"1005021647855597114428453997.8", |
| 1946 |
Less, |
| 1947 |
), |
| 1948 |
( |
| 1949 |
"255945012905633524.15746865235", |
| 1950 |
"-1005021647855597114428453997.8", |
| 1951 |
Greater, |
| 1952 |
), |
| 1953 |
( |
| 1954 |
"-255945012905633524.15746865235", |
| 1955 |
"-1005021647855597114428453997.8", |
| 1956 |
Greater, |
| 1957 |
), |
| 1958 |
// 111 011 same scale |
| 1959 |
( |
| 1960 |
"3836286746260530032892706.6174", |
| 1961 |
"1111481055212557787730018.3040", |
| 1962 |
Greater, |
| 1963 |
), |
| 1964 |
( |
| 1965 |
"-3836286746260530032892706.6174", |
| 1966 |
"1111481055212557787730018.3040", |
| 1967 |
Less, |
| 1968 |
), |
| 1969 |
( |
| 1970 |
"3836286746260530032892706.6174", |
| 1971 |
"-1111481055212557787730018.3040", |
| 1972 |
Greater, |
| 1973 |
), |
| 1974 |
( |
| 1975 |
"-3836286746260530032892706.6174", |
| 1976 |
"-1111481055212557787730018.3040", |
| 1977 |
Less, |
| 1978 |
), |
| 1979 |
// 111 011 different scale |
| 1980 |
( |
| 1981 |
"79710135995301690627798250.27", |
| 1982 |
"4613684285077.479267304996864", |
| 1983 |
Greater, |
| 1984 |
), |
| 1985 |
("-79710135995301690627798250.27", "4613684285077.479267304996864", Less), |
| 1986 |
( |
| 1987 |
"79710135995301690627798250.27", |
| 1988 |
"-4613684285077.479267304996864", |
| 1989 |
Greater, |
| 1990 |
), |
| 1991 |
("-79710135995301690627798250.27", "-4613684285077.479267304996864", Less), |
| 1992 |
// 111 111 same scale |
| 1993 |
( |
| 1994 |
"3836286746260530032892706.6174", |
| 1995 |
"1881105048659612897896770.8539", |
| 1996 |
Greater, |
| 1997 |
), |
| 1998 |
( |
| 1999 |
"-3836286746260530032892706.6174", |
| 2000 |
"1881105048659612897896770.8539", |
| 2001 |
Less, |
| 2002 |
), |
| 2003 |
( |
| 2004 |
"3836286746260530032892706.6174", |
| 2005 |
"-1881105048659612897896770.8539", |
| 2006 |
Greater, |
| 2007 |
), |
| 2008 |
( |
| 2009 |
"-3836286746260530032892706.6174", |
| 2010 |
"-1881105048659612897896770.8539", |
| 2011 |
Less, |
| 2012 |
), |
| 2013 |
// 111 111 different scale |
| 2014 |
( |
| 2015 |
"3879592276836332218003.2886500", |
| 2016 |
"35612499407667292.686490959658", |
| 2017 |
Greater, |
| 2018 |
), |
| 2019 |
( |
| 2020 |
"-3879592276836332218003.2886500", |
| 2021 |
"35612499407667292.686490959658", |
| 2022 |
Less, |
| 2023 |
), |
| 2024 |
( |
| 2025 |
"3879592276836332218003.2886500", |
| 2026 |
"-35612499407667292.686490959658", |
| 2027 |
Greater, |
| 2028 |
), |
| 2029 |
( |
| 2030 |
"-3879592276836332218003.2886500", |
| 2031 |
"-35612499407667292.686490959658", |
| 2032 |
Less, |
| 2033 |
), |
| 2034 |
]; |
| 2035 |
for &(a, b, c) in tests { |
| 2036 |
cmp(a, b, c); |
| 2037 |
} |
| 2038 |
} |
| 2039 |
|
| 2040 |
#[test] |
| 2041 |
fn it_floors_decimals() { |
| 2042 |
let tests = &[ |
| 2043 |
("1", "1"), |
| 2044 |
("1.00", "1"), |
| 2045 |
("1.2345", "1"), |
| 2046 |
("-1", "-1"), |
| 2047 |
("-1.00", "-1"), |
| 2048 |
("-1.2345", "-2"), |
| 2049 |
]; |
| 2050 |
for &(a, expected) in tests { |
| 2051 |
let a = Decimal::from_str(a).unwrap(); |
| 2052 |
assert_eq!(expected, a.floor().to_string(), "Failed flooring {}", a); |
| 2053 |
} |
| 2054 |
} |
| 2055 |
|
| 2056 |
#[test] |
| 2057 |
fn it_ceils_decimals() { |
| 2058 |
let tests = &[ |
| 2059 |
("1", "1"), |
| 2060 |
("1.00", "1"), |
| 2061 |
("1.2345", "2"), |
| 2062 |
("-1", "-1"), |
| 2063 |
("-1.00", "-1"), |
| 2064 |
("-1.2345", "-1"), |
| 2065 |
]; |
| 2066 |
for &(a, expected) in tests { |
| 2067 |
let a = Decimal::from_str(a).unwrap(); |
| 2068 |
assert_eq!(expected, a.ceil().to_string(), "Failed ceiling {}", a); |
| 2069 |
} |
| 2070 |
} |
| 2071 |
|
| 2072 |
#[test] |
| 2073 |
fn it_finds_max_of_two() { |
| 2074 |
let tests = &[("1", "1", "1"), ("2", "1", "2"), ("1", "2", "2")]; |
| 2075 |
for &(a, b, expected) in tests { |
| 2076 |
let a = Decimal::from_str(a).unwrap(); |
| 2077 |
let b = Decimal::from_str(b).unwrap(); |
| 2078 |
assert_eq!(expected, a.max(b).to_string()); |
| 2079 |
} |
| 2080 |
} |
| 2081 |
|
| 2082 |
#[test] |
| 2083 |
fn it_finds_min_of_two() { |
| 2084 |
let tests = &[("1", "1", "1"), ("2", "1", "1"), ("1", "2", "1")]; |
| 2085 |
for &(a, b, expected) in tests { |
| 2086 |
let a = Decimal::from_str(a).unwrap(); |
| 2087 |
let b = Decimal::from_str(b).unwrap(); |
| 2088 |
assert_eq!(expected, a.min(b).to_string()); |
| 2089 |
} |
| 2090 |
} |
| 2091 |
|
| 2092 |
#[test] |
| 2093 |
fn test_max_compares() { |
| 2094 |
let x = "225.33543601344182".parse::<Decimal>().unwrap(); |
| 2095 |
let y = Decimal::MAX; |
| 2096 |
assert!(x < y); |
| 2097 |
assert!(y > x); |
| 2098 |
assert_ne!(y, x); |
| 2099 |
} |
| 2100 |
|
| 2101 |
#[test] |
| 2102 |
fn test_min_compares() { |
| 2103 |
let x = "225.33543601344182".parse::<Decimal>().unwrap(); |
| 2104 |
let y = Decimal::MIN; |
| 2105 |
assert!(x > y); |
| 2106 |
assert!(y < x); |
| 2107 |
assert_ne!(y, x); |
| 2108 |
} |
| 2109 |
|
| 2110 |
#[test] |
| 2111 |
fn it_can_parse_from_i32() { |
| 2112 |
use num_traits::FromPrimitive; |
| 2113 |
|
| 2114 |
let tests = &[ |
| 2115 |
(0i32, "0"), |
| 2116 |
(1i32, "1"), |
| 2117 |
(-1i32, "-1"), |
| 2118 |
(i32::MAX, "2147483647"), |
| 2119 |
(i32::MIN, "-2147483648"), |
| 2120 |
]; |
| 2121 |
for &(input, expected) in tests { |
| 2122 |
let parsed = Decimal::from_i32(input).unwrap(); |
| 2123 |
assert_eq!( |
| 2124 |
expected, |
| 2125 |
parsed.to_string(), |
| 2126 |
"expected {} does not match parsed {}", |
| 2127 |
expected, |
| 2128 |
parsed |
| 2129 |
); |
| 2130 |
assert_eq!( |
| 2131 |
input.to_string(), |
| 2132 |
parsed.to_string(), |
| 2133 |
"i32 to_string {} does not match parsed {}", |
| 2134 |
input, |
| 2135 |
parsed |
| 2136 |
); |
| 2137 |
} |
| 2138 |
} |
| 2139 |
|
| 2140 |
#[test] |
| 2141 |
fn it_can_parse_from_i64() { |
| 2142 |
use num_traits::FromPrimitive; |
| 2143 |
|
| 2144 |
let tests = &[ |
| 2145 |
(0i64, "0"), |
| 2146 |
(1i64, "1"), |
| 2147 |
(-1i64, "-1"), |
| 2148 |
(i64::MAX, "9223372036854775807"), |
| 2149 |
(i64::MIN, "-9223372036854775808"), |
| 2150 |
]; |
| 2151 |
for &(input, expected) in tests { |
| 2152 |
let parsed = Decimal::from_i64(input).unwrap(); |
| 2153 |
assert_eq!( |
| 2154 |
expected, |
| 2155 |
parsed.to_string(), |
| 2156 |
"expected {} does not match parsed {}", |
| 2157 |
expected, |
| 2158 |
parsed |
| 2159 |
); |
| 2160 |
assert_eq!( |
| 2161 |
input.to_string(), |
| 2162 |
parsed.to_string(), |
| 2163 |
"i64 to_string {} does not match parsed {}", |
| 2164 |
input, |
| 2165 |
parsed |
| 2166 |
); |
| 2167 |
} |
| 2168 |
} |
| 2169 |
|
| 2170 |
#[test] |
| 2171 |
fn it_can_round_to_2dp() { |
| 2172 |
let a = Decimal::from_str("6.12345").unwrap(); |
| 2173 |
let b = (Decimal::from_str("100").unwrap() * a).round() / Decimal::from_str("100").unwrap(); |
| 2174 |
assert_eq!("6.12", b.to_string()); |
| 2175 |
} |
| 2176 |
|
| 2177 |
#[test] |
| 2178 |
fn it_can_round_using_basic_midpoint_rules() { |
| 2179 |
let tests = &[ |
| 2180 |
("3.5", RoundingStrategy::MidpointAwayFromZero, "4"), |
| 2181 |
("2.8", RoundingStrategy::MidpointAwayFromZero, "3"), |
| 2182 |
("2.5", RoundingStrategy::MidpointAwayFromZero, "3"), |
| 2183 |
("2.1", RoundingStrategy::MidpointAwayFromZero, "2"), |
| 2184 |
("-2.1", RoundingStrategy::MidpointAwayFromZero, "-2"), |
| 2185 |
("-2.5", RoundingStrategy::MidpointAwayFromZero, "-3"), |
| 2186 |
("-2.8", RoundingStrategy::MidpointAwayFromZero, "-3"), |
| 2187 |
("-3.5", RoundingStrategy::MidpointAwayFromZero, "-4"), |
| 2188 |
("3.5", RoundingStrategy::MidpointNearestEven, "4"), |
| 2189 |
("2.8", RoundingStrategy::MidpointNearestEven, "3"), |
| 2190 |
("2.5", RoundingStrategy::MidpointNearestEven, "2"), |
| 2191 |
("2.1", RoundingStrategy::MidpointNearestEven, "2"), |
| 2192 |
("-2.1", RoundingStrategy::MidpointNearestEven, "-2"), |
| 2193 |
("-2.5", RoundingStrategy::MidpointNearestEven, "-2"), |
| 2194 |
("-2.8", RoundingStrategy::MidpointNearestEven, "-3"), |
| 2195 |
("-3.5", RoundingStrategy::MidpointNearestEven, "-4"), |
| 2196 |
("3.5", RoundingStrategy::MidpointTowardZero, "3"), |
| 2197 |
("2.8", RoundingStrategy::MidpointTowardZero, "3"), |
| 2198 |
("2.5", RoundingStrategy::MidpointTowardZero, "2"), |
| 2199 |
("2.1", RoundingStrategy::MidpointTowardZero, "2"), |
| 2200 |
("-2.1", RoundingStrategy::MidpointTowardZero, "-2"), |
| 2201 |
("-2.5", RoundingStrategy::MidpointTowardZero, "-2"), |
| 2202 |
("-2.8", RoundingStrategy::MidpointTowardZero, "-3"), |
| 2203 |
("-3.5", RoundingStrategy::MidpointTowardZero, "-3"), |
| 2204 |
("2.8", RoundingStrategy::ToNegativeInfinity, "2"), |
| 2205 |
("2.5", RoundingStrategy::ToNegativeInfinity, "2"), |
| 2206 |
("2.1", RoundingStrategy::ToNegativeInfinity, "2"), |
| 2207 |
("-2.1", RoundingStrategy::ToNegativeInfinity, "-3"), |
| 2208 |
("-2.5", RoundingStrategy::ToNegativeInfinity, "-3"), |
| 2209 |
("-2.8", RoundingStrategy::ToNegativeInfinity, "-3"), |
| 2210 |
("2.8", RoundingStrategy::ToPositiveInfinity, "3"), |
| 2211 |
("2.5", RoundingStrategy::ToPositiveInfinity, "3"), |
| 2212 |
("2.1", RoundingStrategy::ToPositiveInfinity, "3"), |
| 2213 |
("-2.1", RoundingStrategy::ToPositiveInfinity, "-2"), |
| 2214 |
("-2.5", RoundingStrategy::ToPositiveInfinity, "-2"), |
| 2215 |
("-2.8", RoundingStrategy::ToPositiveInfinity, "-2"), |
| 2216 |
("2.8", RoundingStrategy::ToZero, "2"), |
| 2217 |
("2.5", RoundingStrategy::ToZero, "2"), |
| 2218 |
("2.1", RoundingStrategy::ToZero, "2"), |
| 2219 |
("-2.1", RoundingStrategy::ToZero, "-2"), |
| 2220 |
("-2.5", RoundingStrategy::ToZero, "-2"), |
| 2221 |
("-2.8", RoundingStrategy::ToZero, "-2"), |
| 2222 |
("2.8", RoundingStrategy::AwayFromZero, "3"), |
| 2223 |
("2.5", RoundingStrategy::AwayFromZero, "3"), |
| 2224 |
("2.1", RoundingStrategy::AwayFromZero, "3"), |
| 2225 |
("-2.1", RoundingStrategy::AwayFromZero, "-3"), |
| 2226 |
("-2.5", RoundingStrategy::AwayFromZero, "-3"), |
| 2227 |
("-2.8", RoundingStrategy::AwayFromZero, "-3"), |
| 2228 |
]; |
| 2229 |
|
| 2230 |
for &(input, strategy, expected) in tests { |
| 2231 |
let a = Decimal::from_str(input).unwrap(); |
| 2232 |
let b = a.round_dp_with_strategy(0, strategy); |
| 2233 |
assert_eq!(expected, b.to_string(), "{} > {} for {:?}", input, expected, strategy); |
| 2234 |
} |
| 2235 |
} |
| 2236 |
|
| 2237 |
#[test] |
| 2238 |
fn it_can_round_using_bankers_rounding() { |
| 2239 |
let tests = &[ |
| 2240 |
("6.12345", 2, "6.12"), |
| 2241 |
("6.126", 2, "6.13"), |
| 2242 |
("-6.126", 2, "-6.13"), |
| 2243 |
("6.5", 0, "6"), |
| 2244 |
("7.5", 0, "8"), |
| 2245 |
("1.2250", 2, "1.22"), |
| 2246 |
("1.2252", 2, "1.23"), |
| 2247 |
("1.2249", 2, "1.22"), |
| 2248 |
("6.1", 2, "6.1"), |
| 2249 |
("0.0000", 2, "0.00"), |
| 2250 |
("0.6666666666666666666666666666", 2, "0.67"), |
| 2251 |
("1.40", 0, "1"), |
| 2252 |
("2.60", 0, "3"), |
| 2253 |
("2.1234567890123456789012345678", 27, "2.123456789012345678901234568"), |
| 2254 |
]; |
| 2255 |
for &(input, dp, expected) in tests { |
| 2256 |
let a = Decimal::from_str(input).unwrap(); |
| 2257 |
#[allow(deprecated)] |
| 2258 |
let b = a.round_dp_with_strategy(dp, RoundingStrategy::BankersRounding); |
| 2259 |
assert_eq!(expected, b.to_string(), "BankersRounding"); |
| 2260 |
|
| 2261 |
// Recommended replacement |
| 2262 |
let b = a.round_dp_with_strategy(dp, RoundingStrategy::MidpointNearestEven); |
| 2263 |
assert_eq!(expected, b.to_string(), "MidpointNearestEven"); |
| 2264 |
} |
| 2265 |
} |
| 2266 |
|
| 2267 |
#[test] |
| 2268 |
fn it_can_round_complex_numbers_using_bankers_rounding() { |
| 2269 |
// Issue #71 |
| 2270 |
let rate = Decimal::new(19, 2); // 0.19 |
| 2271 |
let one = Decimal::new(1, 0); // 1 |
| 2272 |
let part = rate / (rate + one); // 0.19 / (0.19 + 1) = 0.1596638655462184873949579832 |
| 2273 |
|
| 2274 |
#[allow(deprecated)] |
| 2275 |
let part = part.round_dp_with_strategy(2, RoundingStrategy::BankersRounding); // 0.16 |
| 2276 |
assert_eq!("0.16", part.to_string(), "BankersRounding"); |
| 2277 |
|
| 2278 |
// Recommended replacement |
| 2279 |
let part = part.round_dp_with_strategy(2, RoundingStrategy::MidpointNearestEven); // 0.16 |
| 2280 |
assert_eq!("0.16", part.to_string(), "MidpointNearestEven"); |
| 2281 |
} |
| 2282 |
|
| 2283 |
#[test] |
| 2284 |
fn it_can_round_using_round_half_up() { |
| 2285 |
let tests = &[ |
| 2286 |
("0", 0, "0"), |
| 2287 |
("1.234", 3, "1.234"), |
| 2288 |
("1.12", 5, "1.12"), |
| 2289 |
("6.34567", 2, "6.35"), |
| 2290 |
("6.5", 0, "7"), |
| 2291 |
("12.49", 0, "12"), |
| 2292 |
("0.6666666666666666666666666666", 2, "0.67"), |
| 2293 |
("1.40", 0, "1"), |
| 2294 |
("2.60", 0, "3"), |
| 2295 |
("2.1234567890123456789012345678", 27, "2.123456789012345678901234568"), |
| 2296 |
]; |
| 2297 |
for &(input, dp, expected) in tests { |
| 2298 |
let a = Decimal::from_str(input).unwrap(); |
| 2299 |
#[allow(deprecated)] |
| 2300 |
let b = a.round_dp_with_strategy(dp, RoundingStrategy::RoundHalfUp); |
| 2301 |
assert_eq!(expected, b.to_string(), "RoundHalfUp"); |
| 2302 |
|
| 2303 |
// Recommended replacement |
| 2304 |
let b = a.round_dp_with_strategy(dp, RoundingStrategy::MidpointAwayFromZero); |
| 2305 |
assert_eq!(expected, b.to_string(), "MidpointAwayFromZero"); |
| 2306 |
} |
| 2307 |
} |
| 2308 |
|
| 2309 |
#[test] |
| 2310 |
fn it_can_round_complex_numbers_using_round_half_up() { |
| 2311 |
// Issue #71 |
| 2312 |
let rate = Decimal::new(19, 2); // 0.19 |
| 2313 |
let one = Decimal::new(1, 0); // 1 |
| 2314 |
let part = rate / (rate + one); // 0.19 / (0.19 + 1) = 0.1596638655462184873949579832 |
| 2315 |
#[allow(deprecated)] |
| 2316 |
let part = part.round_dp_with_strategy(2, RoundingStrategy::RoundHalfUp); // 0.16 |
| 2317 |
assert_eq!("0.16", part.to_string(), "RoundHalfUp"); |
| 2318 |
|
| 2319 |
// Recommended replacement |
| 2320 |
let part = part.round_dp_with_strategy(2, RoundingStrategy::MidpointAwayFromZero); // 0.16 |
| 2321 |
assert_eq!("0.16", part.to_string(), "MidpointAwayFromZero"); |
| 2322 |
} |
| 2323 |
|
| 2324 |
#[test] |
| 2325 |
fn it_can_round_using_round_half_down() { |
| 2326 |
let tests = &[ |
| 2327 |
("0", 0, "0"), |
| 2328 |
("1.234", 3, "1.234"), |
| 2329 |
("1.12", 5, "1.12"), |
| 2330 |
("6.34567", 2, "6.35"), |
| 2331 |
("6.51", 0, "7"), |
| 2332 |
("12.5", 0, "12"), |
| 2333 |
("0.6666666666666666666666666666", 2, "0.67"), |
| 2334 |
("1.40", 0, "1"), |
| 2335 |
("2.60", 0, "3"), |
| 2336 |
("2.1234567890123456789012345678", 27, "2.123456789012345678901234568"), |
| 2337 |
]; |
| 2338 |
for &(input, dp, expected) in tests { |
| 2339 |
let a = Decimal::from_str(input).unwrap(); |
| 2340 |
#[allow(deprecated)] |
| 2341 |
let b = a.round_dp_with_strategy(dp, RoundingStrategy::RoundHalfDown); |
| 2342 |
assert_eq!(expected, b.to_string(), "RoundHalfDown"); |
| 2343 |
|
| 2344 |
// Recommended replacement |
| 2345 |
let b = a.round_dp_with_strategy(dp, RoundingStrategy::MidpointTowardZero); |
| 2346 |
assert_eq!(expected, b.to_string(), "MidpointTowardZero"); |
| 2347 |
} |
| 2348 |
} |
| 2349 |
|
| 2350 |
#[test] |
| 2351 |
fn it_can_round_complex_numbers_using_round_half_down() { |
| 2352 |
// Issue #71 |
| 2353 |
let rate = Decimal::new(19, 2); // 0.19 |
| 2354 |
let one = Decimal::new(1, 0); // 1 |
| 2355 |
let part = rate / (rate + one); // 0.19 / (0.19 + 1) = 0.1596638655462184873949579832 |
| 2356 |
|
| 2357 |
#[allow(deprecated)] |
| 2358 |
let part = part.round_dp_with_strategy(2, RoundingStrategy::RoundHalfDown); // 0.16 |
| 2359 |
assert_eq!("0.16", part.to_string(), "RoundHalfDown"); |
| 2360 |
|
| 2361 |
// Recommended replacement |
| 2362 |
let part = part.round_dp_with_strategy(2, RoundingStrategy::MidpointTowardZero); // 0.16 |
| 2363 |
assert_eq!("0.16", part.to_string(), "RoundHalfDown"); |
| 2364 |
} |
| 2365 |
|
| 2366 |
#[test] |
| 2367 |
fn it_can_round_to_2dp_using_explicit_function() { |
| 2368 |
let a = Decimal::from_str("6.12345").unwrap(); |
| 2369 |
let b = a.round_dp(2u32); |
| 2370 |
assert_eq!("6.12", b.to_string()); |
| 2371 |
} |
| 2372 |
|
| 2373 |
#[test] |
| 2374 |
fn it_can_round_up_to_2dp_using_explicit_function() { |
| 2375 |
let a = Decimal::from_str("6.126").unwrap(); |
| 2376 |
let b = a.round_dp(2u32); |
| 2377 |
assert_eq!("6.13", b.to_string()); |
| 2378 |
} |
| 2379 |
|
| 2380 |
#[test] |
| 2381 |
fn it_can_round_down_to_2dp_using_explicit_function() { |
| 2382 |
let a = Decimal::from_str("-6.126").unwrap(); |
| 2383 |
let b = a.round_dp(2u32); |
| 2384 |
assert_eq!("-6.13", b.to_string()); |
| 2385 |
} |
| 2386 |
|
| 2387 |
#[test] |
| 2388 |
fn it_can_round_down_using_bankers_rounding() { |
| 2389 |
let a = Decimal::from_str("6.5").unwrap(); |
| 2390 |
let b = a.round_dp(0u32); |
| 2391 |
assert_eq!("6", b.to_string()); |
| 2392 |
} |
| 2393 |
|
| 2394 |
#[test] |
| 2395 |
fn it_can_round_up_using_bankers_rounding() { |
| 2396 |
let a = Decimal::from_str("7.5").unwrap(); |
| 2397 |
let b = a.round_dp(0u32); |
| 2398 |
assert_eq!("8", b.to_string()); |
| 2399 |
} |
| 2400 |
|
| 2401 |
#[test] |
| 2402 |
fn it_can_round_correctly_using_bankers_rounding_1() { |
| 2403 |
let a = Decimal::from_str("1.2250").unwrap(); |
| 2404 |
let b = a.round_dp(2u32); |
| 2405 |
assert_eq!("1.22", b.to_string()); |
| 2406 |
} |
| 2407 |
|
| 2408 |
#[test] |
| 2409 |
fn it_can_round_correctly_using_bankers_rounding_2() { |
| 2410 |
let a = Decimal::from_str("1.2251").unwrap(); |
| 2411 |
let b = a.round_dp(2u32); |
| 2412 |
assert_eq!("1.23", b.to_string()); |
| 2413 |
} |
| 2414 |
|
| 2415 |
#[test] |
| 2416 |
fn it_can_round_down_when_required() { |
| 2417 |
let a = Decimal::from_str("1.2249").unwrap(); |
| 2418 |
let b = a.round_dp(2u32); |
| 2419 |
assert_eq!("1.22", b.to_string()); |
| 2420 |
} |
| 2421 |
|
| 2422 |
#[test] |
| 2423 |
fn it_can_round_to_2dp_using_explicit_function_without_changing_value() { |
| 2424 |
let a = Decimal::from_str("6.1").unwrap(); |
| 2425 |
let b = a.round_dp(2u32); |
| 2426 |
assert_eq!("6.1", b.to_string()); |
| 2427 |
} |
| 2428 |
|
| 2429 |
#[test] |
| 2430 |
fn it_can_round_zero() { |
| 2431 |
let a = Decimal::from_str("0.0000").unwrap(); |
| 2432 |
let b = a.round_dp(2u32); |
| 2433 |
assert_eq!("0.00", b.to_string()); |
| 2434 |
} |
| 2435 |
|
| 2436 |
#[test] |
| 2437 |
fn it_can_round_large_decimals() { |
| 2438 |
let a = Decimal::from_str("0.6666666666666666666666666666").unwrap(); |
| 2439 |
let b = a.round_dp(2u32); |
| 2440 |
assert_eq!("0.67", b.to_string()); |
| 2441 |
} |
| 2442 |
|
| 2443 |
#[test] |
| 2444 |
fn it_can_round_simple_numbers_down() { |
| 2445 |
let a = Decimal::from_str("1.40").unwrap(); |
| 2446 |
let b = a.round_dp(0u32); |
| 2447 |
assert_eq!("1", b.to_string()); |
| 2448 |
} |
| 2449 |
|
| 2450 |
#[test] |
| 2451 |
fn it_can_round_simple_numbers_up() { |
| 2452 |
let a = Decimal::from_str("2.60").unwrap(); |
| 2453 |
let b = a.round_dp(0u32); |
| 2454 |
assert_eq!("3", b.to_string()); |
| 2455 |
} |
| 2456 |
|
| 2457 |
#[test] |
| 2458 |
fn it_can_round_simple_numbers_with_high_precision() { |
| 2459 |
let a = Decimal::from_str("2.1234567890123456789012345678").unwrap(); |
| 2460 |
let b = a.round_dp(27u32); |
| 2461 |
assert_eq!("2.123456789012345678901234568", b.to_string()); |
| 2462 |
} |
| 2463 |
|
| 2464 |
#[test] |
| 2465 |
fn it_can_round_complex_numbers() { |
| 2466 |
// Issue #71 |
| 2467 |
let rate = Decimal::new(19, 2); // 0.19 |
| 2468 |
let one = Decimal::new(1, 0); // 1 |
| 2469 |
let part = rate / (rate + one); // 0.19 / (0.19 + 1) = 0.1596638655462184873949579832 |
| 2470 |
let part = part.round_dp(2); // 0.16 |
| 2471 |
assert_eq!("0.16", part.to_string()); |
| 2472 |
} |
| 2473 |
|
| 2474 |
#[test] |
| 2475 |
fn it_can_round_down() { |
| 2476 |
let tests = &[ |
| 2477 |
("0.470", 1, "0.4"), |
| 2478 |
("-0.470", 1, "-0.4"), // Toward zero |
| 2479 |
("0.400", 1, "0.4"), |
| 2480 |
("-0.400", 1, "-0.4"), |
| 2481 |
]; |
| 2482 |
for &(input, dp, expected) in tests { |
| 2483 |
let a = Decimal::from_str(input).unwrap(); |
| 2484 |
#[allow(deprecated)] |
| 2485 |
let b = a.round_dp_with_strategy(dp, RoundingStrategy::RoundDown); |
| 2486 |
assert_eq!(expected, b.to_string(), "RoundDown"); |
| 2487 |
|
| 2488 |
// Recommended replacement |
| 2489 |
let b = a.round_dp_with_strategy(dp, RoundingStrategy::ToZero); |
| 2490 |
assert_eq!(expected, b.to_string(), "ToZero"); |
| 2491 |
} |
| 2492 |
} |
| 2493 |
|
| 2494 |
#[test] |
| 2495 |
fn it_can_round_up() { |
| 2496 |
let tests = &[ |
| 2497 |
("2.8", 0, "3"), |
| 2498 |
("2.5", 0, "3"), |
| 2499 |
("2.1", 0, "3"), |
| 2500 |
("-2.1", 0, "-3"), |
| 2501 |
("-2.5", 0, "-3"), |
| 2502 |
("-2.8", 0, "-3"), |
| 2503 |
("0.320", 1, "0.4"), |
| 2504 |
("-0.320", 1, "-0.4"), |
| 2505 |
("0.300", 1, "0.3"), |
| 2506 |
("-0.300", 1, "-0.3"), |
| 2507 |
]; |
| 2508 |
|
| 2509 |
for &(input, dp, expected) in tests { |
| 2510 |
let a = Decimal::from_str(input).unwrap(); |
| 2511 |
#[allow(deprecated)] |
| 2512 |
let b = a.round_dp_with_strategy(dp, RoundingStrategy::RoundUp); |
| 2513 |
assert_eq!(expected, b.to_string(), "RoundUp"); |
| 2514 |
|
| 2515 |
// Recommended replacement |
| 2516 |
let b = a.round_dp_with_strategy(dp, RoundingStrategy::AwayFromZero); |
| 2517 |
assert_eq!(expected, b.to_string(), "AwayFromZero"); |
| 2518 |
} |
| 2519 |
} |
| 2520 |
|
| 2521 |
#[test] |
| 2522 |
fn it_can_round_significant_figures() { |
| 2523 |
let tests = &[ |
| 2524 |
("305.459", 0u32, Some("0")), |
| 2525 |
("305.459", 1, Some("300")), |
| 2526 |
("305.459", 2, Some("310")), |
| 2527 |
("305.459", 3, Some("305")), |
| 2528 |
("305.459", 4, Some("305.5")), |
| 2529 |
("305.459", 5, Some("305.46")), |
| 2530 |
("305.459", 6, Some("305.459")), |
| 2531 |
("305.459", 7, Some("305.4590")), |
| 2532 |
("305.459", 10, Some("305.4590000")), |
| 2533 |
("-305.459", 3, Some("-305")), |
| 2534 |
("-305.459", 2, Some("-310")), // We ignore the negative |
| 2535 |
("-305.459", 5, Some("-305.46")), |
| 2536 |
( |
| 2537 |
"79228162514264337593543950335", |
| 2538 |
29, |
| 2539 |
Some("79228162514264337593543950335"), |
| 2540 |
), |
| 2541 |
("79228162514264337593543950335", 1, None), |
| 2542 |
( |
| 2543 |
"79228162514264337593543950335", |
| 2544 |
2, |
| 2545 |
Some("79000000000000000000000000000"), |
| 2546 |
), |
| 2547 |
( |
| 2548 |
"79228162514264337593543950335", |
| 2549 |
30, |
| 2550 |
Some("79228162514264337593543950335"), |
| 2551 |
), |
| 2552 |
( |
| 2553 |
"79228162514264337593543950335", |
| 2554 |
u32::MAX, |
| 2555 |
Some("79228162514264337593543950335"), |
| 2556 |
), |
| 2557 |
]; |
| 2558 |
for &(input, sf, expected) in tests { |
| 2559 |
let input = Decimal::from_str(input).unwrap(); |
| 2560 |
let result = input.round_sf(sf); |
| 2561 |
if let Some(expected) = expected { |
| 2562 |
assert!(result.is_some(), "Expected result for {}.round_sf({})", input, sf); |
| 2563 |
assert_eq!(expected, result.unwrap().to_string(), "{}.round_sf({})", input, sf); |
| 2564 |
} else { |
| 2565 |
assert!(result.is_none(), "Unexpected result for {}.round_sf({})", input, sf); |
| 2566 |
} |
| 2567 |
} |
| 2568 |
} |
| 2569 |
|
| 2570 |
#[test] |
| 2571 |
fn it_can_round_significant_figures_with_strategy() { |
| 2572 |
let tests = &[ |
| 2573 |
("12301", 3u32, RoundingStrategy::AwayFromZero, Some("12400")), |
| 2574 |
("123.01", 3u32, RoundingStrategy::AwayFromZero, Some("124")), |
| 2575 |
("1.2301", 3u32, RoundingStrategy::AwayFromZero, Some("1.24")), |
| 2576 |
("0.12301", 3u32, RoundingStrategy::AwayFromZero, Some("0.124")), |
| 2577 |
("0.012301", 3u32, RoundingStrategy::AwayFromZero, Some("0.0124")), |
| 2578 |
("0.0000012301", 3u32, RoundingStrategy::AwayFromZero, Some("0.00000124")), |
| 2579 |
("1.012301", 3u32, RoundingStrategy::AwayFromZero, Some("1.02")), |
| 2580 |
]; |
| 2581 |
for &(input, sf, strategy, expected) in tests { |
| 2582 |
let input = Decimal::from_str(input).unwrap(); |
| 2583 |
let result = input.round_sf_with_strategy(sf, strategy); |
| 2584 |
if let Some(expected) = expected { |
| 2585 |
assert!( |
| 2586 |
result.is_some(), |
| 2587 |
"Expected result for {}.round_sf_with_strategy({}, {:?})", |
| 2588 |
input, |
| 2589 |
sf, |
| 2590 |
strategy |
| 2591 |
); |
| 2592 |
assert_eq!( |
| 2593 |
expected, |
| 2594 |
result.unwrap().to_string(), |
| 2595 |
"{}.round_sf_with_strategy({}, {:?})", |
| 2596 |
input, |
| 2597 |
sf, |
| 2598 |
strategy |
| 2599 |
); |
| 2600 |
} else { |
| 2601 |
assert!( |
| 2602 |
result.is_none(), |
| 2603 |
"Unexpected result for {}.round_sf_with_strategy({}, {:?})", |
| 2604 |
input, |
| 2605 |
sf, |
| 2606 |
strategy |
| 2607 |
); |
| 2608 |
} |
| 2609 |
} |
| 2610 |
} |
| 2611 |
|
| 2612 |
#[test] |
| 2613 |
fn it_can_trunc() { |
| 2614 |
let tests = &[("1.00000000000000000000", "1"), ("1.000000000000000000000001", "1")]; |
| 2615 |
|
| 2616 |
for &(value, expected) in tests { |
| 2617 |
let value = Decimal::from_str(value).unwrap(); |
| 2618 |
let expected = Decimal::from_str(expected).unwrap(); |
| 2619 |
let trunc = value.trunc(); |
| 2620 |
assert_eq!(expected.to_string(), trunc.to_string()); |
| 2621 |
} |
| 2622 |
} |
| 2623 |
|
| 2624 |
#[test] |
| 2625 |
fn it_can_fract() { |
| 2626 |
let tests = &[ |
| 2627 |
("1.00000000000000000000", "0.00000000000000000000"), |
| 2628 |
("1.000000000000000000000001", "0.000000000000000000000001"), |
| 2629 |
]; |
| 2630 |
|
| 2631 |
for &(value, expected) in tests { |
| 2632 |
let value = Decimal::from_str(value).unwrap(); |
| 2633 |
let expected = Decimal::from_str(expected).unwrap(); |
| 2634 |
let fract = value.fract(); |
| 2635 |
assert_eq!(expected.to_string(), fract.to_string()); |
| 2636 |
} |
| 2637 |
} |
| 2638 |
|
| 2639 |
#[test] |
| 2640 |
fn it_can_normalize() { |
| 2641 |
let tests = &[ |
| 2642 |
("1.00000000000000000000", "1"), |
| 2643 |
("1.10000000000000000000000", "1.1"), |
| 2644 |
("1.00010000000000000000000", "1.0001"), |
| 2645 |
("1", "1"), |
| 2646 |
("1.1", "1.1"), |
| 2647 |
("1.0001", "1.0001"), |
| 2648 |
("-0", "0"), |
| 2649 |
("-0.0", "0"), |
| 2650 |
("-0.010", "-0.01"), |
| 2651 |
("0.0", "0"), |
| 2652 |
]; |
| 2653 |
|
| 2654 |
for &(value, expected) in tests { |
| 2655 |
let value = Decimal::from_str(value).unwrap(); |
| 2656 |
let expected = Decimal::from_str(expected).unwrap(); |
| 2657 |
let normalized = value.normalize(); |
| 2658 |
assert_eq!(expected.to_string(), normalized.to_string()); |
| 2659 |
} |
| 2660 |
} |
| 2661 |
|
| 2662 |
#[test] |
| 2663 |
fn it_can_return_the_max_value() { |
| 2664 |
assert_eq!("79228162514264337593543950335", Decimal::MAX.to_string()); |
| 2665 |
} |
| 2666 |
|
| 2667 |
#[test] |
| 2668 |
fn it_can_return_the_min_value() { |
| 2669 |
assert_eq!("-79228162514264337593543950335", Decimal::MIN.to_string()); |
| 2670 |
} |
| 2671 |
|
| 2672 |
#[test] |
| 2673 |
fn it_can_go_from_and_into() { |
| 2674 |
let d = Decimal::from_str("5").unwrap(); |
| 2675 |
let di8: Decimal = 5u8.into(); |
| 2676 |
let di32: Decimal = 5i32.into(); |
| 2677 |
let disize: Decimal = 5isize.into(); |
| 2678 |
let di64: Decimal = 5i64.into(); |
| 2679 |
let du8: Decimal = 5u8.into(); |
| 2680 |
let du32: Decimal = 5u32.into(); |
| 2681 |
let dusize: Decimal = 5usize.into(); |
| 2682 |
let du64: Decimal = 5u64.into(); |
| 2683 |
|
| 2684 |
assert_eq!(d, di8); |
| 2685 |
assert_eq!(di8, di32); |
| 2686 |
assert_eq!(di32, disize); |
| 2687 |
assert_eq!(disize, di64); |
| 2688 |
assert_eq!(di64, du8); |
| 2689 |
assert_eq!(du8, du32); |
| 2690 |
assert_eq!(du32, dusize); |
| 2691 |
assert_eq!(dusize, du64); |
| 2692 |
} |
| 2693 |
|
| 2694 |
#[test] |
| 2695 |
fn it_converts_to_f64() { |
| 2696 |
let tests = &[ |
| 2697 |
("5", Some(5f64)), |
| 2698 |
("-5", Some(-5f64)), |
| 2699 |
("0.1", Some(0.1f64)), |
| 2700 |
("0.0", Some(0f64)), |
| 2701 |
("-0.0", Some(0f64)), |
| 2702 |
("0.0000000000025", Some(0.25e-11f64)), |
| 2703 |
("1000000.0000000000025", Some(1e6f64)), |
| 2704 |
("0.000000000000000000000000025", Some(0.25e-25_f64)), |
| 2705 |
( |
| 2706 |
"2.1234567890123456789012345678", |
| 2707 |
Some(2.1234567890123456789012345678_f64), |
| 2708 |
), |
| 2709 |
("21234567890123456789012345678", Some(21234567890123458000000000000_f64)), |
| 2710 |
( |
| 2711 |
"-21234567890123456789012345678", |
| 2712 |
Some(-21234567890123458000000000000_f64), |
| 2713 |
), |
| 2714 |
("1.59283191", Some(1.59283191_f64)), |
| 2715 |
("2.2238", Some(2.2238_f64)), |
| 2716 |
("2.2238123", Some(2.2238123_f64)), |
| 2717 |
("22238", Some(22238_f64)), |
| 2718 |
]; |
| 2719 |
for &(value, expected) in tests { |
| 2720 |
let value = Decimal::from_str(value).unwrap().to_f64(); |
| 2721 |
assert_eq!(expected, value); |
| 2722 |
} |
| 2723 |
} |
| 2724 |
|
| 2725 |
#[test] |
| 2726 |
fn it_converts_to_f64_try() { |
| 2727 |
let tests = &[ |
| 2728 |
("5", Some(5f64)), |
| 2729 |
("-5", Some(-5f64)), |
| 2730 |
("0.1", Some(0.1f64)), |
| 2731 |
("0.0", Some(0f64)), |
| 2732 |
("-0.0", Some(0f64)), |
| 2733 |
("0.0000000000025", Some(0.25e-11f64)), |
| 2734 |
("1000000.0000000000025", Some(1e6f64)), |
| 2735 |
("0.000000000000000000000000025", Some(0.25e-25_f64)), |
| 2736 |
( |
| 2737 |
"2.1234567890123456789012345678", |
| 2738 |
Some(2.1234567890123456789012345678_f64), |
| 2739 |
), |
| 2740 |
("21234567890123456789012345678", Some(21234567890123458000000000000_f64)), |
| 2741 |
( |
| 2742 |
"-21234567890123456789012345678", |
| 2743 |
Some(-21234567890123458000000000000_f64), |
| 2744 |
), |
| 2745 |
("1.59283191", Some(1.59283191_f64)), |
| 2746 |
]; |
| 2747 |
for &(value, expected) in tests { |
| 2748 |
let value = Decimal::from_str(value).unwrap().try_into().ok(); |
| 2749 |
assert_eq!(expected, value); |
| 2750 |
} |
| 2751 |
} |
| 2752 |
|
| 2753 |
#[test] |
| 2754 |
fn it_converts_to_i64() { |
| 2755 |
let tests = [ |
| 2756 |
("5", Some(5_i64)), |
| 2757 |
("-5", Some(-5_i64)), |
| 2758 |
("5.12345", Some(5_i64)), |
| 2759 |
("-5.12345", Some(-5_i64)), |
| 2760 |
("-9223372036854775808", Some(-9223372036854775808_i64)), |
| 2761 |
("-9223372036854775808", Some(i64::MIN)), |
| 2762 |
("9223372036854775807", Some(9223372036854775807_i64)), |
| 2763 |
("9223372036854775807", Some(i64::MAX)), |
| 2764 |
("-9223372036854775809", None), // i64::MIN - 1 |
| 2765 |
("9223372036854775808", None), // i64::MAX + 1 |
| 2766 |
// Clear overflows in hi bit |
| 2767 |
("-92233720368547758089", None), |
| 2768 |
("92233720368547758088", None), |
| 2769 |
]; |
| 2770 |
for (input, expected) in tests { |
| 2771 |
let input = Decimal::from_str(input).unwrap(); |
| 2772 |
let actual = input.to_i64(); |
| 2773 |
assert_eq!(expected, actual, "Input: {}", input); |
| 2774 |
} |
| 2775 |
} |
| 2776 |
|
| 2777 |
#[test] |
| 2778 |
fn it_converts_to_u64() { |
| 2779 |
assert_eq!(5u64, Decimal::from_str("5").unwrap().to_u64().unwrap()); |
| 2780 |
assert_eq!(None, Decimal::from_str("-5").unwrap().to_u64()); |
| 2781 |
assert_eq!(5u64, Decimal::from_str("5.12345").unwrap().to_u64().unwrap()); |
| 2782 |
assert_eq!( |
| 2783 |
0xFFFF_FFFF_FFFF_FFFF, |
| 2784 |
Decimal::from_str("18446744073709551615").unwrap().to_u64().unwrap() |
| 2785 |
); |
| 2786 |
assert_eq!(None, Decimal::from_str("18446744073709551616").unwrap().to_u64()); |
| 2787 |
} |
| 2788 |
|
| 2789 |
#[test] |
| 2790 |
fn it_converts_to_i128() { |
| 2791 |
let tests = &[ |
| 2792 |
("5", Some(5i128)), |
| 2793 |
("-5", Some(-5i128)), |
| 2794 |
("5.12345", Some(5i128)), |
| 2795 |
("-5.12345", Some(-5i128)), |
| 2796 |
("9223372036854775807", Some(0x7FFF_FFFF_FFFF_FFFF)), |
| 2797 |
("92233720368547758089", Some(92233720368547758089i128)), |
| 2798 |
]; |
| 2799 |
for (dec, expected) in tests { |
| 2800 |
assert_eq!(Decimal::from_str(dec).unwrap().to_i128(), *expected); |
| 2801 |
} |
| 2802 |
|
| 2803 |
assert_eq!( |
| 2804 |
79_228_162_514_264_337_593_543_950_335_i128, |
| 2805 |
Decimal::MAX.to_i128().unwrap() |
| 2806 |
); |
| 2807 |
} |
| 2808 |
|
| 2809 |
#[test] |
| 2810 |
fn it_converts_to_u128() { |
| 2811 |
let tests = &[ |
| 2812 |
("5", Some(5u128)), |
| 2813 |
("-5", None), |
| 2814 |
("5.12345", Some(5u128)), |
| 2815 |
("-5.12345", None), |
| 2816 |
("18446744073709551615", Some(0xFFFF_FFFF_FFFF_FFFF)), |
| 2817 |
("18446744073709551616", Some(18446744073709551616u128)), |
| 2818 |
]; |
| 2819 |
for (dec, expected) in tests { |
| 2820 |
assert_eq!(Decimal::from_str(dec).unwrap().to_u128(), *expected); |
| 2821 |
} |
| 2822 |
assert_eq!( |
| 2823 |
79_228_162_514_264_337_593_543_950_335_u128, |
| 2824 |
Decimal::MAX.to_u128().unwrap() |
| 2825 |
); |
| 2826 |
} |
| 2827 |
|
| 2828 |
#[test] |
| 2829 |
fn it_converts_from_i128() { |
| 2830 |
let tests: &[(i128, Option<&str>)] = &[ |
| 2831 |
(5, Some("5")), |
| 2832 |
(-5, Some("-5")), |
| 2833 |
(0x7FFF_FFFF_FFFF_FFFF, Some("9223372036854775807")), |
| 2834 |
(92233720368547758089, Some("92233720368547758089")), |
| 2835 |
(0xFFFF_FFFF_FFFF_FFFF_FFFF_FFFF, Some("79228162514264337593543950335")), |
| 2836 |
(0x7FFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF, None), |
| 2837 |
]; |
| 2838 |
for (value, expected) in tests { |
| 2839 |
if let Some(expected_value) = expected { |
| 2840 |
let decimal = Decimal::from_str(expected_value).unwrap(); |
| 2841 |
assert_eq!(num_traits::FromPrimitive::from_i128(*value), Some(decimal)); |
| 2842 |
} |
| 2843 |
} |
| 2844 |
} |
| 2845 |
|
| 2846 |
#[test] |
| 2847 |
fn it_converts_from_u128() { |
| 2848 |
let tests: &[(u128, Option<&str>)] = &[ |
| 2849 |
(5, Some("5")), |
| 2850 |
(0xFFFF_FFFF_FFFF_FFFF, Some("18446744073709551615")), |
| 2851 |
(0xFFFF_FFFF_FFFF_FFFF_FFFF_FFFF, Some("79228162514264337593543950335")), |
| 2852 |
(0x7FFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF, None), |
| 2853 |
]; |
| 2854 |
for (value, expected) in tests { |
| 2855 |
if let Some(expected_value) = expected { |
| 2856 |
let decimal = Decimal::from_str(expected_value).unwrap(); |
| 2857 |
assert_eq!(num_traits::FromPrimitive::from_u128(*value), Some(decimal)); |
| 2858 |
} |
| 2859 |
} |
| 2860 |
} |
| 2861 |
|
| 2862 |
#[test] |
| 2863 |
fn it_converts_from_str() { |
| 2864 |
assert_eq!(Decimal::try_from("1").unwrap(), Decimal::ONE); |
| 2865 |
assert_eq!(Decimal::try_from("10").unwrap(), Decimal::TEN); |
| 2866 |
} |
| 2867 |
|
| 2868 |
#[test] |
| 2869 |
fn it_converts_from_f32() { |
| 2870 |
use num_traits::FromPrimitive; |
| 2871 |
|
| 2872 |
let tests = [ |
| 2873 |
(0.1_f32, "0.1"), |
| 2874 |
(1_f32, "1"), |
| 2875 |
(0_f32, "0"), |
| 2876 |
(0.12345_f32, "0.12345"), |
| 2877 |
(0.1234567800123456789012345678_f32, "0.12345678"), |
| 2878 |
(0.12345678901234567890123456789_f32, "0.12345679"), |
| 2879 |
(0.00000000000000000000000000001_f32, "0"), |
| 2880 |
(5.1_f32, "5.1"), |
| 2881 |
]; |
| 2882 |
|
| 2883 |
for &(input, expected) in &tests { |
| 2884 |
assert_eq!( |
| 2885 |
expected, |
| 2886 |
Decimal::from_f32(input).unwrap().to_string(), |
| 2887 |
"from_f32({})", |
| 2888 |
input |
| 2889 |
); |
| 2890 |
assert_eq!( |
| 2891 |
expected, |
| 2892 |
Decimal::try_from(input).unwrap().to_string(), |
| 2893 |
"try_from({})", |
| 2894 |
input |
| 2895 |
); |
| 2896 |
} |
| 2897 |
} |
| 2898 |
|
| 2899 |
#[test] |
| 2900 |
fn it_converts_from_f32_limits() { |
| 2901 |
use num_traits::FromPrimitive; |
| 2902 |
|
| 2903 |
assert!(Decimal::from_f32(f32::NAN).is_none(), "from_f32(f32::NAN)"); |
| 2904 |
assert!(Decimal::from_f32(f32::INFINITY).is_none(), "from_f32(f32::INFINITY)"); |
| 2905 |
assert!(Decimal::try_from(f32::NAN).is_err(), "try_from(f32::NAN)"); |
| 2906 |
assert!(Decimal::try_from(f32::INFINITY).is_err(), "try_from(f32::INFINITY)"); |
| 2907 |
|
| 2908 |
// These overflow |
| 2909 |
assert!(Decimal::from_f32(f32::MAX).is_none(), "from_f32(f32::MAX)"); |
| 2910 |
assert!(Decimal::from_f32(f32::MIN).is_none(), "from_f32(f32::MIN)"); |
| 2911 |
assert!(Decimal::try_from(f32::MAX).is_err(), "try_from(f32::MAX)"); |
| 2912 |
assert!(Decimal::try_from(f32::MIN).is_err(), "try_from(f32::MIN)"); |
| 2913 |
} |
| 2914 |
|
| 2915 |
#[test] |
| 2916 |
fn it_converts_from_f32_retaining_bits() { |
| 2917 |
let tests = [ |
| 2918 |
(0.1_f32, "0.100000001490116119384765625"), |
| 2919 |
(2_f32, "2"), |
| 2920 |
(4.000_f32, "4"), |
| 2921 |
(5.1_f32, "5.099999904632568359375"), |
| 2922 |
]; |
| 2923 |
|
| 2924 |
for &(input, expected) in &tests { |
| 2925 |
assert_eq!( |
| 2926 |
expected, |
| 2927 |
Decimal::from_f32_retain(input).unwrap().to_string(), |
| 2928 |
"from_f32_retain({})", |
| 2929 |
input |
| 2930 |
); |
| 2931 |
} |
| 2932 |
} |
| 2933 |
|
| 2934 |
#[test] |
| 2935 |
fn it_converts_from_f64() { |
| 2936 |
use num_traits::FromPrimitive; |
| 2937 |
|
| 2938 |
let tests = [ |
| 2939 |
(0.1_f64, "0.1"), |
| 2940 |
(1_f64, "1"), |
| 2941 |
(0_f64, "0"), |
| 2942 |
(0.12345_f64, "0.12345"), |
| 2943 |
(0.1234567890123456089012345678_f64, "0.1234567890123456"), |
| 2944 |
(0.12345678901234567890123456789_f64, "0.1234567890123457"), |
| 2945 |
(0.00000000000000000000000000001_f64, "0"), |
| 2946 |
(0.6927_f64, "0.6927"), |
| 2947 |
(0.00006927_f64, "0.00006927"), |
| 2948 |
(0.000000006927_f64, "0.000000006927"), |
| 2949 |
(5.1_f64, "5.1"), |
| 2950 |
]; |
| 2951 |
|
| 2952 |
for &(input, expected) in &tests { |
| 2953 |
assert_eq!( |
| 2954 |
expected, |
| 2955 |
Decimal::from_f64(input).unwrap().to_string(), |
| 2956 |
"from_f64({})", |
| 2957 |
input |
| 2958 |
); |
| 2959 |
assert_eq!( |
| 2960 |
expected, |
| 2961 |
Decimal::try_from(input).unwrap().to_string(), |
| 2962 |
"try_from({})", |
| 2963 |
input |
| 2964 |
); |
| 2965 |
} |
| 2966 |
} |
| 2967 |
|
| 2968 |
#[test] |
| 2969 |
fn it_converts_from_f64_limits() { |
| 2970 |
use num_traits::FromPrimitive; |
| 2971 |
|
| 2972 |
assert!(Decimal::from_f64(f64::NAN).is_none(), "from_f64(f64::NAN)"); |
| 2973 |
assert!(Decimal::from_f64(f64::INFINITY).is_none(), "from_f64(f64::INFINITY)"); |
| 2974 |
assert!(Decimal::try_from(f64::NAN).is_err(), "try_from(f64::NAN)"); |
| 2975 |
assert!(Decimal::try_from(f64::INFINITY).is_err(), "try_from(f64::INFINITY)"); |
| 2976 |
|
| 2977 |
// These overflow |
| 2978 |
assert!(Decimal::from_f64(f64::MAX).is_none(), "from_f64(f64::MAX)"); |
| 2979 |
assert!(Decimal::from_f64(f64::MIN).is_none(), "from_f64(f64::MIN)"); |
| 2980 |
assert!(Decimal::try_from(f64::MAX).is_err(), "try_from(f64::MIN)"); |
| 2981 |
assert!(Decimal::try_from(f64::MIN).is_err(), "try_from(f64::MAX)"); |
| 2982 |
} |
| 2983 |
|
| 2984 |
#[test] |
| 2985 |
fn it_converts_from_f64_retaining_bits() { |
| 2986 |
let tests = [ |
| 2987 |
(0.1_f64, "0.1000000000000000055511151231"), |
| 2988 |
(2_f64, "2"), |
| 2989 |
(4.000_f64, "4"), |
| 2990 |
(5.1_f64, "5.0999999999999996447286321175"), |
| 2991 |
]; |
| 2992 |
|
| 2993 |
for &(input, expected) in &tests { |
| 2994 |
assert_eq!( |
| 2995 |
expected, |
| 2996 |
Decimal::from_f64_retain(input).unwrap().to_string(), |
| 2997 |
"from_f64_retain({})", |
| 2998 |
input |
| 2999 |
); |
| 3000 |
} |
| 3001 |
} |
| 3002 |
|
| 3003 |
#[test] |
| 3004 |
fn it_converts_to_integers() { |
| 3005 |
assert_eq!(i64::try_from(Decimal::ONE), Ok(1)); |
| 3006 |
assert_eq!(i64::try_from(Decimal::MAX), Err(Error::ConversionTo("i64".to_string()))); |
| 3007 |
assert_eq!(u128::try_from(Decimal::ONE_HUNDRED), Ok(100)); |
| 3008 |
} |
| 3009 |
|
| 3010 |
#[test] |
| 3011 |
fn it_handles_simple_underflow() { |
| 3012 |
// Issue #71 |
| 3013 |
let rate = Decimal::new(19, 2); // 0.19 |
| 3014 |
let one = Decimal::new(1, 0); // 1 |
| 3015 |
let part = rate / (rate + one); // 0.19 / (0.19 + 1) = 0.1596638655462184873949579832 |
| 3016 |
let result = one * part; |
| 3017 |
assert_eq!("0.1596638655462184873949579832", result.to_string()); |
| 3018 |
|
| 3019 |
// 169 * 0.1596638655462184873949579832 = 26.983193277310924 |
| 3020 |
let result = part * Decimal::new(169, 0); |
| 3021 |
assert_eq!("26.983193277310924369747899161", result.to_string()); |
| 3022 |
let result = Decimal::new(169, 0) * part; |
| 3023 |
assert_eq!("26.983193277310924369747899161", result.to_string()); |
| 3024 |
} |
| 3025 |
|
| 3026 |
#[test] |
| 3027 |
fn it_can_parse_highly_significant_numbers() { |
| 3028 |
let tests = &[ |
| 3029 |
("11.111111111111111111111111111", "11.111111111111111111111111111"), |
| 3030 |
("11.11111111111111111111111111111", "11.111111111111111111111111111"), |
| 3031 |
("11.1111111111111111111111111115", "11.111111111111111111111111112"), |
| 3032 |
("115.111111111111111111111111111", "115.11111111111111111111111111"), |
| 3033 |
("1115.11111111111111111111111111", "1115.1111111111111111111111111"), |
| 3034 |
("11.1111111111111111111111111195", "11.111111111111111111111111120"), |
| 3035 |
("99.9999999999999999999999999995", "100.00000000000000000000000000"), |
| 3036 |
("-11.1111111111111111111111111195", "-11.111111111111111111111111120"), |
| 3037 |
("-99.9999999999999999999999999995", "-100.00000000000000000000000000"), |
| 3038 |
("3.1415926535897932384626433832", "3.1415926535897932384626433832"), |
| 3039 |
( |
| 3040 |
"8808257419827262908.5944405087133154018", |
| 3041 |
"8808257419827262908.594440509", |
| 3042 |
), |
| 3043 |
( |
| 3044 |
"8097370036018690744.2590371109596744091", |
| 3045 |
"8097370036018690744.259037111", |
| 3046 |
), |
| 3047 |
( |
| 3048 |
"8097370036018690744.2590371149596744091", |
| 3049 |
"8097370036018690744.259037115", |
| 3050 |
), |
| 3051 |
( |
| 3052 |
"8097370036018690744.2590371159596744091", |
| 3053 |
"8097370036018690744.259037116", |
| 3054 |
), |
| 3055 |
("1.234567890123456789012345678949999", "1.2345678901234567890123456789"), |
| 3056 |
(".00000000000000000000000000001", "0.0000000000000000000000000000"), |
| 3057 |
(".10000000000000000000000000000", "0.1000000000000000000000000000"), |
| 3058 |
]; |
| 3059 |
for &(value, expected) in tests { |
| 3060 |
assert_eq!(expected, Decimal::from_str(value).unwrap().to_string()); |
| 3061 |
} |
| 3062 |
} |
| 3063 |
|
| 3064 |
#[test] |
| 3065 |
fn it_can_parse_exact_highly_significant_numbers() { |
| 3066 |
use rust_decimal::Error; |
| 3067 |
|
| 3068 |
let tests = &[ |
| 3069 |
( |
| 3070 |
"11.111111111111111111111111111", |
| 3071 |
Ok("11.111111111111111111111111111".to_string()), |
| 3072 |
), |
| 3073 |
("11.11111111111111111111111111111", Err(Error::Underflow)), |
| 3074 |
("11.1111111111111111111111111115", Err(Error::Underflow)), |
| 3075 |
("115.111111111111111111111111111", Err(Error::Underflow)), |
| 3076 |
("1115.11111111111111111111111111", Err(Error::Underflow)), |
| 3077 |
("11.1111111111111111111111111195", Err(Error::Underflow)), |
| 3078 |
("99.9999999999999999999999999995", Err(Error::Underflow)), |
| 3079 |
("-11.1111111111111111111111111195", Err(Error::Underflow)), |
| 3080 |
("-99.9999999999999999999999999995", Err(Error::Underflow)), |
| 3081 |
( |
| 3082 |
"3.1415926535897932384626433832", |
| 3083 |
Ok("3.1415926535897932384626433832".to_string()), |
| 3084 |
), |
| 3085 |
("8808257419827262908.5944405087133154018", Err(Error::Underflow)), |
| 3086 |
("8097370036018690744.2590371109596744091", Err(Error::Underflow)), |
| 3087 |
("8097370036018690744.2590371149596744091", Err(Error::Underflow)), |
| 3088 |
("8097370036018690744.2590371159596744091", Err(Error::Underflow)), |
| 3089 |
("1.234567890123456789012345678949999", Err(Error::Underflow)), |
| 3090 |
(".00000000000000000000000000001", Err(Error::Underflow)), |
| 3091 |
(".10000000000000000000000000000", Err(Error::Underflow)), |
| 3092 |
]; |
| 3093 |
for &(value, ref expected) in tests.into_iter() { |
| 3094 |
let actual = Decimal::from_str_exact(value).map(|d| d.to_string()); |
| 3095 |
assert_eq!(*expected, actual); |
| 3096 |
} |
| 3097 |
} |
| 3098 |
|
| 3099 |
#[test] |
| 3100 |
fn it_can_parse_alternative_formats() { |
| 3101 |
let tests = &[ |
| 3102 |
("1_000", "1000"), |
| 3103 |
("1_000_000", "1000000"), |
| 3104 |
("10_000_000", "10000000"), |
| 3105 |
("100_000", "100000"), |
| 3106 |
// At the moment, we'll accept this |
| 3107 |
("1_____________0", "10"), |
| 3108 |
]; |
| 3109 |
for &(value, expected) in tests { |
| 3110 |
assert_eq!(expected, Decimal::from_str(value).unwrap().to_string()); |
| 3111 |
} |
| 3112 |
} |
| 3113 |
|
| 3114 |
#[test] |
| 3115 |
fn it_can_parse_fractional_numbers_with_underscore_separators() { |
| 3116 |
let a = Decimal::from_str("0.1_23_456").unwrap(); |
| 3117 |
assert_eq!(a.is_sign_negative(), false); |
| 3118 |
assert_eq!(a.scale(), 6); |
| 3119 |
assert_eq!("0.123456", a.to_string()); |
| 3120 |
} |
| 3121 |
|
| 3122 |
#[test] |
| 3123 |
fn it_can_parse_numbers_with_underscore_separators_before_decimal_point() { |
| 3124 |
let a = Decimal::from_str("1_234.56").unwrap(); |
| 3125 |
assert_eq!(a.is_sign_negative(), false); |
| 3126 |
assert_eq!(a.scale(), 2); |
| 3127 |
assert_eq!("1234.56", a.to_string()); |
| 3128 |
} |
| 3129 |
|
| 3130 |
#[test] |
| 3131 |
fn it_can_parse_numbers_and_round_correctly_with_underscore_separators_before_decimal_point() { |
| 3132 |
let tests = &[ |
| 3133 |
( |
| 3134 |
"8_097_370_036_018_690_744.2590371159596744091", |
| 3135 |
"8097370036018690744.259037116", |
| 3136 |
), |
| 3137 |
( |
| 3138 |
"8097370036018690744.259_037_115_959_674_409_1", |
| 3139 |
"8097370036018690744.259037116", |
| 3140 |
), |
| 3141 |
( |
| 3142 |
"8_097_370_036_018_690_744.259_037_115_959_674_409_1", |
| 3143 |
"8097370036018690744.259037116", |
| 3144 |
), |
| 3145 |
]; |
| 3146 |
for &(value, expected) in tests { |
| 3147 |
assert_eq!(expected, Decimal::from_str(value).unwrap().to_string()); |
| 3148 |
} |
| 3149 |
} |
| 3150 |
|
| 3151 |
#[test] |
| 3152 |
fn it_can_reject_invalid_formats() { |
| 3153 |
let tests = &["_1", "1.0.0", "10_00.0_00.0"]; |
| 3154 |
for &value in tests { |
| 3155 |
assert!( |
| 3156 |
Decimal::from_str(value).is_err(), |
| 3157 |
"This succeeded unexpectedly: {}", |
| 3158 |
value |
| 3159 |
); |
| 3160 |
} |
| 3161 |
} |
| 3162 |
|
| 3163 |
#[test] |
| 3164 |
fn it_can_reject_large_numbers_with_panic() { |
| 3165 |
let tests = &[ |
| 3166 |
// The maximum number supported is 79,228,162,514,264,337,593,543,950,335 |
| 3167 |
"79228162514264337593543950336", |
| 3168 |
"79228162514264337593543950337", |
| 3169 |
"79228162514264337593543950338", |
| 3170 |
"79228162514264337593543950339", |
| 3171 |
"79228162514264337593543950340", |
| 3172 |
]; |
| 3173 |
for &value in tests { |
| 3174 |
if let Ok(out) = Decimal::from_str(value) { |
| 3175 |
panic!("Unexpectedly parsed {} into {}", value, out) |
| 3176 |
} |
| 3177 |
} |
| 3178 |
} |
| 3179 |
|
| 3180 |
#[test] |
| 3181 |
fn it_can_parse_individual_parts() { |
| 3182 |
let pi = Decimal::from_parts(1102470952, 185874565, 1703060790, false, 28); |
| 3183 |
assert_eq!(pi.to_string(), "3.1415926535897932384626433832"); |
| 3184 |
} |
| 3185 |
|
| 3186 |
#[test] |
| 3187 |
fn it_can_parse_scientific_notation() { |
| 3188 |
let tests = &[ |
| 3189 |
("9.7e-7", "0.00000097"), |
| 3190 |
("9e-7", "0.0000009"), |
| 3191 |
("1.2e10", "12000000000"), |
| 3192 |
("1.2e+10", "12000000000"), |
| 3193 |
("12e10", "120000000000"), |
| 3194 |
("9.7E-7", "0.00000097"), |
| 3195 |
("1.2345E-24", "0.0000000000000000000000012345"), |
| 3196 |
("12345E-28", "0.0000000000000000000000012345"), |
| 3197 |
("1.2345E0", "1.2345"), |
| 3198 |
("1E28", "10000000000000000000000000000"), |
| 3199 |
]; |
| 3200 |
|
| 3201 |
for &(value, expected) in tests { |
| 3202 |
assert_eq!(expected, Decimal::from_scientific(value).unwrap().to_string()); |
| 3203 |
} |
| 3204 |
} |
| 3205 |
|
| 3206 |
#[test] |
| 3207 |
fn it_errors_parsing_large_scientific_notation() { |
| 3208 |
let result = Decimal::from_scientific("1.2345E-28"); |
| 3209 |
assert!(result.is_err()); |
| 3210 |
assert_eq!( |
| 3211 |
result.err(), |
| 3212 |
Some(Error::ScaleExceedsMaximumPrecision(32)) // 4 + 28 |
| 3213 |
); |
| 3214 |
|
| 3215 |
let result = Decimal::from_scientific("12345E29"); |
| 3216 |
assert!(result.is_err()); |
| 3217 |
assert_eq!(result.err(), Some(Error::ScaleExceedsMaximumPrecision(29))); |
| 3218 |
|
| 3219 |
let result = Decimal::from_scientific("12345E28"); |
| 3220 |
assert!(result.is_err()); |
| 3221 |
assert_eq!(result.err(), Some(Error::ExceedsMaximumPossibleValue)); |
| 3222 |
} |
| 3223 |
|
| 3224 |
#[test] |
| 3225 |
fn it_can_parse_different_radix() { |
| 3226 |
let tests = &[ |
| 3227 |
// Input, Radix, Success, to_string() |
| 3228 |
("123", 10, true, "123"), |
| 3229 |
("123", 8, true, "83"), |
| 3230 |
("123", 16, true, "291"), |
| 3231 |
("abc", 10, false, ""), |
| 3232 |
("abc", 16, true, "2748"), |
| 3233 |
("78", 10, true, "78"), |
| 3234 |
("78", 8, false, ""), |
| 3235 |
("101", 2, true, "5"), |
| 3236 |
// Parse base 2 |
| 3237 |
("1111_1111_1111_1111_1111_1111_1111_1111", 2, true, "4294967295"), |
| 3238 |
// Max supported value |
| 3239 |
( |
| 3240 |
"1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_\ |
| 3241 |
1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111", |
| 3242 |
2, |
| 3243 |
true, |
| 3244 |
&Decimal::MAX.to_string(), |
| 3245 |
), |
| 3246 |
// We limit to 28 dp |
| 3247 |
( |
| 3248 |
"843.6500000000000000000000000000", |
| 3249 |
10, |
| 3250 |
true, |
| 3251 |
"843.6500000000000000000000000", |
| 3252 |
), |
| 3253 |
]; |
| 3254 |
|
| 3255 |
for &(input, radix, success, expected) in tests { |
| 3256 |
let result = Decimal::from_str_radix(input, radix); |
| 3257 |
assert_eq!( |
| 3258 |
success, |
| 3259 |
result.is_ok(), |
| 3260 |
"Failed to parse: {} radix {}: {:?}", |
| 3261 |
input, |
| 3262 |
radix, |
| 3263 |
result.err() |
| 3264 |
); |
| 3265 |
if result.is_ok() { |
| 3266 |
assert_eq!( |
| 3267 |
expected, |
| 3268 |
result.unwrap().to_string(), |
| 3269 |
"Original input: {} radix {}", |
| 3270 |
input, |
| 3271 |
radix |
| 3272 |
); |
| 3273 |
} |
| 3274 |
} |
| 3275 |
} |
| 3276 |
|
| 3277 |
#[test] |
| 3278 |
fn it_can_calculate_signum() { |
| 3279 |
let tests = &[("123", 1), ("-123", -1), ("0", 0)]; |
| 3280 |
|
| 3281 |
for &(input, expected) in tests { |
| 3282 |
let input = Decimal::from_str(input).unwrap(); |
| 3283 |
assert_eq!(expected, input.signum().to_i32().unwrap(), "Input: {}", input); |
| 3284 |
} |
| 3285 |
} |
| 3286 |
|
| 3287 |
#[test] |
| 3288 |
fn it_can_calculate_abs_sub() { |
| 3289 |
let tests = &[ |
| 3290 |
("123", "124", 0), |
| 3291 |
("123", "123", 0), |
| 3292 |
("123", "122", 123), |
| 3293 |
("-123", "-124", 123), |
| 3294 |
("-123", "-123", 0), |
| 3295 |
("-123", "-122", 0), |
| 3296 |
]; |
| 3297 |
|
| 3298 |
for &(input1, input2, expected) in tests { |
| 3299 |
let input1 = Decimal::from_str(input1).unwrap(); |
| 3300 |
let input2 = Decimal::from_str(input2).unwrap(); |
| 3301 |
assert_eq!( |
| 3302 |
expected, |
| 3303 |
input1.abs_sub(&input2).to_i32().unwrap(), |
| 3304 |
"Input: {} {}", |
| 3305 |
input1, |
| 3306 |
input2 |
| 3307 |
); |
| 3308 |
} |
| 3309 |
} |
| 3310 |
|
| 3311 |
#[test] |
| 3312 |
#[should_panic(expected = "Scale exceeds the maximum precision allowed: 29 > 28")] |
| 3313 |
fn it_panics_when_scale_too_large() { |
| 3314 |
let _ = Decimal::new(1, 29); |
| 3315 |
} |
| 3316 |
|
| 3317 |
#[test] |
| 3318 |
fn test_zero_eq_negative_zero() { |
| 3319 |
let zero: Decimal = 0.into(); |
| 3320 |
|
| 3321 |
assert_eq!(zero, zero); |
| 3322 |
assert_eq!(-zero, zero); |
| 3323 |
assert_eq!(zero, -zero); |
| 3324 |
} |
| 3325 |
|
| 3326 |
#[test] |
| 3327 |
fn declarative_dec_product() { |
| 3328 |
let vs = (1..5).map(|i| i.into()).collect::<Vec<Decimal>>(); |
| 3329 |
let product: Decimal = vs.into_iter().product(); |
| 3330 |
assert_eq!(product, Decimal::from(24)) |
| 3331 |
} |
| 3332 |
|
| 3333 |
#[test] |
| 3334 |
fn declarative_ref_dec_product() { |
| 3335 |
let vs = (1..5).map(|i| i.into()).collect::<Vec<Decimal>>(); |
| 3336 |
let product: Decimal = vs.iter().product(); |
| 3337 |
assert_eq!(product, Decimal::from(24)) |
| 3338 |
} |
| 3339 |
|
| 3340 |
#[test] |
| 3341 |
fn declarative_dec_sum() { |
| 3342 |
let vs = (0..10).map(|i| i.into()).collect::<Vec<Decimal>>(); |
| 3343 |
let sum: Decimal = vs.into_iter().sum(); |
| 3344 |
assert_eq!(sum, Decimal::from(45)) |
| 3345 |
} |
| 3346 |
|
| 3347 |
#[test] |
| 3348 |
fn declarative_ref_dec_sum() { |
| 3349 |
let vs = (0..10).map(|i| i.into()).collect::<Vec<Decimal>>(); |
| 3350 |
let sum: Decimal = vs.iter().sum(); |
| 3351 |
assert_eq!(sum, Decimal::from(45)) |
| 3352 |
} |
| 3353 |
|
| 3354 |
#[cfg(feature = "postgres")] |
| 3355 |
#[test] |
| 3356 |
fn to_from_sql() { |
| 3357 |
use bytes::BytesMut; |
| 3358 |
use postgres::types::{FromSql, Kind, ToSql, Type}; |
| 3359 |
|
| 3360 |
let tests = &[ |
| 3361 |
"3950.123456", |
| 3362 |
"3950", |
| 3363 |
"0.1", |
| 3364 |
"0.01", |
| 3365 |
"0.001", |
| 3366 |
"0.0001", |
| 3367 |
"0.00001", |
| 3368 |
"0.000001", |
| 3369 |
"1", |
| 3370 |
"-100", |
| 3371 |
"-123.456", |
| 3372 |
"119996.25", |
| 3373 |
"1000000", |
| 3374 |
"9999999.99999", |
| 3375 |
"12340.56789", |
| 3376 |
"79228162514264337593543950335", // 0xFFFF_FFFF_FFFF_FFFF_FFFF_FFFF (96 bit) |
| 3377 |
"4951760157141521099596496895", // 0x0FFF_FFFF_FFFF_FFFF_FFFF_FFFF (95 bit) |
| 3378 |
"4951760157141521099596496896", // 0x1000_0000_0000_0000_0000_0000 |
| 3379 |
"18446744073709551615", |
| 3380 |
"-18446744073709551615", |
| 3381 |
]; |
| 3382 |
|
| 3383 |
let t = Type::new("".into(), 0, Kind::Simple, "".into()); |
| 3384 |
|
| 3385 |
for test in tests { |
| 3386 |
let input = Decimal::from_str(test).unwrap(); |
| 3387 |
let mut bytes = BytesMut::new(); |
| 3388 |
input.to_sql(&t, &mut bytes).unwrap(); |
| 3389 |
let output = Decimal::from_sql(&t, &bytes).unwrap(); |
| 3390 |
|
| 3391 |
assert_eq!(input, output); |
| 3392 |
} |
| 3393 |
} |
| 3394 |
|
| 3395 |
fn hash_it(d: Decimal) -> u64 { |
| 3396 |
use core::hash::{Hash, Hasher}; |
| 3397 |
use std::collections::hash_map::DefaultHasher; |
| 3398 |
|
| 3399 |
let mut h = DefaultHasher::new(); |
| 3400 |
d.hash(&mut h); |
| 3401 |
h.finish() |
| 3402 |
} |
| 3403 |
|
| 3404 |
#[test] |
| 3405 |
fn it_computes_equal_hashes_for_equal_values() { |
| 3406 |
// From the Rust Hash docs: |
| 3407 |
// |
| 3408 |
// "When implementing both Hash and Eq, it is important that the following property holds: |
| 3409 |
// |
| 3410 |
// k1 == k2 -> hash(k1) == hash(k2)" |
| 3411 |
|
| 3412 |
let k1 = Decimal::from_str("1").unwrap(); |
| 3413 |
let k2 = Decimal::from_str("1.0").unwrap(); |
| 3414 |
let k3 = Decimal::from_str("1.00").unwrap(); |
| 3415 |
let k4 = Decimal::from_str("1.01").unwrap(); |
| 3416 |
|
| 3417 |
assert_eq!(k1, k2); |
| 3418 |
assert_eq!(k1, k3); |
| 3419 |
assert_ne!(k1, k4); |
| 3420 |
|
| 3421 |
let h1 = hash_it(k1); |
| 3422 |
let h2 = hash_it(k2); |
| 3423 |
let h3 = hash_it(k3); |
| 3424 |
let h4 = hash_it(k4); |
| 3425 |
|
| 3426 |
assert_eq!(h1, h2); |
| 3427 |
assert_eq!(h1, h3); |
| 3428 |
assert_ne!(h1, h4); |
| 3429 |
|
| 3430 |
// Test the application of Hash calculation to a HashMap. |
| 3431 |
|
| 3432 |
let mut map = std::collections::HashMap::new(); |
| 3433 |
|
| 3434 |
map.insert(k1, k1.to_string()); |
| 3435 |
// map[k2] should overwrite map[k1] because k1 == k2. |
| 3436 |
map.insert(k2, k2.to_string()); |
| 3437 |
|
| 3438 |
assert_eq!("1.0", map.get(&k3).expect("could not get k3")); |
| 3439 |
assert_eq!(1, map.len()); |
| 3440 |
|
| 3441 |
// map[k3] should overwrite map[k2] because k3 == k2. |
| 3442 |
map.insert(k3, k3.to_string()); |
| 3443 |
// map[k4] should not overwrite map[k3] because k4 != k3. |
| 3444 |
map.insert(k4, k4.to_string()); |
| 3445 |
|
| 3446 |
assert_eq!(2, map.len()); |
| 3447 |
assert_eq!("1.00", map.get(&k1).expect("could not get k1")); |
| 3448 |
} |
| 3449 |
|
| 3450 |
#[test] |
| 3451 |
fn it_computes_equal_hashes_for_positive_and_negative_zero() { |
| 3452 |
// Verify 0 and -0 have the same hash |
| 3453 |
let k1 = Decimal::from_str("0").unwrap(); |
| 3454 |
let k2 = Decimal::from_str("-0").unwrap(); |
| 3455 |
assert_eq!(k1, k2); |
| 3456 |
let h1 = hash_it(k1); |
| 3457 |
let h2 = hash_it(k2); |
| 3458 |
assert_eq!(h1, h2); |
| 3459 |
|
| 3460 |
// Verify 0 and -0.0 have the same hash |
| 3461 |
let k1 = Decimal::from_str("0").unwrap(); |
| 3462 |
let k2 = Decimal::from_str("-0.0").unwrap(); |
| 3463 |
assert_eq!(k1, k2); |
| 3464 |
let h1 = hash_it(k1); |
| 3465 |
let h2 = hash_it(k2); |
| 3466 |
assert_eq!(h1, h2); |
| 3467 |
} |
| 3468 |
|
| 3469 |
#[test] |
| 3470 |
#[should_panic(expected = "Number less than minimum value that can be represented.")] |
| 3471 |
fn it_handles_i128_min() { |
| 3472 |
let _ = Decimal::from_i128_with_scale(i128::MIN, 0); |
| 3473 |
} |
| 3474 |
|
| 3475 |
#[test] |
| 3476 |
fn it_handles_i128_min_safely() { |
| 3477 |
let result = Decimal::try_from_i128_with_scale(i128::MIN, 0); |
| 3478 |
assert!(result.is_err()); |
| 3479 |
assert_eq!(result.err().unwrap(), Error::LessThanMinimumPossibleValue); |
| 3480 |
} |
| 3481 |
|
| 3482 |
#[test] |
| 3483 |
fn it_can_rescale() { |
| 3484 |
let tests = &[ |
| 3485 |
("0", 6, "0.000000", 6), |
| 3486 |
("0.000000", 2, "0.00", 2), |
| 3487 |
("0.12345600000", 6, "0.123456", 6), |
| 3488 |
("0.123456", 12, "0.123456000000", 12), |
| 3489 |
("0.123456", 0, "0", 0), |
| 3490 |
("0.000001", 4, "0.0000", 4), |
| 3491 |
("1233456", 4, "1233456.0000", 4), |
| 3492 |
// Cap to 28 |
| 3493 |
("1.2", 30, "1.2000000000000000000000000000", 28), |
| 3494 |
("79228162514264337593543950335", 0, "79228162514264337593543950335", 0), |
| 3495 |
("4951760157141521099596496895", 1, "4951760157141521099596496895.0", 1), |
| 3496 |
("4951760157141521099596496896", 1, "4951760157141521099596496896.0", 1), |
| 3497 |
("18446744073709551615", 6, "18446744073709551615.000000", 6), |
| 3498 |
("-18446744073709551615", 6, "-18446744073709551615.000000", 6), |
| 3499 |
// 27 since we can't fit a scale of 28 for this number |
| 3500 |
("11.76470588235294", 28, "11.764705882352940000000000000", 27), |
| 3501 |
]; |
| 3502 |
|
| 3503 |
for &(value_raw, new_scale, expected_value, expected_scale) in tests { |
| 3504 |
let mut value = Decimal::from_str(value_raw).unwrap(); |
| 3505 |
value.rescale(new_scale); |
| 3506 |
assert_eq!(expected_value, value.to_string()); |
| 3507 |
assert_eq!(expected_scale, value.scale()); |
| 3508 |
} |
| 3509 |
} |
| 3510 |
|
| 3511 |
#[test] |
| 3512 |
fn test_constants() { |
| 3513 |
assert_eq!("0", Decimal::ZERO.to_string()); |
| 3514 |
assert_eq!("1", Decimal::ONE.to_string()); |
| 3515 |
assert_eq!("-1", Decimal::NEGATIVE_ONE.to_string()); |
| 3516 |
assert_eq!("10", Decimal::TEN.to_string()); |
| 3517 |
assert_eq!("100", Decimal::ONE_HUNDRED.to_string()); |
| 3518 |
assert_eq!("1000", Decimal::ONE_THOUSAND.to_string()); |
| 3519 |
assert_eq!("2", Decimal::TWO.to_string()); |
| 3520 |
} |
| 3521 |
|
| 3522 |
#[test] |
| 3523 |
fn test_inv() { |
| 3524 |
assert_eq!("0.01", Decimal::ONE_HUNDRED.inv().to_string()); |
| 3525 |
} |
| 3526 |
|
| 3527 |
// Mathematical features |
| 3528 |
#[cfg(feature = "maths")] |
| 3529 |
mod maths { |
| 3530 |
use super::*; |
| 3531 |
use rust_decimal::MathematicalOps; |
| 3532 |
|
| 3533 |
use num_traits::One; |
| 3534 |
|
| 3535 |
#[test] |
| 3536 |
fn test_constants() { |
| 3537 |
assert_eq!("3.1415926535897932384626433833", Decimal::PI.to_string()); |
| 3538 |
assert_eq!("6.2831853071795864769252867666", Decimal::TWO_PI.to_string()); |
| 3539 |
assert_eq!("1.5707963267948966192313216916", Decimal::HALF_PI.to_string()); |
| 3540 |
assert_eq!("2.7182818284590452353602874714", Decimal::E.to_string()); |
| 3541 |
assert_eq!("0.3678794411714423215955237702", Decimal::E_INVERSE.to_string()); |
| 3542 |
} |
| 3543 |
|
| 3544 |
#[test] |
| 3545 |
fn test_powu() { |
| 3546 |
let test_cases = &[ |
| 3547 |
// x, y, expected x ^ y |
| 3548 |
("4", 3_u64, "64"), |
| 3549 |
("3.222", 5_u64, "347.238347228449632"), |
| 3550 |
("0.1", 0_u64, "1"), |
| 3551 |
("342.4", 1_u64, "342.4"), |
| 3552 |
("2.0", 16_u64, "65536"), |
| 3553 |
]; |
| 3554 |
for &(x, y, expected) in test_cases { |
| 3555 |
let x = Decimal::from_str(x).unwrap(); |
| 3556 |
let pow = x.powu(y); |
| 3557 |
assert_eq!(pow.to_string(), expected, "{} ^ {}", x, y); |
| 3558 |
} |
| 3559 |
} |
| 3560 |
|
| 3561 |
#[test] |
| 3562 |
#[should_panic(expected = "Pow overflowed")] |
| 3563 |
fn test_powu_panic() { |
| 3564 |
let two = Decimal::new(2, 0); |
| 3565 |
let _ = two.powu(128); |
| 3566 |
} |
| 3567 |
|
| 3568 |
#[test] |
| 3569 |
fn test_checked_powu() { |
| 3570 |
let test_cases = &[ |
| 3571 |
(Decimal::new(4, 0), 3_u64, Some(Decimal::new(64, 0))), |
| 3572 |
( |
| 3573 |
Decimal::from_str("3.222").unwrap(), |
| 3574 |
5_u64, |
| 3575 |
Some(Decimal::from_str("347.238347228449632").unwrap()), |
| 3576 |
), |
| 3577 |
( |
| 3578 |
Decimal::from_str("0.1").unwrap(), |
| 3579 |
0_u64, |
| 3580 |
Some(Decimal::from_str("1").unwrap()), |
| 3581 |
), |
| 3582 |
( |
| 3583 |
Decimal::from_str("342.4").unwrap(), |
| 3584 |
1_u64, |
| 3585 |
Some(Decimal::from_str("342.4").unwrap()), |
| 3586 |
), |
| 3587 |
( |
| 3588 |
Decimal::from_str("2.0").unwrap(), |
| 3589 |
16_u64, |
| 3590 |
Some(Decimal::from_str("65536").unwrap()), |
| 3591 |
), |
| 3592 |
(Decimal::from_str("2.0").unwrap(), 128_u64, None), |
| 3593 |
]; |
| 3594 |
for case in test_cases { |
| 3595 |
assert_eq!(case.2, case.0.checked_powu(case.1)); |
| 3596 |
} |
| 3597 |
} |
| 3598 |
|
| 3599 |
#[test] |
| 3600 |
fn test_powi() { |
| 3601 |
let test_cases = &[ |
| 3602 |
// x, y, expected x ^ y |
| 3603 |
("0", 0, "1"), |
| 3604 |
("1", 0, "1"), |
| 3605 |
("0", 1, "0"), |
| 3606 |
("2", 3, "8"), |
| 3607 |
("-2", 3, "-8"), |
| 3608 |
("2", -3, "0.125"), |
| 3609 |
("-2", -3, "-0.125"), |
| 3610 |
( |
| 3611 |
"3", |
| 3612 |
-3, |
| 3613 |
either!("0.037037037037037037037037037", "0.0370370370370370370370370370"), |
| 3614 |
), |
| 3615 |
("6", 3, "216"), |
| 3616 |
("0.5", 2, "0.25"), |
| 3617 |
]; |
| 3618 |
for &(x, y, expected) in test_cases { |
| 3619 |
let x = Decimal::from_str(x).unwrap(); |
| 3620 |
let pow = x.powi(y); |
| 3621 |
assert_eq!(pow.to_string(), expected, "{} ^ {}", x, y); |
| 3622 |
} |
| 3623 |
} |
| 3624 |
|
| 3625 |
#[test] |
| 3626 |
fn test_powd() { |
| 3627 |
let test_cases = &[ |
| 3628 |
// x, y, expected x ^ y |
| 3629 |
("0", "0", "1"), |
| 3630 |
("1", "0", "1"), |
| 3631 |
("0", "1", "0"), |
| 3632 |
("2", "3", "8"), |
| 3633 |
("-2", "3", "-8"), |
| 3634 |
("2", "-3", "0.125"), |
| 3635 |
("-2", "-3", "-0.125"), |
| 3636 |
("2.0", "3.0", "8"), |
| 3637 |
("-2.0", "3.0", "-8"), |
| 3638 |
("2.0", "-3.0", "0.125"), |
| 3639 |
("-2.0", "-3.0", "-0.125"), |
| 3640 |
("2.00", "3.00", "8"), |
| 3641 |
("-2.00", "3.00", "-8"), |
| 3642 |
("2.00", "-3.00", "0.125"), |
| 3643 |
("-2.00", "-3.00", "-0.125"), |
| 3644 |
( |
| 3645 |
"3", |
| 3646 |
"-3", |
| 3647 |
either!("0.037037037037037037037037037", "0.0370370370370370370370370370"), |
| 3648 |
), |
| 3649 |
("6", "3", "216"), |
| 3650 |
("0.5", "2", "0.25"), |
| 3651 |
("6", "13", "13060694016"), |
| 3652 |
// Exact result: 1 / 6^7 |
| 3653 |
("6", "-7", "0.0000035722450845907636031093"), |
| 3654 |
// ~= 0.8408964152537145 |
| 3655 |
( |
| 3656 |
"0.5", |
| 3657 |
"0.25", |
| 3658 |
either!("0.8408964159265360661551317741", "0.8408964159265360661551317742"), |
| 3659 |
), |
| 3660 |
// ~= 0.999999999999999999999999999790814 |
| 3661 |
( |
| 3662 |
"0.1234567890123456789012345678", |
| 3663 |
"0.0000000000000000000000000001", |
| 3664 |
"0.9999999999999999999999999998", |
| 3665 |
), |
| 3666 |
// ~= 611.0451043224257 |
| 3667 |
( |
| 3668 |
"1234.5678", |
| 3669 |
"0.9012", |
| 3670 |
either!("611.04510415448740041442807964", "611.04510415448740041442807964"), |
| 3671 |
), |
| 3672 |
( |
| 3673 |
"-2", |
| 3674 |
"0.5", |
| 3675 |
either!("-1.4142135570048917090885260834", "-1.4142135570048917090885260835"), |
| 3676 |
), |
| 3677 |
// ~= -1.1193003023312942 |
| 3678 |
( |
| 3679 |
"-2.5", |
| 3680 |
"0.123", |
| 3681 |
either!("-1.1193002994383985239135362086", "-1.1193002994383985239135362086"), |
| 3682 |
), |
| 3683 |
// ~= 0.0003493091 |
| 3684 |
( |
| 3685 |
"0.0000000000000000000000000001", |
| 3686 |
"0.1234567890123456789012345678", |
| 3687 |
either!("0.0003533642875741443321850682", "0.0003305188683169079961720764"), |
| 3688 |
), |
| 3689 |
]; |
| 3690 |
for &(x, y, expected) in test_cases { |
| 3691 |
let x = Decimal::from_str(x).unwrap(); |
| 3692 |
let y = Decimal::from_str(y).unwrap(); |
| 3693 |
let pow = x.powd(y); |
| 3694 |
assert_eq!(pow.to_string(), expected, "{} ^ {}", x, y); |
| 3695 |
} |
| 3696 |
} |
| 3697 |
|
| 3698 |
#[test] |
| 3699 |
fn test_sqrt() { |
| 3700 |
let test_cases = &[ |
| 3701 |
("4", "2"), |
| 3702 |
("3.222", "1.7949930361981909371487724124"), |
| 3703 |
("199.45", "14.122676800097069416754994263"), |
| 3704 |
("342.4", "18.504053609952604112132102540"), |
| 3705 |
("2", "1.414213562373095048801688724209698078569671875376948073176"), |
| 3706 |
("0.0000000000000000000000000001", "0.0000000000000100000000000000"), |
| 3707 |
]; |
| 3708 |
for case in test_cases { |
| 3709 |
let a = Decimal::from_str(case.0).unwrap(); |
| 3710 |
let expected = Decimal::from_str(case.1).unwrap(); |
| 3711 |
assert_eq!(expected, a.sqrt().unwrap()); |
| 3712 |
} |
| 3713 |
|
| 3714 |
assert_eq!(Decimal::new(-2, 0).sqrt(), None); |
| 3715 |
} |
| 3716 |
|
| 3717 |
#[cfg(not(feature = "legacy-ops"))] |
| 3718 |
#[test] |
| 3719 |
fn test_exp() { |
| 3720 |
// These are approximations |
| 3721 |
let test_cases = &[ |
| 3722 |
// e^10 ~= 22026.465794806703 |
| 3723 |
("10", "22026.416157416030662013737698"), |
| 3724 |
// e^11 ~= 59874.14171519778 |
| 3725 |
("11", "59873.388231055804982198781924"), |
| 3726 |
// e^3 ~= 20.085536923187664 |
| 3727 |
("3", "20.085536911963143539758560764"), |
| 3728 |
// e^8 ~= 2980.957987041727 |
| 3729 |
("8", "2980.9578998304103856663509017"), |
| 3730 |
// e^0.1 ~= 1.1051709180756477 |
| 3731 |
("0.1", "1.1051709166666666666666666667"), |
| 3732 |
// e^2.0 ~= 7.3890560989306495 |
| 3733 |
("2.0", "7.3890560703259115957528655940"), |
| 3734 |
// e^-2 ~= 0.1353352832366127 |
| 3735 |
("-2", "0.1353352837605267572029589224"), |
| 3736 |
// e^-1 ~= 0.36787944117144233 |
| 3737 |
("-1", "0.3678794414773748171422559335"), |
| 3738 |
// e^0.123456789 ~= 1.131401115 |
| 3739 |
("0.123456789", "1.1314011144241455834073838005"), |
| 3740 |
// e^0.123456789123456789123456789 ~= 1.131401114651912752617990081 |
| 3741 |
("0.123456789123456789123456789", "1.1314011145638247316063947842"), |
| 3742 |
]; |
| 3743 |
for &(x, expected) in test_cases { |
| 3744 |
let x = Decimal::from_str(x).unwrap(); |
| 3745 |
let expected = Decimal::from_str(expected).unwrap(); |
| 3746 |
assert_eq!(expected, x.exp()); |
| 3747 |
assert_eq!(Some(expected), x.checked_exp()); |
| 3748 |
} |
| 3749 |
} |
| 3750 |
|
| 3751 |
#[cfg(not(feature = "legacy-ops"))] |
| 3752 |
#[test] |
| 3753 |
fn test_exp_with_tolerance() { |
| 3754 |
let test_cases = &[ |
| 3755 |
// e^0 = 1 |
| 3756 |
("0", "0.0002", "1"), |
| 3757 |
// e^1 ~= 2.7182539682539682539682539683 |
| 3758 |
("1", "0.0002", "2.7182539682539682539682539683"), |
| 3759 |
// e^10 ~= 22026.465794806703 |
| 3760 |
( |
| 3761 |
"10", |
| 3762 |
"0.02", |
| 3763 |
either!("22026.416157416030662013737698", "22026.416157416030662013737699"), |
| 3764 |
), |
| 3765 |
// e^11 ~= 59874.14171519778 |
| 3766 |
("11", "0.0002", "59873.388231055804982198781924"), |
| 3767 |
// e^11.7578 ~= 127741.03548949540892948423052 |
| 3768 |
("11.7578", "0.0002", "127741.03548949540892948423052"), |
| 3769 |
// e^3 ~= 20.085536923187664 |
| 3770 |
("3", "0.00002", "20.085534430970814899386327955"), |
| 3771 |
// e^8 ~= 2980.957987041727 |
| 3772 |
("8", "0.0002", "2980.9578998304103856663509017"), |
| 3773 |
// e^0.1 ~= 1.1051709180756477 |
| 3774 |
("0.1", "0.0002", "1.1051666666666666666666666667"), |
| 3775 |
// e^2.0 ~= 7.3890560989306495 |
| 3776 |
("2.0", "0.0002", "7.3890460157126823793490460156"), |
| 3777 |
// e^11.7578+ starts to overflow |
| 3778 |
("11.7579", "0.0002", ""), |
| 3779 |
// e^11.7578+ starts to overflow |
| 3780 |
("123", "0.0002", ""), |
| 3781 |
// e^-8+ starts to underflow |
| 3782 |
("-8", "0.0002", "0.0003354626377168530220952633"), |
| 3783 |
// e^-9 continues to converge towards zero |
| 3784 |
("-9", "0.0002", "0.0001234098417553083895710102"), |
| 3785 |
// e^-11 continues to converge towards zero |
| 3786 |
("-11", "0.0002", "0.0000167019109748879838728391"), |
| 3787 |
// e^11.7579 has underflowed (by overflowing) |
| 3788 |
("-11.7579", "0.0002", ""), |
| 3789 |
// e^-1024 has fully underflowed (by overflowing) |
| 3790 |
("-1024", "0.0002", ""), |
| 3791 |
]; |
| 3792 |
for &(x, tolerance, expected) in test_cases { |
| 3793 |
let x = Decimal::from_str(x).unwrap(); |
| 3794 |
let tolerance = Decimal::from_str(tolerance).unwrap(); |
| 3795 |
let expected = if expected.is_empty() { |
| 3796 |
None |
| 3797 |
} else { |
| 3798 |
Some(Decimal::from_str(expected).unwrap()) |
| 3799 |
}; |
| 3800 |
|
| 3801 |
if let Some(expected) = expected { |
| 3802 |
assert_eq!(expected, x.exp_with_tolerance(tolerance)); |
| 3803 |
assert_eq!(Some(expected), x.checked_exp_with_tolerance(tolerance)); |
| 3804 |
} else { |
| 3805 |
assert_eq!(None, x.checked_exp_with_tolerance(tolerance)); |
| 3806 |
} |
| 3807 |
} |
| 3808 |
} |
| 3809 |
|
| 3810 |
#[test] |
| 3811 |
#[should_panic(expected = "Exp overflowed")] |
| 3812 |
fn test_exp_expected_panic_from_overflow() { |
| 3813 |
let d = Decimal::from_str("1024").unwrap(); |
| 3814 |
let _ = d.exp(); |
| 3815 |
} |
| 3816 |
|
| 3817 |
#[test] |
| 3818 |
#[should_panic(expected = "Exp underflowed")] |
| 3819 |
fn test_exp_expected_panic_from_underflow() { |
| 3820 |
let d = Decimal::from_str("-1024").unwrap(); |
| 3821 |
let _ = d.exp(); |
| 3822 |
} |
| 3823 |
|
| 3824 |
#[test] |
| 3825 |
fn test_norm_cdf() { |
| 3826 |
let test_cases = &[ |
| 3827 |
( |
| 3828 |
Decimal::from_str("-0.4").unwrap(), |
| 3829 |
either!( |
| 3830 |
Decimal::from_str("0.3445781286821245037094401704").unwrap(), |
| 3831 |
Decimal::from_str("0.3445781286821245037094401728").unwrap() |
| 3832 |
), |
| 3833 |
), |
| 3834 |
( |
| 3835 |
Decimal::from_str("-0.1").unwrap(), |
| 3836 |
either!( |
| 3837 |
Decimal::from_str("0.4601722899186706579921922696").unwrap(), |
| 3838 |
Decimal::from_str("0.4601722899186706579921922711").unwrap() |
| 3839 |
), |
| 3840 |
), |
| 3841 |
( |
| 3842 |
Decimal::from_str("0.1").unwrap(), |
| 3843 |
Decimal::from_str(either!( |
| 3844 |
"0.5398277100813293420078077304", |
| 3845 |
"0.5398277100813293420078077290" |
| 3846 |
)) |
| 3847 |
.unwrap(), |
| 3848 |
), |
| 3849 |
( |
| 3850 |
Decimal::from_str("0.4").unwrap(), |
| 3851 |
either!( |
| 3852 |
Decimal::from_str("0.6554218713178754962905598296").unwrap(), |
| 3853 |
Decimal::from_str("0.6554218713178754962905598272").unwrap() |
| 3854 |
), |
| 3855 |
), |
| 3856 |
( |
| 3857 |
Decimal::from_str("2.0").unwrap(), |
| 3858 |
either!( |
| 3859 |
Decimal::from_str("0.9772497381095865280953380673").unwrap(), |
| 3860 |
Decimal::from_str("0.9772497381095865280953380672").unwrap() |
| 3861 |
), |
| 3862 |
), |
| 3863 |
]; |
| 3864 |
for case in test_cases { |
| 3865 |
assert_eq!(case.1, case.0.norm_cdf()); |
| 3866 |
} |
| 3867 |
} |
| 3868 |
|
| 3869 |
#[test] |
| 3870 |
fn test_norm_pdf() { |
| 3871 |
let test_cases = &[ |
| 3872 |
( |
| 3873 |
Decimal::from_str("-2.0").unwrap(), |
| 3874 |
Decimal::from_str("0.0539909667221995238993056051").unwrap(), |
| 3875 |
), |
| 3876 |
( |
| 3877 |
Decimal::from_str("-0.4").unwrap(), |
| 3878 |
Decimal::from_str("0.3682701404285264134348468378").unwrap(), |
| 3879 |
), |
| 3880 |
( |
| 3881 |
Decimal::from_str("-0.1").unwrap(), |
| 3882 |
Decimal::from_str("0.3969525474873078082322691394").unwrap(), |
| 3883 |
), |
| 3884 |
( |
| 3885 |
Decimal::from_str("0.1").unwrap(), |
| 3886 |
Decimal::from_str("0.3969525474873078082322691394").unwrap(), |
| 3887 |
), |
| 3888 |
( |
| 3889 |
Decimal::from_str("0.4").unwrap(), |
| 3890 |
Decimal::from_str("0.3682701404285264134348468378").unwrap(), |
| 3891 |
), |
| 3892 |
( |
| 3893 |
Decimal::from_str("2.0").unwrap(), |
| 3894 |
Decimal::from_str("0.0539909667221995238993056051").unwrap(), |
| 3895 |
), |
| 3896 |
]; |
| 3897 |
for case in test_cases { |
| 3898 |
assert_eq!(case.1, case.0.norm_pdf()); |
| 3899 |
} |
| 3900 |
} |
| 3901 |
|
| 3902 |
#[test] |
| 3903 |
fn test_ln() { |
| 3904 |
let test_cases = [ |
| 3905 |
("1", "0"), |
| 3906 |
// Wolfram Alpha gives -1.46968 |
| 3907 |
( |
| 3908 |
"0.23", |
| 3909 |
either!("-1.4696759700589416772292300779", "-1.4696759700589416772292300777"), |
| 3910 |
), |
| 3911 |
// Wolfram Alpha gives 0.693147180559945309417232121458176568075500134360255254120 |
| 3912 |
("2", "0.6931471805599453094172321218"), |
| 3913 |
// Wolfram Alpha gives 3.218875824868200749201518666452375279051202708537035443825 |
| 3914 |
( |
| 3915 |
"25", |
| 3916 |
either!("3.2188758248682007492015186670", "3.2188758248682007492015186674"), |
| 3917 |
), |
| 3918 |
// Wolfram Alpha gives 0.210721022 |
| 3919 |
( |
| 3920 |
"1.234567890", |
| 3921 |
either!("0.2107210222156525610500017104", "0.2107210222156525610500017106"), |
| 3922 |
), |
| 3923 |
]; |
| 3924 |
|
| 3925 |
for (input, expected) in test_cases { |
| 3926 |
let input = Decimal::from_str(input).unwrap(); |
| 3927 |
let expected = Decimal::from_str(expected).unwrap(); |
| 3928 |
assert_eq!(expected, input.ln(), "Failed to calculate ln({})", input); |
| 3929 |
} |
| 3930 |
} |
| 3931 |
|
| 3932 |
#[test] |
| 3933 |
#[cfg(feature = "maths-nopanic")] |
| 3934 |
fn test_invalid_ln_nopanic() { |
| 3935 |
let test_cases = ["0", "-2.0"]; |
| 3936 |
|
| 3937 |
for input in test_cases { |
| 3938 |
let input = Decimal::from_str(input).unwrap(); |
| 3939 |
assert_eq!("0", input.ln().to_string(), "Failed to calculate ln({})", input); |
| 3940 |
} |
| 3941 |
} |
| 3942 |
|
| 3943 |
#[test] |
| 3944 |
#[should_panic(expected = "Unable to calculate ln for zero")] |
| 3945 |
#[cfg(not(feature = "maths-nopanic"))] |
| 3946 |
fn test_invalid_ln_zero_panic() { |
| 3947 |
let _ = Decimal::ZERO.ln(); |
| 3948 |
} |
| 3949 |
|
| 3950 |
#[test] |
| 3951 |
#[should_panic(expected = "Unable to calculate ln for negative numbers")] |
| 3952 |
#[cfg(not(feature = "maths-nopanic"))] |
| 3953 |
fn test_invalid_ln_negative_panic() { |
| 3954 |
let _ = Decimal::NEGATIVE_ONE.ln(); |
| 3955 |
} |
| 3956 |
|
| 3957 |
#[test] |
| 3958 |
fn test_log10() { |
| 3959 |
let test_cases = [ |
| 3960 |
("1", "0"), |
| 3961 |
// Wolfram Alpha: 0.3010299956639811952137388947 |
| 3962 |
( |
| 3963 |
"2", |
| 3964 |
either!("0.3010299956639811952137388949", "0.3010299956639811952137388948"), |
| 3965 |
), |
| 3966 |
// Wolfram Alpha: 0.0915149772 |
| 3967 |
( |
| 3968 |
"1.234567890", |
| 3969 |
either!("0.0915149771692704475183336230", "0.0915149771692704475183336231"), |
| 3970 |
), |
| 3971 |
("10", "1"), |
| 3972 |
("100", "2"), |
| 3973 |
("1000", "3"), |
| 3974 |
("1000.00000000", "3"), |
| 3975 |
("1000.000000000000000000000", "3"), |
| 3976 |
("10.000000000000000000000000000", "1"), |
| 3977 |
("100000000000000.0000000000", "14"), |
| 3978 |
("0.10", "-1"), |
| 3979 |
("0.1", "-1"), |
| 3980 |
("0.01", "-2"), |
| 3981 |
("0.010", "-2"), |
| 3982 |
("0.0100000000000000000", "-2"), |
| 3983 |
("0.000001", "-6"), |
| 3984 |
("0.000001000000000", "-6"), |
| 3985 |
]; |
| 3986 |
|
| 3987 |
for (input, expected) in test_cases { |
| 3988 |
let input = Decimal::from_str(input).unwrap(); |
| 3989 |
let expected = Decimal::from_str(expected).unwrap(); |
| 3990 |
assert_eq!(expected, input.log10(), "Failed to calculate log10({})", input); |
| 3991 |
} |
| 3992 |
} |
| 3993 |
|
| 3994 |
#[test] |
| 3995 |
#[cfg(feature = "maths-nopanic")] |
| 3996 |
fn test_invalid_log10_nopanic() { |
| 3997 |
let test_cases = ["0", "-2.0"]; |
| 3998 |
|
| 3999 |
for input in test_cases { |
| 4000 |
let input = Decimal::from_str(input).unwrap(); |
| 4001 |
assert_eq!("0", input.log10().to_string(), "Failed to calculate ln({})", input); |
| 4002 |
} |
| 4003 |
} |
| 4004 |
|
| 4005 |
#[test] |
| 4006 |
#[should_panic(expected = "Unable to calculate log10 for zero")] |
| 4007 |
#[cfg(not(feature = "maths-nopanic"))] |
| 4008 |
fn test_invalid_log10_zero_panic() { |
| 4009 |
let _ = Decimal::ZERO.log10(); |
| 4010 |
} |
| 4011 |
|
| 4012 |
#[test] |
| 4013 |
#[should_panic(expected = "Unable to calculate log10 for negative numbers")] |
| 4014 |
#[cfg(not(feature = "maths-nopanic"))] |
| 4015 |
fn test_invalid_log10_negative_panic() { |
| 4016 |
let _ = Decimal::NEGATIVE_ONE.log10(); |
| 4017 |
} |
| 4018 |
|
| 4019 |
#[test] |
| 4020 |
fn test_erf() { |
| 4021 |
let test_cases = &[ |
| 4022 |
( |
| 4023 |
Decimal::from_str("-2.0").unwrap(), |
| 4024 |
// Wolfram give -0.9953222650189527 |
| 4025 |
Decimal::from_str("-0.9953225170750043399400930073").unwrap(), |
| 4026 |
), |
| 4027 |
( |
| 4028 |
Decimal::from_str("-0.4").unwrap(), |
| 4029 |
Decimal::from_str("-0.4283924127205154977961931420").unwrap(), |
| 4030 |
), |
| 4031 |
( |
| 4032 |
Decimal::from_str("0.4").unwrap(), |
| 4033 |
Decimal::from_str("0.4283924127205154977961931420").unwrap(), |
| 4034 |
), |
| 4035 |
( |
| 4036 |
Decimal::one(), |
| 4037 |
Decimal::from_str("0.8427010463338918630217928957").unwrap(), |
| 4038 |
), |
| 4039 |
( |
| 4040 |
Decimal::from_str("2").unwrap(), |
| 4041 |
Decimal::from_str("0.9953225170750043399400930073").unwrap(), |
| 4042 |
), |
| 4043 |
]; |
| 4044 |
for case in test_cases { |
| 4045 |
assert_eq!(case.1, case.0.erf()); |
| 4046 |
} |
| 4047 |
} |
| 4048 |
|
| 4049 |
#[test] |
| 4050 |
fn test_checked_sin() { |
| 4051 |
const ACCEPTED_PRECISION: u32 = 10; |
| 4052 |
let test_cases = &[ |
| 4053 |
// Sin(0) |
| 4054 |
("0", Some("0")), |
| 4055 |
// Sin(PI/2) |
| 4056 |
("1.5707963267948966192313216916", Some("1")), |
| 4057 |
// Sin(PI) |
| 4058 |
("3.1415926535897932384626433833", Some("0")), |
| 4059 |
// Sin(3PI/2) |
| 4060 |
("4.7123889803846898576939650749", Some("-1")), |
| 4061 |
// Sin(2PI) |
| 4062 |
("6.2831853071795864769252867666", Some("0")), |
| 4063 |
// Sin(1) ~= 0.8414709848078965066525023216302989996225630607983710656727517099 |
| 4064 |
("1", Some("0.8414709848078965066525023216")), |
| 4065 |
// Sin(2) ~= 0.9092974268256816953960198659117448427022549714478902683789730115 |
| 4066 |
("2", Some("0.9092974268256816953960198659")), |
| 4067 |
// Sin(4) ~= -0.756802495307928251372639094511829094135912887336472571485416773 |
| 4068 |
("4", Some("-0.7568024953079282513726390945")), |
| 4069 |
// Sin(6) ~= -0.279415498198925872811555446611894759627994864318204318483351369 |
| 4070 |
("6", Some("-0.2794154981989258728115554466")), |
| 4071 |
// WA estimate: -0.893653245236708. Legacy ops is closer to f64 accuracy. |
| 4072 |
( |
| 4073 |
"-79228162514264.337593543950335", |
| 4074 |
Some(either!("-0.893653245236708", "-0.8963358176")), |
| 4075 |
), |
| 4076 |
]; |
| 4077 |
for (input, result) in test_cases { |
| 4078 |
let radians = Decimal::from_str(input).unwrap(); |
| 4079 |
let sin = radians.checked_sin(); |
| 4080 |
if let Some(result) = result { |
| 4081 |
assert!(sin.is_some(), "Expected result for sin({})", input); |
| 4082 |
let result = Decimal::from_str(result).unwrap(); |
| 4083 |
assert_approx_eq!(sin.unwrap(), result, ACCEPTED_PRECISION, "sin({})", input); |
| 4084 |
} else { |
| 4085 |
assert!(sin.is_none(), "Unexpected result for sin({})", input); |
| 4086 |
} |
| 4087 |
} |
| 4088 |
} |
| 4089 |
|
| 4090 |
#[test] |
| 4091 |
fn test_checked_cos() { |
| 4092 |
const ACCEPTED_PRECISION: u32 = 10; |
| 4093 |
let test_cases = &[ |
| 4094 |
// Cos(0) |
| 4095 |
("0", Some("1")), |
| 4096 |
// Cos(PI/2) |
| 4097 |
("1.5707963267948966192313216916", Some("0")), |
| 4098 |
// Cos(PI) |
| 4099 |
("3.1415926535897932384626433833", Some("-1")), |
| 4100 |
// Cos(3PI/2) |
| 4101 |
("4.7123889803846898576939650749", Some("0")), |
| 4102 |
// Cos(2PI) |
| 4103 |
("6.2831853071795864769252867666", Some("1")), |
| 4104 |
// Cos(1) ~= 0.5403023058681397174009366074429766037323104206179222276700972553 |
| 4105 |
("1", Some("0.5403023058681397174009366074")), |
| 4106 |
// Cos(2) ~= -0.416146836547142386997568229500762189766000771075544890755149973 |
| 4107 |
("2", Some("-0.4161468365471423869975682295")), |
| 4108 |
// Cos(4) ~= -0.653643620863611914639168183097750381424133596646218247007010283 |
| 4109 |
("4", Some("-0.6536436208636119146391681831")), |
| 4110 |
// Cos(6) ~= 0.9601702866503660205456522979229244054519376792110126981292864260 |
| 4111 |
("6", Some("0.9601702866503660205456522979")), |
| 4112 |
// WA estimate: 0.448758150096352. Legacy ops is closer to f64 accuracy. |
| 4113 |
( |
| 4114 |
"-79228162514264.337593543950335", |
| 4115 |
Some(either!("0.448758150096352", "0.443375802326")), |
| 4116 |
), |
| 4117 |
]; |
| 4118 |
for (input, result) in test_cases { |
| 4119 |
let radians = Decimal::from_str(input).unwrap(); |
| 4120 |
let cos = radians.checked_cos(); |
| 4121 |
if let Some(result) = result { |
| 4122 |
assert!(cos.is_some(), "Expected result for cos({})", input); |
| 4123 |
let result = Decimal::from_str(result).unwrap(); |
| 4124 |
assert_approx_eq!(cos.unwrap(), result, ACCEPTED_PRECISION, "cos({})", input); |
| 4125 |
} else { |
| 4126 |
assert!(cos.is_none(), "Unexpected result for cos({})", input); |
| 4127 |
} |
| 4128 |
} |
| 4129 |
} |
| 4130 |
|
| 4131 |
#[test] |
| 4132 |
fn test_checked_tan() { |
| 4133 |
const ACCEPTED_PRECISION: u32 = 8; |
| 4134 |
let test_cases = &[ |
| 4135 |
// Tan(0) |
| 4136 |
("0", Some("0")), |
| 4137 |
// Tan(PI/2) |
| 4138 |
("1.5707963267948966192313216916", None), |
| 4139 |
// Tan(PI) |
| 4140 |
("3.1415926535897932384626433833", Some("0")), |
| 4141 |
// Tan(3PI/2) |
| 4142 |
("4.7123889803846898576939650749", None), |
| 4143 |
// Tan(2PI) |
| 4144 |
("6.2831853071795864769252867666", Some("0")), |
| 4145 |
// Tan(1) ~= 1.5574077246549022305069748074583601730872507723815200383839466056 |
| 4146 |
("1", Some("1.5574077246549022305069748075")), |
| 4147 |
// Tan(2) ~= -2.185039863261518991643306102313682543432017746227663164562955869 |
| 4148 |
("2", Some("-2.1850398632615189916433061023")), |
| 4149 |
// Tan(4) ~= 1.1578212823495775831373424182673239231197627673671421300848571893 |
| 4150 |
("4", Some("1.1578212823495775831373424183")), |
| 4151 |
// Tan(6) ~= -0.291006191384749157053699588868175542831155570912339131608827193 |
| 4152 |
("6", Some("-0.2910061913847491570536995889")), |
| 4153 |
// WA estimate: -1.99139167733184. Legacy ops is closer to f64 accuracy. |
| 4154 |
( |
| 4155 |
"-79228162514264.337593543950335", |
| 4156 |
Some(either!("-1.99139167733184", "-2.021616454709")), |
| 4157 |
), |
| 4158 |
]; |
| 4159 |
for (input, result) in test_cases { |
| 4160 |
let radians = Decimal::from_str(input).unwrap(); |
| 4161 |
let tan = radians.checked_tan(); |
| 4162 |
if let Some(result) = result { |
| 4163 |
assert!(tan.is_some(), "Expected result for tan({})", input); |
| 4164 |
let result = Decimal::from_str(result).unwrap(); |
| 4165 |
assert_approx_eq!(tan.unwrap(), result, ACCEPTED_PRECISION, "tan({})", input); |
| 4166 |
} else { |
| 4167 |
assert!(tan.is_none(), "Unexpected result for tan({})", input); |
| 4168 |
} |
| 4169 |
} |
| 4170 |
} |
| 4171 |
} |
| 4172 |
|
| 4173 |
// Generated tests |
| 4174 |
#[cfg(not(feature = "legacy-ops"))] |
| 4175 |
mod generated { |
| 4176 |
use rust_decimal::prelude::*; |
| 4177 |
|
| 4178 |
macro_rules! gen_test { |
| 4179 |
($name:ident, $csv:expr, $method:tt) => { |
| 4180 |
#[test] |
| 4181 |
fn $name() { |
| 4182 |
let path = std::env::current_dir().unwrap(); |
| 4183 |
let mut rdr = csv::Reader::from_reader( |
| 4184 |
std::fs::File::open(format!("{}/tests/generated/{}", path.display(), $csv)).unwrap(), |
| 4185 |
); |
| 4186 |
let mut row = 0; |
| 4187 |
for result in rdr.records() { |
| 4188 |
let record = result.unwrap(); |
| 4189 |
row += 1; |
| 4190 |
|
| 4191 |
// Extract the data |
| 4192 |
let d1 = record.get(0).unwrap(); |
| 4193 |
let d2 = record.get(1).unwrap(); |
| 4194 |
let result = record.get(2).unwrap(); |
| 4195 |
let error = record.get(3).unwrap(); |
| 4196 |
|
| 4197 |
// Do the calc |
| 4198 |
let d1 = Decimal::from_str(&d1).unwrap(); |
| 4199 |
let d2 = Decimal::from_str(&d2).unwrap(); |
| 4200 |
let expected = Decimal::from_str(&result).unwrap(); |
| 4201 |
match d1.$method(d2) { |
| 4202 |
Some(v) => assert_eq!(expected, v, "Row {}", row), |
| 4203 |
None => assert!(!error.is_empty()), |
| 4204 |
} |
| 4205 |
} |
| 4206 |
} |
| 4207 |
}; |
| 4208 |
} |
| 4209 |
|
| 4210 |
gen_test!(test_add_000_001, "Add_000_001.csv", checked_add); |
| 4211 |
gen_test!(test_add_000_010, "Add_000_010.csv", checked_add); |
| 4212 |
gen_test!(test_add_000_011, "Add_000_011.csv", checked_add); |
| 4213 |
gen_test!(test_add_000_100, "Add_000_100.csv", checked_add); |
| 4214 |
gen_test!(test_add_000_101, "Add_000_101.csv", checked_add); |
| 4215 |
gen_test!(test_add_000_110, "Add_000_110.csv", checked_add); |
| 4216 |
gen_test!(test_add_000_111, "Add_000_111.csv", checked_add); |
| 4217 |
gen_test!(test_add_001_000, "Add_001_000.csv", checked_add); |
| 4218 |
gen_test!(test_add_001_001, "Add_001_001.csv", checked_add); |
| 4219 |
gen_test!(test_add_001_010, "Add_001_010.csv", checked_add); |
| 4220 |
gen_test!(test_add_001_011, "Add_001_011.csv", checked_add); |
| 4221 |
gen_test!(test_add_001_100, "Add_001_100.csv", checked_add); |
| 4222 |
gen_test!(test_add_001_101, "Add_001_101.csv", checked_add); |
| 4223 |
gen_test!(test_add_001_110, "Add_001_110.csv", checked_add); |
| 4224 |
gen_test!(test_add_001_111, "Add_001_111.csv", checked_add); |
| 4225 |
gen_test!(test_add_010_000, "Add_010_000.csv", checked_add); |
| 4226 |
gen_test!(test_add_010_001, "Add_010_001.csv", checked_add); |
| 4227 |
gen_test!(test_add_010_010, "Add_010_010.csv", checked_add); |
| 4228 |
gen_test!(test_add_010_011, "Add_010_011.csv", checked_add); |
| 4229 |
gen_test!(test_add_010_100, "Add_010_100.csv", checked_add); |
| 4230 |
gen_test!(test_add_010_101, "Add_010_101.csv", checked_add); |
| 4231 |
gen_test!(test_add_010_110, "Add_010_110.csv", checked_add); |
| 4232 |
gen_test!(test_add_010_111, "Add_010_111.csv", checked_add); |
| 4233 |
gen_test!(test_add_011_000, "Add_011_000.csv", checked_add); |
| 4234 |
gen_test!(test_add_011_001, "Add_011_001.csv", checked_add); |
| 4235 |
gen_test!(test_add_011_010, "Add_011_010.csv", checked_add); |
| 4236 |
gen_test!(test_add_011_011, "Add_011_011.csv", checked_add); |
| 4237 |
gen_test!(test_add_011_100, "Add_011_100.csv", checked_add); |
| 4238 |
gen_test!(test_add_011_101, "Add_011_101.csv", checked_add); |
| 4239 |
gen_test!(test_add_011_110, "Add_011_110.csv", checked_add); |
| 4240 |
gen_test!(test_add_011_111, "Add_011_111.csv", checked_add); |
| 4241 |
gen_test!(test_add_100_000, "Add_100_000.csv", checked_add); |
| 4242 |
gen_test!(test_add_100_001, "Add_100_001.csv", checked_add); |
| 4243 |
gen_test!(test_add_100_010, "Add_100_010.csv", checked_add); |
| 4244 |
gen_test!(test_add_100_011, "Add_100_011.csv", checked_add); |
| 4245 |
gen_test!(test_add_100_100, "Add_100_100.csv", checked_add); |
| 4246 |
gen_test!(test_add_100_101, "Add_100_101.csv", checked_add); |
| 4247 |
gen_test!(test_add_100_110, "Add_100_110.csv", checked_add); |
| 4248 |
gen_test!(test_add_100_111, "Add_100_111.csv", checked_add); |
| 4249 |
gen_test!(test_add_101_000, "Add_101_000.csv", checked_add); |
| 4250 |
gen_test!(test_add_101_001, "Add_101_001.csv", checked_add); |
| 4251 |
gen_test!(test_add_101_010, "Add_101_010.csv", checked_add); |
| 4252 |
gen_test!(test_add_101_011, "Add_101_011.csv", checked_add); |
| 4253 |
gen_test!(test_add_101_100, "Add_101_100.csv", checked_add); |
| 4254 |
gen_test!(test_add_101_101, "Add_101_101.csv", checked_add); |
| 4255 |
gen_test!(test_add_101_110, "Add_101_110.csv", checked_add); |
| 4256 |
gen_test!(test_add_101_111, "Add_101_111.csv", checked_add); |
| 4257 |
gen_test!(test_add_110_000, "Add_110_000.csv", checked_add); |
| 4258 |
gen_test!(test_add_110_001, "Add_110_001.csv", checked_add); |
| 4259 |
gen_test!(test_add_110_010, "Add_110_010.csv", checked_add); |
| 4260 |
gen_test!(test_add_110_011, "Add_110_011.csv", checked_add); |
| 4261 |
gen_test!(test_add_110_100, "Add_110_100.csv", checked_add); |
| 4262 |
gen_test!(test_add_110_101, "Add_110_101.csv", checked_add); |
| 4263 |
gen_test!(test_add_110_110, "Add_110_110.csv", checked_add); |
| 4264 |
gen_test!(test_add_110_111, "Add_110_111.csv", checked_add); |
| 4265 |
gen_test!(test_add_111_000, "Add_111_000.csv", checked_add); |
| 4266 |
gen_test!(test_add_111_001, "Add_111_001.csv", checked_add); |
| 4267 |
gen_test!(test_add_111_010, "Add_111_010.csv", checked_add); |
| 4268 |
gen_test!(test_add_111_011, "Add_111_011.csv", checked_add); |
| 4269 |
gen_test!(test_add_111_100, "Add_111_100.csv", checked_add); |
| 4270 |
gen_test!(test_add_111_101, "Add_111_101.csv", checked_add); |
| 4271 |
gen_test!(test_add_111_110, "Add_111_110.csv", checked_add); |
| 4272 |
gen_test!(test_add_111_111, "Add_111_111.csv", checked_add); |
| 4273 |
|
| 4274 |
gen_test!(test_div_000_001, "Div_000_001.csv", checked_div); |
| 4275 |
gen_test!(test_div_000_010, "Div_000_010.csv", checked_div); |
| 4276 |
gen_test!(test_div_000_011, "Div_000_011.csv", checked_div); |
| 4277 |
gen_test!(test_div_000_100, "Div_000_100.csv", checked_div); |
| 4278 |
gen_test!(test_div_000_101, "Div_000_101.csv", checked_div); |
| 4279 |
gen_test!(test_div_000_110, "Div_000_110.csv", checked_div); |
| 4280 |
gen_test!(test_div_000_111, "Div_000_111.csv", checked_div); |
| 4281 |
gen_test!(test_div_001_000, "Div_001_000.csv", checked_div); |
| 4282 |
gen_test!(test_div_001_001, "Div_001_001.csv", checked_div); |
| 4283 |
gen_test!(test_div_001_010, "Div_001_010.csv", checked_div); |
| 4284 |
gen_test!(test_div_001_011, "Div_001_011.csv", checked_div); |
| 4285 |
gen_test!(test_div_001_100, "Div_001_100.csv", checked_div); |
| 4286 |
gen_test!(test_div_001_101, "Div_001_101.csv", checked_div); |
| 4287 |
gen_test!(test_div_001_110, "Div_001_110.csv", checked_div); |
| 4288 |
gen_test!(test_div_001_111, "Div_001_111.csv", checked_div); |
| 4289 |
gen_test!(test_div_010_000, "Div_010_000.csv", checked_div); |
| 4290 |
gen_test!(test_div_010_001, "Div_010_001.csv", checked_div); |
| 4291 |
gen_test!(test_div_010_010, "Div_010_010.csv", checked_div); |
| 4292 |
gen_test!(test_div_010_011, "Div_010_011.csv", checked_div); |
| 4293 |
gen_test!(test_div_010_100, "Div_010_100.csv", checked_div); |
| 4294 |
gen_test!(test_div_010_101, "Div_010_101.csv", checked_div); |
| 4295 |
gen_test!(test_div_010_110, "Div_010_110.csv", checked_div); |
| 4296 |
gen_test!(test_div_010_111, "Div_010_111.csv", checked_div); |
| 4297 |
gen_test!(test_div_011_000, "Div_011_000.csv", checked_div); |
| 4298 |
gen_test!(test_div_011_001, "Div_011_001.csv", checked_div); |
| 4299 |
gen_test!(test_div_011_010, "Div_011_010.csv", checked_div); |
| 4300 |
gen_test!(test_div_011_011, "Div_011_011.csv", checked_div); |
| 4301 |
gen_test!(test_div_011_100, "Div_011_100.csv", checked_div); |
| 4302 |
gen_test!(test_div_011_101, "Div_011_101.csv", checked_div); |
| 4303 |
gen_test!(test_div_011_110, "Div_011_110.csv", checked_div); |
| 4304 |
gen_test!(test_div_011_111, "Div_011_111.csv", checked_div); |
| 4305 |
gen_test!(test_div_100_000, "Div_100_000.csv", checked_div); |
| 4306 |
gen_test!(test_div_100_001, "Div_100_001.csv", checked_div); |
| 4307 |
gen_test!(test_div_100_010, "Div_100_010.csv", checked_div); |
| 4308 |
gen_test!(test_div_100_011, "Div_100_011.csv", checked_div); |
| 4309 |
gen_test!(test_div_100_100, "Div_100_100.csv", checked_div); |
| 4310 |
gen_test!(test_div_100_101, "Div_100_101.csv", checked_div); |
| 4311 |
gen_test!(test_div_100_110, "Div_100_110.csv", checked_div); |
| 4312 |
gen_test!(test_div_100_111, "Div_100_111.csv", checked_div); |
| 4313 |
gen_test!(test_div_101_000, "Div_101_000.csv", checked_div); |
| 4314 |
gen_test!(test_div_101_001, "Div_101_001.csv", checked_div); |
| 4315 |
gen_test!(test_div_101_010, "Div_101_010.csv", checked_div); |
| 4316 |
gen_test!(test_div_101_011, "Div_101_011.csv", checked_div); |
| 4317 |
gen_test!(test_div_101_100, "Div_101_100.csv", checked_div); |
| 4318 |
gen_test!(test_div_101_101, "Div_101_101.csv", checked_div); |
| 4319 |
gen_test!(test_div_101_110, "Div_101_110.csv", checked_div); |
| 4320 |
gen_test!(test_div_101_111, "Div_101_111.csv", checked_div); |
| 4321 |
gen_test!(test_div_110_000, "Div_110_000.csv", checked_div); |
| 4322 |
gen_test!(test_div_110_001, "Div_110_001.csv", checked_div); |
| 4323 |
gen_test!(test_div_110_010, "Div_110_010.csv", checked_div); |
| 4324 |
gen_test!(test_div_110_011, "Div_110_011.csv", checked_div); |
| 4325 |
gen_test!(test_div_110_100, "Div_110_100.csv", checked_div); |
| 4326 |
gen_test!(test_div_110_101, "Div_110_101.csv", checked_div); |
| 4327 |
gen_test!(test_div_110_110, "Div_110_110.csv", checked_div); |
| 4328 |
gen_test!(test_div_110_111, "Div_110_111.csv", checked_div); |
| 4329 |
gen_test!(test_div_111_000, "Div_111_000.csv", checked_div); |
| 4330 |
gen_test!(test_div_111_001, "Div_111_001.csv", checked_div); |
| 4331 |
gen_test!(test_div_111_010, "Div_111_010.csv", checked_div); |
| 4332 |
gen_test!(test_div_111_011, "Div_111_011.csv", checked_div); |
| 4333 |
gen_test!(test_div_111_100, "Div_111_100.csv", checked_div); |
| 4334 |
gen_test!(test_div_111_101, "Div_111_101.csv", checked_div); |
| 4335 |
gen_test!(test_div_111_110, "Div_111_110.csv", checked_div); |
| 4336 |
gen_test!(test_div_111_111, "Div_111_111.csv", checked_div); |
| 4337 |
|
| 4338 |
gen_test!(test_mul_000_001, "Mul_000_001.csv", checked_mul); |
| 4339 |
gen_test!(test_mul_000_010, "Mul_000_010.csv", checked_mul); |
| 4340 |
gen_test!(test_mul_000_011, "Mul_000_011.csv", checked_mul); |
| 4341 |
gen_test!(test_mul_000_100, "Mul_000_100.csv", checked_mul); |
| 4342 |
gen_test!(test_mul_000_101, "Mul_000_101.csv", checked_mul); |
| 4343 |
gen_test!(test_mul_000_110, "Mul_000_110.csv", checked_mul); |
| 4344 |
gen_test!(test_mul_000_111, "Mul_000_111.csv", checked_mul); |
| 4345 |
gen_test!(test_mul_001_000, "Mul_001_000.csv", checked_mul); |
| 4346 |
gen_test!(test_mul_001_001, "Mul_001_001.csv", checked_mul); |
| 4347 |
gen_test!(test_mul_001_010, "Mul_001_010.csv", checked_mul); |
| 4348 |
gen_test!(test_mul_001_011, "Mul_001_011.csv", checked_mul); |
| 4349 |
gen_test!(test_mul_001_100, "Mul_001_100.csv", checked_mul); |
| 4350 |
gen_test!(test_mul_001_101, "Mul_001_101.csv", checked_mul); |
| 4351 |
gen_test!(test_mul_001_110, "Mul_001_110.csv", checked_mul); |
| 4352 |
gen_test!(test_mul_001_111, "Mul_001_111.csv", checked_mul); |
| 4353 |
gen_test!(test_mul_010_000, "Mul_010_000.csv", checked_mul); |
| 4354 |
gen_test!(test_mul_010_001, "Mul_010_001.csv", checked_mul); |
| 4355 |
gen_test!(test_mul_010_010, "Mul_010_010.csv", checked_mul); |
| 4356 |
gen_test!(test_mul_010_011, "Mul_010_011.csv", checked_mul); |
| 4357 |
gen_test!(test_mul_010_100, "Mul_010_100.csv", checked_mul); |
| 4358 |
gen_test!(test_mul_010_101, "Mul_010_101.csv", checked_mul); |
| 4359 |
gen_test!(test_mul_010_110, "Mul_010_110.csv", checked_mul); |
| 4360 |
gen_test!(test_mul_010_111, "Mul_010_111.csv", checked_mul); |
| 4361 |
gen_test!(test_mul_011_000, "Mul_011_000.csv", checked_mul); |
| 4362 |
gen_test!(test_mul_011_001, "Mul_011_001.csv", checked_mul); |
| 4363 |
gen_test!(test_mul_011_010, "Mul_011_010.csv", checked_mul); |
| 4364 |
gen_test!(test_mul_011_011, "Mul_011_011.csv", checked_mul); |
| 4365 |
gen_test!(test_mul_011_100, "Mul_011_100.csv", checked_mul); |
| 4366 |
gen_test!(test_mul_011_101, "Mul_011_101.csv", checked_mul); |
| 4367 |
gen_test!(test_mul_011_110, "Mul_011_110.csv", checked_mul); |
| 4368 |
gen_test!(test_mul_011_111, "Mul_011_111.csv", checked_mul); |
| 4369 |
gen_test!(test_mul_100_000, "Mul_100_000.csv", checked_mul); |
| 4370 |
gen_test!(test_mul_100_001, "Mul_100_001.csv", checked_mul); |
| 4371 |
gen_test!(test_mul_100_010, "Mul_100_010.csv", checked_mul); |
| 4372 |
gen_test!(test_mul_100_011, "Mul_100_011.csv", checked_mul); |
| 4373 |
gen_test!(test_mul_100_100, "Mul_100_100.csv", checked_mul); |
| 4374 |
gen_test!(test_mul_100_101, "Mul_100_101.csv", checked_mul); |
| 4375 |
gen_test!(test_mul_100_110, "Mul_100_110.csv", checked_mul); |
| 4376 |
gen_test!(test_mul_100_111, "Mul_100_111.csv", checked_mul); |
| 4377 |
gen_test!(test_mul_101_000, "Mul_101_000.csv", checked_mul); |
| 4378 |
gen_test!(test_mul_101_001, "Mul_101_001.csv", checked_mul); |
| 4379 |
gen_test!(test_mul_101_010, "Mul_101_010.csv", checked_mul); |
| 4380 |
gen_test!(test_mul_101_011, "Mul_101_011.csv", checked_mul); |
| 4381 |
gen_test!(test_mul_101_100, "Mul_101_100.csv", checked_mul); |
| 4382 |
gen_test!(test_mul_101_101, "Mul_101_101.csv", checked_mul); |
| 4383 |
gen_test!(test_mul_101_110, "Mul_101_110.csv", checked_mul); |
| 4384 |
gen_test!(test_mul_101_111, "Mul_101_111.csv", checked_mul); |
| 4385 |
gen_test!(test_mul_110_000, "Mul_110_000.csv", checked_mul); |
| 4386 |
gen_test!(test_mul_110_001, "Mul_110_001.csv", checked_mul); |
| 4387 |
gen_test!(test_mul_110_010, "Mul_110_010.csv", checked_mul); |
| 4388 |
gen_test!(test_mul_110_011, "Mul_110_011.csv", checked_mul); |
| 4389 |
gen_test!(test_mul_110_100, "Mul_110_100.csv", checked_mul); |
| 4390 |
gen_test!(test_mul_110_101, "Mul_110_101.csv", checked_mul); |
| 4391 |
gen_test!(test_mul_110_110, "Mul_110_110.csv", checked_mul); |
| 4392 |
gen_test!(test_mul_110_111, "Mul_110_111.csv", checked_mul); |
| 4393 |
gen_test!(test_mul_111_000, "Mul_111_000.csv", checked_mul); |
| 4394 |
gen_test!(test_mul_111_001, "Mul_111_001.csv", checked_mul); |
| 4395 |
gen_test!(test_mul_111_010, "Mul_111_010.csv", checked_mul); |
| 4396 |
gen_test!(test_mul_111_011, "Mul_111_011.csv", checked_mul); |
| 4397 |
gen_test!(test_mul_111_100, "Mul_111_100.csv", checked_mul); |
| 4398 |
gen_test!(test_mul_111_101, "Mul_111_101.csv", checked_mul); |
| 4399 |
gen_test!(test_mul_111_110, "Mul_111_110.csv", checked_mul); |
| 4400 |
gen_test!(test_mul_111_111, "Mul_111_111.csv", checked_mul); |
| 4401 |
|
| 4402 |
gen_test!(test_rem_000_001, "Rem_000_001.csv", checked_rem); |
| 4403 |
gen_test!(test_rem_000_010, "Rem_000_010.csv", checked_rem); |
| 4404 |
gen_test!(test_rem_000_011, "Rem_000_011.csv", checked_rem); |
| 4405 |
gen_test!(test_rem_000_100, "Rem_000_100.csv", checked_rem); |
| 4406 |
gen_test!(test_rem_000_101, "Rem_000_101.csv", checked_rem); |
| 4407 |
gen_test!(test_rem_000_110, "Rem_000_110.csv", checked_rem); |
| 4408 |
gen_test!(test_rem_000_111, "Rem_000_111.csv", checked_rem); |
| 4409 |
gen_test!(test_rem_001_000, "Rem_001_000.csv", checked_rem); |
| 4410 |
gen_test!(test_rem_001_001, "Rem_001_001.csv", checked_rem); |
| 4411 |
gen_test!(test_rem_001_010, "Rem_001_010.csv", checked_rem); |
| 4412 |
gen_test!(test_rem_001_011, "Rem_001_011.csv", checked_rem); |
| 4413 |
gen_test!(test_rem_001_100, "Rem_001_100.csv", checked_rem); |
| 4414 |
gen_test!(test_rem_001_101, "Rem_001_101.csv", checked_rem); |
| 4415 |
gen_test!(test_rem_001_110, "Rem_001_110.csv", checked_rem); |
| 4416 |
gen_test!(test_rem_001_111, "Rem_001_111.csv", checked_rem); |
| 4417 |
gen_test!(test_rem_010_000, "Rem_010_000.csv", checked_rem); |
| 4418 |
gen_test!(test_rem_010_001, "Rem_010_001.csv", checked_rem); |
| 4419 |
gen_test!(test_rem_010_010, "Rem_010_010.csv", checked_rem); |
| 4420 |
gen_test!(test_rem_010_011, "Rem_010_011.csv", checked_rem); |
| 4421 |
gen_test!(test_rem_010_100, "Rem_010_100.csv", checked_rem); |
| 4422 |
gen_test!(test_rem_010_101, "Rem_010_101.csv", checked_rem); |
| 4423 |
gen_test!(test_rem_010_110, "Rem_010_110.csv", checked_rem); |
| 4424 |
gen_test!(test_rem_010_111, "Rem_010_111.csv", checked_rem); |
| 4425 |
gen_test!(test_rem_011_000, "Rem_011_000.csv", checked_rem); |
| 4426 |
gen_test!(test_rem_011_001, "Rem_011_001.csv", checked_rem); |
| 4427 |
gen_test!(test_rem_011_010, "Rem_011_010.csv", checked_rem); |
| 4428 |
gen_test!(test_rem_011_011, "Rem_011_011.csv", checked_rem); |
| 4429 |
gen_test!(test_rem_011_100, "Rem_011_100.csv", checked_rem); |
| 4430 |
gen_test!(test_rem_011_101, "Rem_011_101.csv", checked_rem); |
| 4431 |
gen_test!(test_rem_011_110, "Rem_011_110.csv", checked_rem); |
| 4432 |
gen_test!(test_rem_011_111, "Rem_011_111.csv", checked_rem); |
| 4433 |
gen_test!(test_rem_100_000, "Rem_100_000.csv", checked_rem); |
| 4434 |
gen_test!(test_rem_100_001, "Rem_100_001.csv", checked_rem); |
| 4435 |
gen_test!(test_rem_100_010, "Rem_100_010.csv", checked_rem); |
| 4436 |
gen_test!(test_rem_100_011, "Rem_100_011.csv", checked_rem); |
| 4437 |
gen_test!(test_rem_100_100, "Rem_100_100.csv", checked_rem); |
| 4438 |
gen_test!(test_rem_100_101, "Rem_100_101.csv", checked_rem); |
| 4439 |
gen_test!(test_rem_100_110, "Rem_100_110.csv", checked_rem); |
| 4440 |
gen_test!(test_rem_100_111, "Rem_100_111.csv", checked_rem); |
| 4441 |
gen_test!(test_rem_101_000, "Rem_101_000.csv", checked_rem); |
| 4442 |
gen_test!(test_rem_101_001, "Rem_101_001.csv", checked_rem); |
| 4443 |
gen_test!(test_rem_101_010, "Rem_101_010.csv", checked_rem); |
| 4444 |
gen_test!(test_rem_101_011, "Rem_101_011.csv", checked_rem); |
| 4445 |
gen_test!(test_rem_101_100, "Rem_101_100.csv", checked_rem); |
| 4446 |
gen_test!(test_rem_101_101, "Rem_101_101.csv", checked_rem); |
| 4447 |
gen_test!(test_rem_101_110, "Rem_101_110.csv", checked_rem); |
| 4448 |
gen_test!(test_rem_101_111, "Rem_101_111.csv", checked_rem); |
| 4449 |
gen_test!(test_rem_110_000, "Rem_110_000.csv", checked_rem); |
| 4450 |
gen_test!(test_rem_110_001, "Rem_110_001.csv", checked_rem); |
| 4451 |
gen_test!(test_rem_110_010, "Rem_110_010.csv", checked_rem); |
| 4452 |
gen_test!(test_rem_110_011, "Rem_110_011.csv", checked_rem); |
| 4453 |
gen_test!(test_rem_110_100, "Rem_110_100.csv", checked_rem); |
| 4454 |
gen_test!(test_rem_110_101, "Rem_110_101.csv", checked_rem); |
| 4455 |
gen_test!(test_rem_110_110, "Rem_110_110.csv", checked_rem); |
| 4456 |
gen_test!(test_rem_110_111, "Rem_110_111.csv", checked_rem); |
| 4457 |
gen_test!(test_rem_111_000, "Rem_111_000.csv", checked_rem); |
| 4458 |
gen_test!(test_rem_111_001, "Rem_111_001.csv", checked_rem); |
| 4459 |
gen_test!(test_rem_111_010, "Rem_111_010.csv", checked_rem); |
| 4460 |
gen_test!(test_rem_111_011, "Rem_111_011.csv", checked_rem); |
| 4461 |
gen_test!(test_rem_111_100, "Rem_111_100.csv", checked_rem); |
| 4462 |
gen_test!(test_rem_111_101, "Rem_111_101.csv", checked_rem); |
| 4463 |
gen_test!(test_rem_111_110, "Rem_111_110.csv", checked_rem); |
| 4464 |
gen_test!(test_rem_111_111, "Rem_111_111.csv", checked_rem); |
| 4465 |
|
| 4466 |
gen_test!(test_sub_000_001, "Sub_000_001.csv", checked_sub); |
| 4467 |
gen_test!(test_sub_000_010, "Sub_000_010.csv", checked_sub); |
| 4468 |
gen_test!(test_sub_000_011, "Sub_000_011.csv", checked_sub); |
| 4469 |
gen_test!(test_sub_000_100, "Sub_000_100.csv", checked_sub); |
| 4470 |
gen_test!(test_sub_000_101, "Sub_000_101.csv", checked_sub); |
| 4471 |
gen_test!(test_sub_000_110, "Sub_000_110.csv", checked_sub); |
| 4472 |
gen_test!(test_sub_000_111, "Sub_000_111.csv", checked_sub); |
| 4473 |
gen_test!(test_sub_001_000, "Sub_001_000.csv", checked_sub); |
| 4474 |
gen_test!(test_sub_001_001, "Sub_001_001.csv", checked_sub); |
| 4475 |
gen_test!(test_sub_001_010, "Sub_001_010.csv", checked_sub); |
| 4476 |
gen_test!(test_sub_001_011, "Sub_001_011.csv", checked_sub); |
| 4477 |
gen_test!(test_sub_001_100, "Sub_001_100.csv", checked_sub); |
| 4478 |
gen_test!(test_sub_001_101, "Sub_001_101.csv", checked_sub); |
| 4479 |
gen_test!(test_sub_001_110, "Sub_001_110.csv", checked_sub); |
| 4480 |
gen_test!(test_sub_001_111, "Sub_001_111.csv", checked_sub); |
| 4481 |
gen_test!(test_sub_010_000, "Sub_010_000.csv", checked_sub); |
| 4482 |
gen_test!(test_sub_010_001, "Sub_010_001.csv", checked_sub); |
| 4483 |
gen_test!(test_sub_010_010, "Sub_010_010.csv", checked_sub); |
| 4484 |
gen_test!(test_sub_010_011, "Sub_010_011.csv", checked_sub); |
| 4485 |
gen_test!(test_sub_010_100, "Sub_010_100.csv", checked_sub); |
| 4486 |
gen_test!(test_sub_010_101, "Sub_010_101.csv", checked_sub); |
| 4487 |
gen_test!(test_sub_010_110, "Sub_010_110.csv", checked_sub); |
| 4488 |
gen_test!(test_sub_010_111, "Sub_010_111.csv", checked_sub); |
| 4489 |
gen_test!(test_sub_011_000, "Sub_011_000.csv", checked_sub); |
| 4490 |
gen_test!(test_sub_011_001, "Sub_011_001.csv", checked_sub); |
| 4491 |
gen_test!(test_sub_011_010, "Sub_011_010.csv", checked_sub); |
| 4492 |
gen_test!(test_sub_011_011, "Sub_011_011.csv", checked_sub); |
| 4493 |
gen_test!(test_sub_011_100, "Sub_011_100.csv", checked_sub); |
| 4494 |
gen_test!(test_sub_011_101, "Sub_011_101.csv", checked_sub); |
| 4495 |
gen_test!(test_sub_011_110, "Sub_011_110.csv", checked_sub); |
| 4496 |
gen_test!(test_sub_011_111, "Sub_011_111.csv", checked_sub); |
| 4497 |
gen_test!(test_sub_100_000, "Sub_100_000.csv", checked_sub); |
| 4498 |
gen_test!(test_sub_100_001, "Sub_100_001.csv", checked_sub); |
| 4499 |
gen_test!(test_sub_100_010, "Sub_100_010.csv", checked_sub); |
| 4500 |
gen_test!(test_sub_100_011, "Sub_100_011.csv", checked_sub); |
| 4501 |
gen_test!(test_sub_100_100, "Sub_100_100.csv", checked_sub); |
| 4502 |
gen_test!(test_sub_100_101, "Sub_100_101.csv", checked_sub); |
| 4503 |
gen_test!(test_sub_100_110, "Sub_100_110.csv", checked_sub); |
| 4504 |
gen_test!(test_sub_100_111, "Sub_100_111.csv", checked_sub); |
| 4505 |
gen_test!(test_sub_101_000, "Sub_101_000.csv", checked_sub); |
| 4506 |
gen_test!(test_sub_101_001, "Sub_101_001.csv", checked_sub); |
| 4507 |
gen_test!(test_sub_101_010, "Sub_101_010.csv", checked_sub); |
| 4508 |
gen_test!(test_sub_101_011, "Sub_101_011.csv", checked_sub); |
| 4509 |
gen_test!(test_sub_101_100, "Sub_101_100.csv", checked_sub); |
| 4510 |
gen_test!(test_sub_101_101, "Sub_101_101.csv", checked_sub); |
| 4511 |
gen_test!(test_sub_101_110, "Sub_101_110.csv", checked_sub); |
| 4512 |
gen_test!(test_sub_101_111, "Sub_101_111.csv", checked_sub); |
| 4513 |
gen_test!(test_sub_110_000, "Sub_110_000.csv", checked_sub); |
| 4514 |
gen_test!(test_sub_110_001, "Sub_110_001.csv", checked_sub); |
| 4515 |
gen_test!(test_sub_110_010, "Sub_110_010.csv", checked_sub); |
| 4516 |
gen_test!(test_sub_110_011, "Sub_110_011.csv", checked_sub); |
| 4517 |
gen_test!(test_sub_110_100, "Sub_110_100.csv", checked_sub); |
| 4518 |
gen_test!(test_sub_110_101, "Sub_110_101.csv", checked_sub); |
| 4519 |
gen_test!(test_sub_110_110, "Sub_110_110.csv", checked_sub); |
| 4520 |
gen_test!(test_sub_110_111, "Sub_110_111.csv", checked_sub); |
| 4521 |
gen_test!(test_sub_111_000, "Sub_111_000.csv", checked_sub); |
| 4522 |
gen_test!(test_sub_111_001, "Sub_111_001.csv", checked_sub); |
| 4523 |
gen_test!(test_sub_111_010, "Sub_111_010.csv", checked_sub); |
| 4524 |
gen_test!(test_sub_111_011, "Sub_111_011.csv", checked_sub); |
| 4525 |
gen_test!(test_sub_111_100, "Sub_111_100.csv", checked_sub); |
| 4526 |
gen_test!(test_sub_111_101, "Sub_111_101.csv", checked_sub); |
| 4527 |
gen_test!(test_sub_111_110, "Sub_111_110.csv", checked_sub); |
| 4528 |
gen_test!(test_sub_111_111, "Sub_111_111.csv", checked_sub); |
| 4529 |
} |
| 4530 |
|
| 4531 |
#[cfg(feature = "rocket-traits")] |
| 4532 |
mod rocket { |
| 4533 |
use crate::Decimal; |
| 4534 |
use rocket::form::{Form, FromForm}; |
| 4535 |
use std::str::FromStr; |
| 4536 |
|
| 4537 |
#[derive(FromForm)] |
| 4538 |
struct Example { |
| 4539 |
foo: Decimal, |
| 4540 |
bar: Decimal, |
| 4541 |
} |
| 4542 |
|
| 4543 |
#[test] |
| 4544 |
fn it_can_parse_form() { |
| 4545 |
let parsed: Example = Form::parse("bar=0.12345678901234567890123456789&foo=-123456.78").unwrap(); |
| 4546 |
assert_eq!(parsed.foo, Decimal::from_str("-123456.78").unwrap()); |
| 4547 |
assert_eq!( |
| 4548 |
parsed.bar, |
| 4549 |
Decimal::from_str("0.12345678901234567890123456789").unwrap() |
| 4550 |
); |
| 4551 |
} |
| 4552 |
} |
| 4553 |
|
| 4554 |
#[cfg(feature = "rust-fuzz")] |
| 4555 |
mod rust_fuzz { |
| 4556 |
use arbitrary::{Arbitrary, Unstructured}; |
| 4557 |
|
| 4558 |
use super::*; |
| 4559 |
|
| 4560 |
#[test] |
| 4561 |
fn it_can_generate_arbitrary_decimals() { |
| 4562 |
let mut u = Unstructured::new(b"it_can_generate_arbitrary_decimals"); |
| 4563 |
let d = Decimal::arbitrary(&mut u); |
| 4564 |
assert!(d.is_ok()); |
| 4565 |
} |
| 4566 |
} |
| 4567 |
|
| 4568 |
mod issues { |
| 4569 |
use rust_decimal::prelude::*; |
| 4570 |
|
| 4571 |
#[test] |
| 4572 |
fn issue_384_neg_overflow_during_subtract_carry() { |
| 4573 |
// 288230376151711744 |
| 4574 |
let a = Decimal::from_parts(0, 67108864, 0, false, 0); |
| 4575 |
// 714606955844629274884780.85120 |
| 4576 |
let b = Decimal::from_parts(0, 0, 3873892070, false, 3873892070); |
| 4577 |
let c = a.checked_sub(b); |
| 4578 |
assert!(c.is_some()); |
| 4579 |
|
| 4580 |
// 288230376151711744. |
| 4581 |
// - 714606955844629274884780.85120 |
| 4582 |
// = |
| 4583 |
// - 714606667614253123173036.85120 |
| 4584 |
assert_eq!("-714606667614253123173036.85120", c.unwrap().to_string()); |
| 4585 |
} |
| 4586 |
|
| 4587 |
#[test] |
| 4588 |
fn issue_392_overflow_during_remainder() { |
| 4589 |
let a = Decimal::from_str("-79228157791897.854723898738431").unwrap(); |
| 4590 |
let b = Decimal::from_str("184512476.73336922111").unwrap(); |
| 4591 |
let c = a.checked_div(b); |
| 4592 |
assert!(c.is_some()); |
| 4593 |
assert_eq!("-429391.87200000000002327170816", c.unwrap().to_string()) |
| 4594 |
} |
| 4595 |
} |