team-ljyzipelo

공개
18줄637 바이트
1use super::*;
2
3#[test]
4fn ratio_boundaries_do_not_overflow() {
5 assert!(ratio(0, 0).is_ok());
6 assert_eq!(ratio(1, 0), Err(ErrorCode::Limit));
7 for compressed in [1, 17, 65536, 16 * 1024 * 1024] {
8 assert!(ratio(compressed * 1000, compressed).is_ok());
9 assert_eq!(
10 ratio(compressed * 1000 + 1, compressed),
11 Err(ErrorCode::Limit)
12 );
13 }
14 assert!(ratio(u64::MAX, u64::MAX).is_ok());
15 assert!(ratio(u64::MAX, u64::MAX / 1000 + 1).is_ok());
16 assert_eq!(ratio(u64::MAX, u64::MAX / 1000), Err(ErrorCode::Limit));
17 assert_eq!(add(u64::MAX, 1), Err(ErrorCode::Integrity));
18}