本文整理汇总了Python中gauge.Gauge.when方法的典型用法代码示例。如果您正苦于以下问题:Python Gauge.when方法的具体用法?Python Gauge.when怎么用?Python Gauge.when使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gauge.Gauge
的用法示例。
在下文中一共展示了Gauge.when方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_whenever
# 需要导入模块: from gauge import Gauge [as 别名]
# 或者: from gauge.Gauge import when [as 别名]
def test_whenever():
g = Gauge(0, 10, at=0)
g.add_momentum(+1)
g.add_momentum(-2, since=3, until=4)
g.add_momentum(-2, since=5, until=6)
g.add_momentum(-2, since=7, until=8)
assert g.when(3) == 3
assert g.when(3, after=1) == 5
assert g.when(3, after=2) == 7
assert g.when(3, after=3) == 9
with pytest.raises(ValueError):
g.when(3, after=4)
whenever = g.whenever(3)
assert list(whenever) == [3, 5, 7, 9]
# inverse
g = Gauge(10, 10, at=0)
g.add_momentum(-1)
g.add_momentum(+2, since=3, until=4)
g.add_momentum(+2, since=5, until=6)
g.add_momentum(+2, since=7, until=8)
assert g.when(7) == 3
assert g.when(7, after=1) == 5
示例2: test_when
# 需要导入模块: from gauge import Gauge [as 别名]
# 或者: from gauge.Gauge import when [as 别名]
def test_when():
g = Gauge(0, 10, at=0)
assert g.when(0) == 0
with pytest.raises(ValueError):
g.when(10)
g.add_momentum(+1)
assert g.when(10) == 10
g.add_momentum(+1, since=3, until=5)
assert g.when(10) == 8
g.add_momentum(-2, since=4, until=8)
assert g.when(0) == 0
assert g.when(1) == 1
assert g.when(2) == 2
assert g.when(3) == 3
assert g.when(4) == 3.5
assert g.when(5) == 4
assert g.when(6) == 12
assert g.when(7) == 13
assert g.when(8) == 14
assert g.when(9) == 15
assert g.when(10) == 16
with pytest.raises(ValueError):
g.when(11)