コード例 #1
0
ファイル: energytests.py プロジェクト: chidoli/energy
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()
コード例 #2
0
ファイル: energytests.py プロジェクト: chidoli/energy
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()
コード例 #3
0
ファイル: energytests.py プロジェクト: DaneTheory/energy
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()
コード例 #4
0
ファイル: energytests.py プロジェクト: mananthavelu/energy
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()
コード例 #5
0
ファイル: energytests.py プロジェクト: DaneTheory/energy
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()
コード例 #6
0
ファイル: energytests.py プロジェクト: mananthavelu/energy
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()