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
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)