Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
sffc committed Jul 6, 2023
1 parent 0b53868 commit d05dd46
Showing 1 changed file with 33 additions and 7 deletions.
40 changes: 33 additions & 7 deletions utils/fixed_decimal/tests/rounding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,44 +178,70 @@ pub fn test_within_ranges() {
assert_eq!(fd.write_to_string(), "-2000", "{rounding_mode}: {n}");
let mut fd = FixedDecimal::from(n - 1000000).multiplied_pow10(-5);
f(&mut fd, -2);
assert_eq!(fd.write_to_string(), "-10.02", "{rounding_mode}: {n} ÷ 10^5 ± 10");
assert_eq!(
fd.write_to_string(),
"-10.02",
"{rounding_mode}: {n} ÷ 10^5 ± 10"
);
}
for n in range_n1000 {
let mut fd = FixedDecimal::from(n);
f(&mut fd, 3);
assert_eq!(fd.write_to_string(), "-1000", "{rounding_mode}: {n}");
let mut fd = FixedDecimal::from(n - 1000000).multiplied_pow10(-5);
f(&mut fd, -2);
assert_eq!(fd.write_to_string(), "-10.01", "{rounding_mode}: {n} ÷ 10^5 ± 10");
assert_eq!(
fd.write_to_string(),
"-10.01",
"{rounding_mode}: {n} ÷ 10^5 ± 10"
);
}
for n in range_0 {
let mut fd = FixedDecimal::from(n);
f(&mut fd, 3);
fd.set_sign(Sign::None); // get rid of -0
assert_eq!(fd.write_to_string(), "000", "{rounding_mode}: {n}");
let (mut fd, expected) = if n < 0 {
(FixedDecimal::from(n - 1000000).multiplied_pow10(-5), "-10.00")
(
FixedDecimal::from(n - 1000000).multiplied_pow10(-5),
"-10.00",
)
} else {
(FixedDecimal::from(n + 1000000).multiplied_pow10(-5), "10.00")
(
FixedDecimal::from(n + 1000000).multiplied_pow10(-5),
"10.00",
)
};
f(&mut fd, -2);
assert_eq!(fd.write_to_string(), expected, "{rounding_mode}: {n} ÷ 10^5 ± 10");
assert_eq!(
fd.write_to_string(),
expected,
"{rounding_mode}: {n} ÷ 10^5 ± 10"
);
}
for n in range_1000 {
let mut fd = FixedDecimal::from(n);
f(&mut fd, 3);
assert_eq!(fd.write_to_string(), "1000", "{rounding_mode}: {n}");
let mut fd = FixedDecimal::from(n + 1000000).multiplied_pow10(-5);
f(&mut fd, -2);
assert_eq!(fd.write_to_string(), "10.01", "{rounding_mode}: {n} ÷ 10^5 ± 10");
assert_eq!(
fd.write_to_string(),
"10.01",
"{rounding_mode}: {n} ÷ 10^5 ± 10"
);
}
for n in range_2000 {
let mut fd = FixedDecimal::from(n);
f(&mut fd, 3);
assert_eq!(fd.write_to_string(), "2000", "{rounding_mode}: {n}");
let mut fd = FixedDecimal::from(n + 1000000).multiplied_pow10(-5);
f(&mut fd, -2);
assert_eq!(fd.write_to_string(), "10.02", "{rounding_mode}: {n} ÷ 10^5 ± 10");
assert_eq!(
fd.write_to_string(),
"10.02",
"{rounding_mode}: {n} ÷ 10^5 ± 10"
);
}
}
}

0 comments on commit d05dd46

Please sign in to comment.