use rust_decimal_macros::dec;
use crate::{Kwh, Money};
#[test]
fn should_round_rather_than_truncate() {
assert_eq!(Money::from(dec!(0.50019)).to_string(), "0.5002¤");
assert_eq!(Money::from(dec!(0.20839)).to_string(), "0.2084¤");
assert_eq!(Kwh::from(dec!(0.00018)).to_string(), "0.0002kWh");
}
#[test]
fn should_print_a_tie_rounded_to_the_even_digit() {
assert_eq!(Money::from(dec!(0.50015)).to_string(), "0.5002¤");
assert_eq!(Money::from(dec!(0.25005)).to_string(), "0.2500¤");
assert_eq!(Kwh::from(dec!(0.00015)).to_string(), "0.0002kWh");
assert_eq!(Kwh::from(dec!(0.00025)).to_string(), "0.0002kWh");
}
#[test]
fn should_print_a_negative_tie_rounded_to_the_even_digit() {
assert_eq!(Money::from(dec!(-0.50015)).to_string(), "-0.5002¤");
assert_eq!(Money::from(dec!(-0.25005)).to_string(), "-0.2500¤");
}
#[test]
fn should_round_the_alternate_form_the_same_way() {
assert_eq!(format!("{:#}", Money::from(dec!(0.50015))), "0.5002");
assert_eq!(format!("{:#}", Money::from(dec!(0.25005))), "0.2500");
}
#[test]
fn should_not_print_a_tiny_rate_as_a_bare_zero() {
assert_eq!(Money::from(dec!(0.00004)).to_string(), "0.0000¤");
assert_eq!(Kwh::from(dec!(0.00001)).to_string(), "0.0000kWh");
}
#[test]
fn should_print_an_exact_zero_without_decimals() {
assert_eq!(Money::from(dec!(0)).to_string(), "0¤");
assert_eq!(format!("{:#}", Money::from(dec!(0))), "0");
}