def use_energy_in_the_future(): energy = Energy(10, 5) with time_traveler() as T: T( 5); energy.use() T( 6); assert energy.passed() == 1 with raises(ValueError): T( 0); energy.passed()
def use_energy_in_the_future(): energy = Energy(10, 5) with time_traveler() as T: T(5) energy.use() T(6) assert energy.passed() == 1 with raises(ValueError): T(0) energy.passed()
def test_future_tulerance(): energy = Energy(10, 5, future_tolerance=4) with time_traveler() as T: T(5) energy.use() # used at the past T(6) assert energy.passed() == 1 assert energy == 9 # used at the near future T(4) assert energy.passed() == 0 assert energy == 9 T(3) assert energy.passed() == 0 assert energy == 9 T(2) assert energy.passed() == 0 assert energy == 9 T(1) assert energy.passed() == 0 assert energy == 9 # used at the remote future T(0) with raises(ValueError): energy.passed()
def test_use_energy_at_the_future(): energy = Energy(10, 5) with time_traveler() as T: T( 5); energy.use() T( 6); assert energy.passed() == 1 with raises(ValueError): T( 4); energy.passed() with raises(ValueError): T( 3); energy.passed() with raises(ValueError): T( 2); energy.passed() with raises(ValueError): T( 1); energy.passed() with raises(ValueError): T( 0); energy.passed()
def test_use_energy_at_the_future(): energy = Energy(10, 5) with time_traveler() as T: T(5) energy.use() T(6) assert energy.passed() == 1 with raises(ValueError): T(4) energy.passed() with raises(ValueError): T(3) energy.passed() with raises(ValueError): T(2) energy.passed() with raises(ValueError): T(1) energy.passed() with raises(ValueError): T(0) energy.passed()