コード例 #1
0
ファイル: gaugetest.py プロジェクト: what-studio/gauge
def test_hypergauge_case4():
    g = Gauge(12, 100, at=0)
    g.add_momentum(+1, since=1, until=6)
    g.add_momentum(-1, since=3, until=8)
    g.set_max(Gauge(15, 15, at=0), at=0)
    g.max_gauge.add_momentum(-1)
    assert g.determination == [
        (0, 12), (1, 12), (2, 13), (3, 12), (6, 9), (8, 7), (15, 0)]
    # bidirectional hyper-gauge
    g_max = Gauge(10, 10, at=0)
    g_max.add_momentum(-1, since=0, until=4)
    g_max.add_momentum(+1, since=6, until=7)
    g_min = Gauge(0, 10, at=0)
    g_min.add_momentum(+1, since=1, until=6)
    g_min.add_momentum(-1, since=6, until=8)
    g = Gauge(5, g_max, g_min, at=0)
    g.add_momentum(+1, since=0, until=3)
    g.add_momentum(-1, since=3, until=6)
    g.add_momentum(+1, since=6, until=9)
    g.add_momentum(-1, since=9, until=12)
    assert g.determination == [
        (0, 5), (2.5, 7.5), (3, 7), (4, 6), (5.5, 4.5), (6, 5), (8, 7),
        (9, 7), (12, 4)]
    g_min.incr(1, at=5)
    assert g.determination == [(5, 5), (6, 6), (7, 7), (9, 7), (12, 4)]
コード例 #2
0
ファイル: gaugetest.py プロジェクト: what-studio/gauge
def test_ok_outbound():
    g = Gauge(1, 10)
    with pytest.raises(ValueError):
        g.set(11)
    with pytest.raises(ValueError):
        g.incr(100)
    with pytest.raises(ValueError):
        g.decr(100)
    g.set(10)
    assert g.get() == 10
    g.set(11, outbound=OK)
    assert g.get() == 11
コード例 #3
0
def test_ok_outbound():
    g = Gauge(1, 10)
    with pytest.raises(ValueError):
        g.set(11)
    with pytest.raises(ValueError):
        g.incr(100)
    with pytest.raises(ValueError):
        g.decr(100)
    g.set(10)
    assert g.get() == 10
    g.set(11, outbound=OK)
    assert g.get() == 11
コード例 #4
0
ファイル: gaugetest.py プロジェクト: what-studio/gauge
def test_case3():
    g = Gauge(0, 10, at=0)
    assert g.get(0) == 0
    g.add_momentum(+1, since=0)
    assert g.get(10) == 10
    g.incr(3, outbound=OK, at=11)
    assert g.get(11) == 13
    g.add_momentum(-1, since=13)
    assert g.get(13) == 13
    assert g.get(14) == 12
    assert g.get(15) == 11
    assert g.get(16) == 10
    assert g.get(17) == 10
コード例 #5
0
def test_case3():
    g = Gauge(0, 10, at=0)
    assert g.get(0) == 0
    g.add_momentum(+1, since=0)
    assert g.get(10) == 10
    g.incr(3, outbound=OK, at=11)
    assert g.get(11) == 13
    g.add_momentum(-1, since=13)
    assert g.get(13) == 13
    assert g.get(14) == 12
    assert g.get(15) == 11
    assert g.get(16) == 10
    assert g.get(17) == 10
コード例 #6
0
ファイル: gaugetest.py プロジェクト: what-studio/gauge
def test_life():
    with t(0):
        life = Gauge(100, 100)
        life.add_momentum(-1)
        assert life.get() == 100
    with t(1):
        assert life.get() == 99
    with t(2):
        assert life.get() == 98
    with t(10):
        assert life.get() == 90
        life.incr(1)
        assert life.get() == 91
    with t(11):
        assert life.get() == 90
コード例 #7
0
def test_life():
    with t(0):
        life = Gauge(100, 100)
        life.add_momentum(-1)
        assert life.get() == 100
    with t(1):
        assert life.get() == 99
    with t(2):
        assert life.get() == 98
    with t(10):
        assert life.get() == 90
        life.incr(1)
        assert life.get() == 91
    with t(11):
        assert life.get() == 90
