本文整理汇总了Python中gauge.Gauge.add_momentum方法的典型用法代码示例。如果您正苦于以下问题:Python Gauge.add_momentum方法的具体用法?Python Gauge.add_momentum怎么用?Python Gauge.add_momentum使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gauge.Gauge
的用法示例。
在下文中一共展示了Gauge.add_momentum方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_case1
# 需要导入模块: from gauge import Gauge [as 别名]
# 或者: from gauge.Gauge import add_momentum [as 别名]
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_set_min_max
# 需要导入模块: from gauge import Gauge [as 别名]
# 或者: from gauge.Gauge import add_momentum [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)]
示例3: test_in_range
# 需要导入模块: from gauge import Gauge [as 别名]
# 或者: from gauge.Gauge import add_momentum [as 别名]
def test_in_range():
g = Gauge(20, 10, at=0)
assert not g.in_range(0)
assert not g.in_range(20)
g.add_momentum(-1)
assert not g.in_range(0)
assert g.in_range(20)
示例4: test_hypergauge_hybrid1
# 需要导入模块: from gauge import Gauge [as 别名]
# 或者: from gauge.Gauge import add_momentum [as 别名]
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)]
示例5: Equilibrium
# 需要导入模块: from gauge import Gauge [as 别名]
# 或者: from gauge.Gauge import add_momentum [as 别名]
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)
示例6: test_make_momentum
# 需要导入模块: from gauge import Gauge [as 别名]
# 或者: from gauge.Gauge import add_momentum [as 别名]
def test_make_momentum():
g = Gauge(0, 10, at=0)
m = g.add_momentum(+1)
assert isinstance(m, Momentum)
with pytest.raises(TypeError):
g.add_momentum(m, since=1)
with pytest.raises(TypeError):
g.add_momentum(m, until=2)
示例7: test_intersection_of_vertical_segment_reversed
# 需要导入模块: from gauge import Gauge [as 别名]
# 或者: from gauge.Gauge import add_momentum [as 别名]
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)]
示例8: test_hypergauge_case2
# 需要导入模块: from gauge import Gauge [as 别名]
# 或者: from gauge.Gauge import add_momentum [as 别名]
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)]
示例9: test_hypergauge_with_different_base_time
# 需要导入模块: from gauge import Gauge [as 别名]
# 或者: from gauge.Gauge import add_momentum [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
示例10: test_thin_momenta
# 需要导入模块: from gauge import Gauge [as 别名]
# 或者: from gauge.Gauge import add_momentum [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
示例11: test_pickle
# 需要导入模块: from gauge import Gauge [as 别名]
# 或者: from gauge.Gauge import add_momentum [as 别名]
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
示例12: test_decr_max_hyper
# 需要导入模块: from gauge import Gauge [as 别名]
# 或者: from gauge.Gauge import add_momentum [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
示例13: random_gauge2
# 需要导入模块: from gauge import Gauge [as 别名]
# 或者: from gauge.Gauge import add_momentum [as 别名]
def random_gauge2(random=random, far=1000, near=1, until=20):
# 0 <= g <= (near ~ far)
g_max = Gauge(random.uniform(near, far), far, near, at=0)
value = random.uniform(0, g_max.max_value)
g = Gauge(value, g_max, at=0)
for x in range(0, until, 5):
g_max.add_momentum(random.uniform(-far, +far), since=x, until=x + 5)
for x in range(0, until, 2):
g.add_momentum(random.uniform(-far, +far), since=x, until=x + 2)
return g
示例14: test_set_range
# 需要导入模块: from gauge import Gauge [as 别名]
# 或者: from gauge.Gauge import add_momentum [as 别名]
def test_set_range():
g = Gauge(0, 100, at=0)
g.add_momentum(+1)
assert g.determination == [(0, 0), (100, 100)]
g.set_range(Gauge(100, 100, at=0), Gauge(0, 100, at=0), at=0)
g.max_gauge.add_momentum(-1, until=40)
g.min_gauge.add_momentum(+1, until=40)
assert g.determination == [(0, 0), (60, 60)]
g.clear_momenta(at=30)
g.add_momentum(-1)
assert g.determination == [(30, 30), (40, 40)]
示例15: test_same_determination
# 需要导入模块: from gauge import Gauge [as 别名]
# 或者: from gauge.Gauge import add_momentum [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