本文整理汇总了Python中gauge.Gauge类的典型用法代码示例。如果您正苦于以下问题:Python Gauge类的具体用法?Python Gauge怎么用?Python Gauge使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Gauge类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_case1
def test_case1():
g = Gauge(0, 5, at=0)
g.add_momentum(+1)
g.add_momentum(-2, since=1, until=3)
g.add_momentum(+1, since=5, until=7)
assert g.determination == [
(0, 0), (1, 1), (2, 0), (3, 0), (5, 2), (6.5, 5), (7, 5)]
示例2: test_hypergauge_hybrid1
def test_hypergauge_hybrid1():
# hybrid 1: same velocity of `g` and `g.max_gauge`.
# (suggested by @hybrid0)
g = Gauge(0, Gauge(1, 5, at=0), at=0)
g.add_momentum(+1)
g.max_gauge.add_momentum(+1, since=1)
assert g.determination == [(0, 0), (1, 1), (5, 5)]
示例3: test_intersection_of_vertical_segment_reversed
def test_intersection_of_vertical_segment_reversed():
f = FakeGauge([(0, 0), (1e-309, -1)])
g = Gauge(-2.5, 0, f, at=-1)
g.add_momentum(+2)
g.add_momentum(-1)
assert \
round_determination(g.determination, precision=1) == \
[(-1, -2.5), (0, -0.5), (0.5, 0)]
示例4: test_hypergauge_case2
def test_hypergauge_case2():
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, until=4)
g.max_gauge.add_momentum(+1, since=4, until=6)
assert g.determination == [
(0, 12), (1, 12), (2, 13), (3, 12), (4, 11), (6, 11), (8, 9)]
示例5: test_pickle
def test_pickle():
g = Gauge(0, 10, at=0)
r = Random(17171771)
for x in range(10000):
since = r.randrange(1000)
until = since + 1 + r.randrange(1000)
g.add_momentum(r.uniform(-10, +10), since=since, until=until)
data = pickle.dumps(g)
g2 = pickle.loads(data)
assert g.determination == g2.determination
示例6: test_over_max_on_hypergauge
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
示例7: test_decr_max_hyper
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
示例8: Equilibrium
class Equilibrium(object):
gauge = None
speed = None
def __init__(self, medium, speed):
self.speed = speed
self.medium = medium
@property
def medium(self):
return self._medium
@medium.setter
def medium(self, medium, at=None):
at = now_or(at)
self._medium = medium
if self.gauge is None:
self.gauge = Gauge(medium, medium, medium)
return
value = self.gauge.clear_momenta(at)
if value == medium:
self.gauge._set_limits(medium, medium, at=at)
return
if value < medium:
self.gauge.set_max(medium, at=at)
velocity = +self.speed
elif value > medium:
self.gauge.set_min(medium, at=at)
velocity = -self.speed
self.gauge.add_momentum(velocity, since=at)
示例9: zigzag
def zigzag():
g = Gauge(1, Gauge(2, 3, 2, at=0), Gauge(1, 1, 0, at=0), at=0)
for x in range(6):
g.max_gauge.add_momentum(+1, since=x * 2, until=x * 2 + 1)
g.max_gauge.add_momentum(-1, since=x * 2 + 1, until=x * 2 + 2)
g.min_gauge.add_momentum(-1, since=x * 2, until=x * 2 + 1)
g.min_gauge.add_momentum(+1, since=x * 2 + 1, until=x * 2 + 2)
for x in range(3):
t = sum(y * 2 for y in range(x + 1))
g.add_momentum(+1, since=t, until=t + (x + 1))
g.add_momentum(-1, since=t + (x + 1), until=t + 2 * (x + 1))
return g
示例10: test_decr_max_normal
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
示例11: test_decr_max_before_base_time
def test_decr_max_before_base_time():
# decr max earlier than the gauge's base time.
g = Gauge(0, Gauge(10, 100, at=10), at=5)
g.add_momentum(+1)
assert g.determination == [(5, 0), (15, 10)]
with pytest.raises(ValueError):
g.max_gauge.decr(5, at=0)
assert g.determination == [(5, 0), (15, 10)]
g.max_gauge.incr(10, at=10)
assert g.determination == [(10, 5), (25, 20)]
示例12: test_intersection_of_vertical_segment
def test_intersection_of_vertical_segment():
assert 0 != 1e-309
assert math.isinf(1 / 1e-309)
f = FakeGauge([(0, 0), (1e-309, 1)])
assert f.get(0.000000000000000000000) == 0
assert f.get(0.000000000000000000001) == 1
g = Gauge(2.5, f, at=-1)
g.add_momentum(-2)
g.add_momentum(+1)
assert \
round_determination(g.determination, precision=1) == \
[(-1, 2.5), (0, 0.5), (0.5, 0)]
示例13: shift_gauge
def shift_gauge(gauge, delta=0):
"""Adds the given delta to a gauge."""
if gauge.max_gauge is None:
max_ = gauge.max_value + delta
else:
max_ = shift_gauge(gauge.max_gauge, delta)
if gauge.min_gauge is None:
min_ = gauge.min_value + delta
else:
min_ = shift_gauge(gauge.min_gauge, delta)
g = Gauge(gauge.base[VALUE] + delta, max_, min_, gauge.base[TIME])
for momentum in gauge.momenta:
g.add_momentum(momentum)
return g
示例14: test_hypergauge_zigzag2
def test_hypergauge_zigzag2():
g = Gauge(2, Gauge(3, 5, 3, at=0), Gauge(2, 2, 0, at=0), at=0)
for x in range(5):
g.max_gauge.add_momentum(+1, since=x * 4, until=x * 4 + 2)
g.max_gauge.add_momentum(-1, since=x * 4 + 2, until=x * 4 + 4)
g.min_gauge.add_momentum(-1, since=x * 4, until=x * 4 + 2)
g.min_gauge.add_momentum(+1, since=x * 4 + 2, until=x * 4 + 4)
for x in range(4):
t = sum(y * 2 for y in range(x + 1))
g.add_momentum(+1, since=t, until=t + (x + 1))
g.add_momentum(-1, since=t + (x + 1), until=t + 2 * (x + 1))
assert g.determination == [
(0, 2), (1, 3), (2, 2), (3.5, 3.5), (4, 3), (6, 1), (8, 3), (9, 4),
(11.5, 1.5), (12, 2), (14.5, 4.5), (16, 3), (18.5, 0.5), (20, 2)]
示例15: test_same_determination
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