Example #1
0
    def test_copy(self):
        g1 = Autoincrement()
        g2 = g1.copy()

        g2.get_single()

        assert g1.get_single() == g2.get_single() - 1
Example #2
0
 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
Example #3
0
 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
Example #4
0
 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
Example #5
0
    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)
Example #7
0
 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
Example #8
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')
Example #9
0
 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
Example #10
0
 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
Example #11
0
 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
Example #12
0
 def _get_ts(self):
     time = Autoincrement()
     data = ConstantValueGenerator(value=42, dtype=np.uint16)
     return TimeSeries(time_gen=time, data_gen=data)
Example #13
0
    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
Example #14
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
Example #15
0
 def _get_afo(self, fun):
     generator = Autoincrement()
     afo = ApplyFunctionOperator(function=fun, generator=generator)
     return afo
Example #16
0
 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)
Example #17
0
 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,)
Example #18
0
 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