36 lines
718 B
Rust
36 lines
718 B
Rust
use super::{Budget, Limits};
|
|
|
|
const L: Limits = Limits {
|
|
pages: 10,
|
|
endpoints: 2,
|
|
notifications: 2,
|
|
regions: 1,
|
|
};
|
|
|
|
#[test]
|
|
fn a_carve_takes_all_parts_or_none() {
|
|
let mut b = Budget::new(L);
|
|
b.endpoints.charge(2);
|
|
let child = Limits {
|
|
pages: 1,
|
|
endpoints: 1,
|
|
..Limits::default()
|
|
};
|
|
assert!(!b.carve(child));
|
|
assert_eq!(b.limits(), L);
|
|
assert!(b.carve(Limits {
|
|
endpoints: 0,
|
|
..child
|
|
}));
|
|
assert_eq!(b.limits().pages, 9);
|
|
}
|
|
|
|
#[test]
|
|
fn a_refund_restores_what_was_carved() {
|
|
let mut b = Budget::new(L);
|
|
assert!(b.carve(L));
|
|
assert_eq!(b.limits(), Limits::default());
|
|
b.refund(L);
|
|
assert_eq!(b.limits(), L);
|
|
}
|