def test_copy(self): g1 = Autoincrement() g2 = g1.copy() g2.get_single() assert g1.get_single() == g2.get_single() - 1
def test_stream_single(self): g = Autoincrement() c = 0 for i in range(1000): for val in g.stream_single(): assert val == c c += 1 if c > 100000: break
def test_values_batch(self): ai = Autoincrement(start=-4.2, step=+4.2, dtype=np.float64) count = 0 for i in range(10): nb = np.random.randint(2, 10000) values = ai.get_batch(nb) for j, val in enumerate(values): d = (Decimal(-4.2) + ((Decimal(count + j)) * Decimal(4.2))) assert round(Decimal(val), 1) == round(d, 1) count += nb
def test_stream_batch(self): g = Autoincrement() c = 0 for i in range(10): nb = np.random.randint(2, 1000) for values in g.stream_batch(nb): for val in values: assert val == c c += 1 if c > 100000: break
def test_values_batch(self): gen = History(Autoincrement(), 42) for i, v in enumerate(gen.get_batch(10)): assert i == v for i in range(10): assert gen.get_prev(-10+i) == i
def __init__(self, gen_params: dict): super().__init__(gen_params) self.is_thread_safe = True self.sequenceBegin = gen_params['sequenceBegin'] self.gen = Autoincrement(start=self.sequenceBegin, step=1, dtype=np.int32)
def test_values_single(self): triangular_fun = BoundingOperator( ApplyFunctionOperator(function=lambda x: abs((x % 4) - 2) - 1, generator=Autoincrement()), lb=-1, ub=1) n = ScalingOperator(generator=triangular_fun, lb=-10, ub=10, dtype=np.float32) for _ in range(10000): assert n.get_single() == 10 assert n.get_single() == 0 assert n.get_single() == -10 assert n.get_single() == 0
def test_values_single(self): triangular_fun = BoundingOperator( ApplyFunctionOperator(function=lambda x: abs((x % 4) - 2) - 1, generator=Autoincrement()), lb=-1, ub=1) rd = RandomDatetime(generator=triangular_fun, start=np.datetime64("1950"), end=np.datetime64("2042"), unit="Y") for i in range(10000): assert rd.get_single() == np.datetime64('2042') assert rd.get_single() == np.datetime64('1996') assert rd.get_single() == np.datetime64('1950') assert rd.get_single() == np.datetime64('1996')
def test_values_single(self): gen = History(Autoincrement(), 42) for i in range(10): assert i == gen.get_single() for i in range(10): assert gen.get_prev(-10+i) == i for i in range(10): assert i + 10 == gen.get_single() for i in range(10): assert gen.get_prev(-10+i) == i + 10
def test_values_batch(self): triangular_fun = BoundingOperator( ApplyFunctionOperator(function=lambda x: abs((x % 4) - 2) - 1, generator=Autoincrement()), lb=-1, ub=1) rd = RandomDatetime(generator=triangular_fun, start=np.datetime64("1950"), end=np.datetime64("2042"), unit="Y") tmp = [np.datetime64('2042'), np.datetime64('1996'), np.datetime64('1950'), np.datetime64('1996')] count = 0 for i in range(10): nb = np.random.randint(2, 1000) values = rd.get_batch(nb) for j, val in enumerate(values): assert val == tmp[(count + j) % 4] count += nb
def test_values_batch(self): triangular_fun = BoundingOperator( ApplyFunctionOperator(function=lambda x: abs((x % 4) - 2) - 1, generator=Autoincrement()), lb=-1, ub=1) n = ScalingOperator(generator=triangular_fun, lb=-10, ub=10, dtype=np.float32) tmp = [10, 0, -10, 0] count = 0 for i in range(10): nb = np.random.randint(2, 1000) values = n.get_batch(nb) for j, val in enumerate(values): assert val == tmp[(count + j) % 4] count += nb
def _get_ts(self): time = Autoincrement() data = ConstantValueGenerator(value=42, dtype=np.uint16) return TimeSeries(time_gen=time, data_gen=data)
def test_values_batch(self): gen = MeanHistory(Autoincrement(start=4), 4, initial_values=[0,1,2,3]) for i in range(42): for j, v in enumerate(gen.get_batch(10)): assert v == ((i * 10 + j) * 4.0 + 6.0) / 4.0
def test_values_single(self): gen = MeanHistory(Autoincrement(start=4), 4, initial_values=[0,1,2,3]) for i in range(42): assert gen.get_single() == (i * 4.0 + 6.0) / 4.0
def _get_afo(self, fun): generator = Autoincrement() afo = ApplyFunctionOperator(function=fun, generator=generator) return afo
def test_type(self): ai = Autoincrement(start=-42, step=+42, dtype=np.int32) assert ai.get_single() == -42 assert isinstance(ai.get_batch(42), np.ndarray)
def test_shape(self): ai = Autoincrement(start=-42, step=+42, dtype=np.int32) nb = np.random.randint(2, 10000) assert ai.get_batch(nb).shape == (nb,)
def test_values_single(self): ai = Autoincrement(start=-42, step=+42, dtype=np.int32) for i in range(np.random.randint(10, 10000)): val = ai.get_single() assert val == -42 + i * 42