コード例 #8
0
def test_hypergauge_case4():
    g = Gauge(12, 100, at=0)
    g.add_momentum(+1, since=1, until=6)
    g.add_momentum(-1, since=3, until=8)
    g.set_max(Gauge(15, 15, at=0), at=0)
    g.max_gauge.add_momentum(-1)
    assert g.determination == [(0, 12), (1, 12), (2, 13), (3, 12), (6, 9),
                               (8, 7), (15, 0)]
    # bidirectional hyper-gauge
    g_max = Gauge(10, 10, at=0)
    g_max.add_momentum(-1, since=0, until=4)
    g_max.add_momentum(+1, since=6, until=7)
    g_min = Gauge(0, 10, at=0)
    g_min.add_momentum(+1, since=1, until=6)
    g_min.add_momentum(-1, since=6, until=8)
    g = Gauge(5, g_max, g_min, at=0)
    g.add_momentum(+1, since=0, until=3)
    g.add_momentum(-1, since=3, until=6)
    g.add_momentum(+1, since=6, until=9)
    g.add_momentum(-1, since=9, until=12)
    assert g.determination == [(0, 5), (2.5, 7.5), (3, 7), (4, 6), (5.5, 4.5),
                               (6, 5), (8, 7), (9, 7), (12, 4)]
    g_min.incr(1, at=5)
    assert g.determination == [(5, 5), (6, 6), (7, 7), (9, 7), (12, 4)]
コード例 #9
0
ファイル: gaugetest.py プロジェクト: what-studio/gauge
def test_clamp_outbound():
    g = Gauge(1, 10)
    g.set(11, outbound=CLAMP)
    assert g.get() == 10
    g.incr(100, outbound=CLAMP)
    assert g.get() == 10
    g.decr(100, outbound=CLAMP)
    assert g.get() == 0
    g.incr(3, outbound=CLAMP)
    assert g.get() == 3
    g.decr(1, outbound=CLAMP)
    assert g.get() == 2
    g.set(100, outbound=OK)
    g.incr(3, outbound=CLAMP)
    assert g.get() == 100
    g.decr(3, outbound=CLAMP)
    assert g.get() == 97
    g.set(98, outbound=CLAMP)
    assert g.get() == 97
    g.set(97, outbound=CLAMP)
    assert g.get() == 97
    g.set(96, outbound=CLAMP)
    assert g.get() == 96
コード例 #10
0
def test_clamp_outbound():
    g = Gauge(1, 10)
    g.set(11, outbound=CLAMP)
    assert g.get() == 10
    g.incr(100, outbound=CLAMP)
    assert g.get() == 10
    g.decr(100, outbound=CLAMP)
    assert g.get() == 0
    g.incr(3, outbound=CLAMP)
    assert g.get() == 3
    g.decr(1, outbound=CLAMP)
    assert g.get() == 2
    g.set(100, outbound=OK)
    g.incr(3, outbound=CLAMP)
    assert g.get() == 100
    g.decr(3, outbound=CLAMP)
    assert g.get() == 97
    g.set(98, outbound=CLAMP)
    assert g.get() == 97
    g.set(97, outbound=CLAMP)
    assert g.get() == 97
    g.set(96, outbound=CLAMP)
    assert g.get() == 96
コード例 #11
0
ファイル: gaugetest.py プロジェクト: what-studio/gauge
def test_once_outbound():
    g = Gauge(1, 10)
    assert g.incr(5, outbound=ONCE) == 6
    assert g.incr(5, outbound=ONCE) == 11
    with pytest.raises(ValueError):
        g.incr(1, outbound=ONCE)
コード例 #12
0
def test_once_outbound():
    g = Gauge(1, 10)
    assert g.incr(5, outbound=ONCE) == 6
    assert g.incr(5, outbound=ONCE) == 11
    with pytest.raises(ValueError):
        g.incr(1, outbound=ONCE)