Nothing to see here, move along meow
0

Configure Feed

Select the types of activity you want to include in your feed.

at main 2.3 kB View raw
1use lancer_core::sched_budget::SchedBudget; 2use proptest::prelude::*; 3 4#[test] 5fn new_has_full_remaining() { 6 let b = SchedBudget::new(1000, 5000); 7 assert_eq!(b.remaining_us, 1000); 8 assert_eq!(b.budget_us, 1000); 9 assert_eq!(b.period_us, 5000); 10 assert!(b.replenish_at.is_none()); 11} 12 13#[test] 14fn consume_decrements() { 15 let mut b = SchedBudget::new(1000, 5000); 16 b.consume(300, 100); 17 assert_eq!(b.remaining_us, 700); 18 assert!(b.replenish_at.is_none()); 19} 20 21#[test] 22fn consume_saturates_at_zero() { 23 let mut b = SchedBudget::new(100, 5000); 24 b.consume(200, 50); 25 assert_eq!(b.remaining_us, 0); 26} 27 28#[test] 29fn is_exhausted_when_zero() { 30 let mut b = SchedBudget::new(100, 5000); 31 b.consume(100, 50); 32 assert!(b.is_exhausted()); 33} 34 35#[test] 36fn is_exhausted_false_when_nonzero() { 37 let b = SchedBudget::new(100, 5000); 38 assert!(!b.is_exhausted()); 39} 40 41#[test] 42fn consume_to_zero_sets_replenish_at() { 43 let mut b = SchedBudget::new(100, 5000); 44 b.consume(100, 1000); 45 assert_eq!(b.replenish_at, Some(1000 + 5000)); 46} 47 48#[test] 49fn replenish_refills() { 50 let mut b = SchedBudget::new(100, 5000); 51 b.consume(100, 1000); 52 assert!(b.is_exhausted()); 53 b.replenish(6000); 54 assert_eq!(b.remaining_us, 100); 55 assert!(!b.is_exhausted()); 56} 57 58#[test] 59fn replenish_before_time_noop() { 60 let mut b = SchedBudget::new(100, 5000); 61 b.consume(100, 1000); 62 b.replenish(5999); 63 assert!(b.is_exhausted()); 64 assert_eq!(b.remaining_us, 0); 65} 66 67#[test] 68fn replenish_none_noop() { 69 let mut b = SchedBudget::new(100, 5000); 70 b.consume(50, 1000); 71 b.replenish(999_999); 72 assert_eq!(b.remaining_us, 50); 73} 74 75proptest! { 76 #[test] 77 fn consume_then_replenish_cycle( 78 budget in 1u64..10000, 79 period in 1u64..100000, 80 elapsed in 0u64..20000, 81 ) { 82 let mut b = SchedBudget::new(budget, period); 83 let now = 1000u64; 84 b.consume(elapsed, now); 85 86 if b.is_exhausted() { 87 let replenish_time = b.replenish_at.unwrap(); 88 b.replenish(replenish_time); 89 prop_assert_eq!(b.remaining_us, budget); 90 prop_assert!(!b.is_exhausted()); 91 } else { 92 prop_assert_eq!(b.remaining_us, budget.saturating_sub(elapsed)); 93 } 94 } 95}