def bonus_energy(): energy = Energy(10, 300) with time_traveler() as T: T(0) energy.set(15) T(1) assert energy == 15 T(2) energy.use() T(3) assert energy.recover_in() is None T(4) energy.use() T(5) assert energy.recover_in() is None T(6) energy.use(5) T(7) assert energy.recover_in() == 299 T(8) assert energy.recover_in() == 298 T(9) energy.set(15) T(10) assert energy.recover_in() is None
def test_arithmetic_assign_energy(): energy = Energy(10, 3) with time_traveler() as T: T( 0); energy += 10 T( 1); assert energy == 20 T( 2); energy -= 13 T( 3); assert energy == 7 T( 6); assert energy == 8 T( 7); energy += 10 T( 8); energy -= 10; T( 9); assert energy.recover_in() == 2 T(10); assert energy.recover_in() == 1 T(11); assert energy == 9
def bonus_energy(): energy = Energy(10, 300) with time_traveler() as T: T( 0); energy.set(15) T( 1); assert energy == 15 T( 2); energy.use() T( 3); assert energy.recover_in() is None T( 4); energy.use() T( 5); assert energy.recover_in() is None T( 6); energy.use(5) T( 7); assert energy.recover_in() == 299 T( 8); assert energy.recover_in() == 298 T( 9); energy.set(15) T(10); assert energy.recover_in() is None
def recover_energy(): energy = Energy(10, 5) with time_traveler() as T: T(0) energy.use(1) T(1) assert energy == 9 assert energy.recover_in() == 4 T(2) assert energy == 9 assert energy.recover_in() == 3 T(3) assert energy == 9 assert energy.recover_in() == 2 T(4) assert energy == 9 assert energy.recover_in() == 1 T(5) assert energy == 10 assert energy.recover_in() == None T(6) assert energy == 10 assert energy.recover_in() == None T(99) assert energy == 10 assert energy.recover_in() == None
def test_use_energy(): energy = Energy(10, 1000) assert energy == 10 energy.use() assert energy == 9 energy.use(5) assert energy == 4 with raises(ValueError): energy.use(5) energy.use(10, timestamp() + 10000) assert energy.current(timestamp() + 10000) == 0 with raises(ValueError): energy.use(10, timestamp() + 10010) energy.use(10, timestamp() + 10010, force=True) assert energy.recover_in(timestamp() + 10010) == 11000 assert energy.current(timestamp() + 10010) == 0 assert energy.debt(timestamp() + 10010) == 10 energy.use(10, timestamp() + 10010, force=True) assert energy.recover_in(timestamp() + 10010) == 21000 assert energy.debt(timestamp() + 10010) == 20
def test_extra_energy(): energy = Energy(10, 300) with time_traveler() as T: T(0) energy.set(15) T(1) assert energy == 15 assert energy.recover_in() is None assert energy.recover_fully_in() is None T(2) energy.use() assert energy.recover_in() is None assert energy.recover_fully_in() is None T(6) energy.use(6) T(7) assert energy.recover_in() == 299 assert energy.recover_fully_in() == 599 T(8) assert energy.recover_in() == 298 assert energy.recover_fully_in() == 598 T(9) energy.set(15) assert energy.recover_in() is None assert energy.recover_fully_in() is None T(10) assert energy.recover_in() is None assert energy.recover_fully_in() is None
def recover_energy(): energy = Energy(10, 5) with time_traveler() as T: T( 0); energy.use(1) T( 1); assert energy == 9; assert energy.recover_in() == 4 T( 2); assert energy == 9; assert energy.recover_in() == 3 T( 3); assert energy == 9; assert energy.recover_in() == 2 T( 4); assert energy == 9; assert energy.recover_in() == 1 T( 5); assert energy == 10; assert energy.recover_in() == None T( 6); assert energy == 10; assert energy.recover_in() == None T(99); assert energy == 10; assert energy.recover_in() == None
def test_arithmetic_assign_energy(): energy = Energy(10, 3) with time_traveler() as T: T(0) energy += 10 T(1) assert energy == 20 T(2) energy -= 13 T(3) assert energy == 7 T(6) assert energy == 8 T(7) energy += 10 T(8) energy -= 10 T(9) assert energy.recover_in() == 2 T(10) assert energy.recover_in() == 1 T(11) assert energy == 9
def test_recover_energy(): energy = Energy(10, 5) with time_traveler() as T: T(0) energy.use(2) T(1) assert energy == 8 assert energy.recover_in() == 4 assert energy.recover_fully_in() == 9 T(2) assert energy == 8 assert energy.recover_in() == 3 assert energy.recover_fully_in() == 8 T(3) assert energy == 8 assert energy.recover_in() == 2 assert energy.recover_fully_in() == 7 T(4) assert energy == 8 assert energy.recover_in() == 1 assert energy.recover_fully_in() == 6 T(5) assert energy == 9 assert energy.recover_in() == 5 assert energy.recover_fully_in() == 5 T(9) assert energy == 9 assert energy.recover_in() == 1 assert energy.recover_fully_in() == 1 T(10) assert energy == 10 assert energy.recover_in() == None assert energy.recover_fully_in() == None T(100) assert energy == 10 assert energy.recover_in() == None assert energy.recover_fully_in() == None