assert_eq!(Sat(2067187500000000).cycle(), 1); assert_eq!(Sat(2067187500000000 + 1).cycle(), 1); } #[test] fn third() { assert_eq!(Sat(0).third(), 0); assert_eq!(Sat(50 * COIN_VALUE - 1).third(), 4999999999); assert_eq!(Sat(50 * COIN_VALUE).third(), 0); assert_eq!(Sat(50 * COIN_VALUE + 1).third(), 1); } #[test] fn percentile() { assert_eq!(Sat(0).percentile(), "0%"); assert_eq!(Sat(Sat::LAST.n() / 2).percentile(), "49.99999999999998%"); assert_eq!(Sat::LAST.percentile(), "100%"); } #[test] fn from_percentile() { "-1%".parse::().unwrap_err(); "101%".parse::().unwrap_err(); } #[test] fn percentile_round_trip() { #[track_caller] fn case(n: u64) { let expected = Sat(n); let actual = expected.percentile().parse::().unwrap(); assert_eq!(expected, actual); } for n in 0..1024 { case(n); case(Sat::LAST.n() / 2 + n); case(Sat::LAST.n() - n); case(Sat::LAST.n() / (n + 1)); }