本文整理汇总了Python中gauge.Gauge.get方法的典型用法代码示例。如果您正苦于以下问题:Python Gauge.get方法的具体用法?Python Gauge.get怎么用?Python Gauge.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gauge.Gauge
的用法示例。
在下文中一共展示了Gauge.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_set_min_max
# 需要导入模块: from gauge import Gauge [as 别名]
# 或者: from gauge.Gauge import get [as 别名]
def test_set_min_max():
# without momentum
g = Gauge(5, 10)
assert g.get_max() == 10
assert g.get_min() == 0
assert g.get() == 5
g.set_range(max=100, min=10)
assert g.get_max() == 100
assert g.get_min() == 10
assert g.get() == 10
g.set_min(10)
assert g.get() == 10
g.set_min(5)
assert g.get() == 10
g.set_range(max=5, min=0)
assert g.get_max() == 5
assert g.get_min() == 0
assert g.get() == 5
# with momentum
g = Gauge(5, 10, at=0)
g.add_momentum(+1)
assert g.determination == [(0, 5), (5, 10)]
g.set_max(50, at=0)
assert g.determination == [(0, 5), (45, 50)]
g.set_min(40, at=0)
assert g.determination == [(0, 40), (10, 50)]
示例2: test_thin_momenta
# 需要导入模块: from gauge import Gauge [as 别名]
# 或者: from gauge.Gauge import get [as 别名]
def test_thin_momenta():
g = Gauge(0, 100, at=0)
for x in range(1000):
g.add_momentum(+1000000000, since=x, until=x + 1e-10)
assert_all_in_range(g)
assert g.get(0) == 0
assert g.get(1001) == 100
for x, y in zip(range(9999), range(1, 10000)):
assert 0 <= g.get(x / 10.) <= g.get(y / 10.) <= 100
示例3: test_hypergauge_with_different_base_time
# 需要导入模块: from gauge import Gauge [as 别名]
# 或者: from gauge.Gauge import get [as 别名]
def test_hypergauge_with_different_base_time():
g = Gauge(0, Gauge(10, 100, at=100), at=0)
g.add_momentum(+1)
assert g.max_gauge.get(0) == 10
assert g.get(10) == 10
g = Gauge(0, Gauge(10, 100, at=0), at=100)
g.add_momentum(+1)
assert g.max_gauge.get(100) == 10
assert g.get(110) == 10
示例4: test_over_max_on_hypergauge
# 需要导入模块: from gauge import Gauge [as 别名]
# 或者: from gauge.Gauge import get [as 别名]
def test_over_max_on_hypergauge():
g = Gauge(1, Gauge(10, 20, at=0), at=0)
g.max_gauge.add_momentum(+1)
with pytest.raises(ValueError):
g.set(20, at=0)
g.set(20, at=0, outbound=OK)
assert g.get(at=0) == 20
g.set(20, at=10)
assert g.get(at=10) == 20
assert g.get(at=0) == 20 # past was forgot
示例5: test_decr_max_hyper
# 需要导入模块: from gauge import Gauge [as 别名]
# 或者: from gauge.Gauge import get [as 别名]
def test_decr_max_hyper():
g = Gauge(0, Gauge(10, 100, at=0), at=0)
g.add_momentum(+2)
g.add_momentum(-1)
assert g.base[TIME] == 0
assert g.get(10) == 10
g.max_gauge.decr(5, at=10)
assert g.base[TIME] == 10
assert g.get(10) == 5
assert g.get(20) == 5
示例6: test_same_determination
# 需要导入模块: from gauge import Gauge [as 别名]
# 或者: from gauge.Gauge import get [as 别名]
def test_same_determination():
g = Gauge(10, 100, at=0)
g.add_momentum(+1, since=5, until=10)
g.add_momentum(+1, since=20, until=30)
g.add_momentum(-2, since=50, until=60)
fg = FrozenGauge(g)
assert fg.get(0) == g.get(0) == 10
assert fg.get(10) == g.get(10) == 15
assert fg.get(30) == g.get(30) == 25
assert fg.get(60) == g.get(60) == 5
assert fg.get(100) == g.get(100) == 5
示例7: test_ok_outbound
# 需要导入模块: from gauge import Gauge [as 别名]
# 或者: from gauge.Gauge import get [as 别名]
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
示例8: test_decr_max_normal
# 需要导入模块: from gauge import Gauge [as 别名]
# 或者: from gauge.Gauge import get [as 别名]
def test_decr_max_normal():
g = Gauge(0, 10, at=0)
g.add_momentum(+2)
g.add_momentum(-1)
assert g.base[TIME] == 0
assert g.get(10) == 10
g.set_max(5, at=10)
g.set(10, outbound=OK, at=10)
assert g.base[TIME] == 10
assert g.get(10) == 10
assert g.get(15) == 5
assert g.get(20) == 5
示例9: test_momenta_order
# 需要导入模块: from gauge import Gauge [as 别名]
# 或者: from gauge.Gauge import get [as 别名]
def test_momenta_order():
g = Gauge(0, 50, at=0)
g.add_momentum(+3, since=0, until=5)
g.add_momentum(+2, since=1, until=4)
g.add_momentum(+1, since=2, until=3)
assert g.get(0) == 0
assert g.get(1) == 3
assert g.get(2) == 8
assert g.get(3) == 14
g.decr(1, at=3)
assert g.get(3) == 13
assert g.get(4) == 18
assert g.get(5) == 21
示例10: test_clear_momenta
# 需要导入模块: from gauge import Gauge [as 别名]
# 或者: from gauge.Gauge import get [as 别名]
def test_clear_momenta():
g = Gauge(0, 10, at=0)
g.add_momentum(+1)
g.clear_momenta(at=5)
assert g.get(5) == 5
assert g.determination == [(5, 5)]
# clear momenta when the value is out of the range
g.add_momentum(+1)
g.set(15, outbound=OK, at=10)
g.clear_momenta(at=10)
assert g.get(10) == 15
assert g.determination == [(10, 15)]
# rebase by Gauge.clear_momenta()
g.clear_momenta(100)
assert g.get() == 100
示例11: test_forget_past
# 需要导入模块: from gauge import Gauge [as 别名]
# 或者: from gauge.Gauge import get [as 别名]
def test_forget_past():
g = Gauge(0, 50, at=0)
g.add_momentum(+1, since=0, until=5)
g.add_momentum(0, since=0)
g.add_momentum(0, until=999)
assert g.get(0) == 0
assert g.get(1) == 1
assert g.get(2) == 2
assert g.get(3) == 3
assert g.get(4) == 4
assert g.get(5) == 5
assert g.get(10) == 5
assert g.get(20) == 5
assert len(g.momenta) == 3
g.forget_past(at=30)
assert len(g.momenta) == 2
示例12: test_clamped_by_max_gauge
# 需要导入模块: from gauge import Gauge [as 别名]
# 或者: from gauge.Gauge import get [as 别名]
def test_clamped_by_max_gauge():
# in_range, decr max -> clamp
g = Gauge(10, Gauge(20, 20, at=0), at=0)
assert g.get(0) == 10
g.max_gauge.set(5, at=0)
assert g.get(0) == 5
# in_range, incr max -> not clamp
g.max_gauge.set(15, at=0)
assert g.get(0) == 5
# outbound, decr max -> not clamp
g.set(20, outbound=OK, at=0)
assert g.get(0) == 20
g.max_gauge.set(10, at=0)
assert g.get(0) == 20
# time-skewed
g = Gauge(10, Gauge(20, 20, at=0), at=0)
g.max_gauge.set(5, at=10)
assert g.base[TIME] == 10
assert g.base[VALUE] == 5
示例13: test_case8_simple
# 需要导入模块: from gauge import Gauge [as 别名]
# 或者: from gauge.Gauge import get [as 别名]
def test_case8_simple():
max_ = Gauge(10, 10, at=0)
max_.add_momentum(-1)
g = Gauge(10, max_, at=0)
max_.forget_past(at=2)
with pytest.raises(ValueError):
max_.forget_past(at=1) # forget older past.
assert g.get(99999) == approx(0)
示例14: test_clamp_outbound
# 需要导入模块: from gauge import Gauge [as 别名]
# 或者: from gauge.Gauge import get [as 别名]
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
示例15: test_case3
# 需要导入模块: from gauge import Gauge [as 别名]
# 或者: from gauge.Gauge import get [as 别名]
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