def test_online_mean():
    s = SimulatedTimeSeries(make_data(1, 6))
    s_mean = s.online_mean()
    assert s_mean.produce(3) == [(1, 1.0), (2, 1.5), (3, 2.0)]
    assert s_mean.produce(3) == [(4, 2.5), (5, 3.0), (6, 3.5)]

    s = SimulatedTimeSeries(make_data(1, 6))
    s_mean = s.online_mean()
    s_mean.produce(3)
    s_mean = s.online_mean()
    assert s_mean.produce(3) == [(4, 4.0), (5, 4.5), (6, 5.0)]
def test_mean():
    """
    A function to test mean with size of 10000 and 30000

    """
    finite_data = make_simple_data(10000)
    ts = SimulatedTimeSeries(finite_data)
    assert ts.mean() == 5000

    infinite_data = make_simple_data(30000)
    ts = SimulatedTimeSeries(infinite_data)
    with raises(ValueError):
        ts.mean()
def test_online_std():
    s = SimulatedTimeSeries(make_data(1, 6))
    s_std = s.online_std()
    assert s_std.produce(3) == [(1, 0.0), (2, 0.7071067811865476), (3, 1.0)]
    assert s_std.produce(3) == [(4, 1.2909944487358056),
                                (5, 1.5811388300841898),
                                (6, 1.8708286933869707)]

    s = SimulatedTimeSeries(make_data(1, 6))
    s_std = s.online_std()
    s_std.produce(3)
    s_std = s.online_std()
    assert s_std.produce(3) == [(4, 0.0), (5, 0.7071067811865476), (6, 1.0)]
示例#4
0
 def test_simulated_timeseries_initialization(self):
     """ Use make_data as a generator"""
     # Generator must be pre-primed
     generator = make_data(1, stop=None)
     ts = SimulatedTimeSeries(generator)
     print(ts.produce(2))
     logging.info(list(ts.produce(2)))
def test_itervalues_tuple():
    gen_tuple = default_generator(list_tuple)
    sts = SimulatedTimeSeries(gen_tuple)
    i = 0
    for x in sts.itervalues():
        assert x == list_value[i]
        i += 1
def test_type():
    """
    A function to test if input is a generator

    """
    with raises(TypeError):
        wrongtype = SimulatedTimeSeries(5)
def test_itertimes_number():
    gen = default_generator(list_value)
    sts = SimulatedTimeSeries(gen)
    i = 0
    for x in sts.itertimes():
        assert x == i
        i += 1
def test_iter_number():
    gen = default_generator(list_value)
    sts = SimulatedTimeSeries(gen)
    i = 0
    for x in iter(sts):
        assert x == list_value[i]
        i += 1
def test_repr():
    """
    A function to test __repr__

    """
    data = make_simple_data(5)
    timeseries_5 = SimulatedTimeSeries(data)
    assert repr(timeseries_5) == "SimulatedTimeSeries(time=0)"
示例#10
0
 def test_valid_init(self):
     """ All the sized timeseries __init__ constructors should take
         any sequence-like thing. Unsized should take a generator.
     """
     # NOTE: Depending on intepretation, this might be safe
     ts = TimeSeries([0], [0])
     ats = ArrayTimeSeries([0], [0])
     sts = SimulatedTimeSeries(zero_generator)
     scores.append(('#ts', 'init valid ts, ats, sts', 3))
def test_online_mean():
    #values = [10.68, 10.18, 4.10, 9.05, 11.68, 12.30, 9.80, 4.44, 11.40, 6.41, 9.15]
    #gen2 =  default_generator(values)
    gen = default_generator(list_value)
    sts = SimulatedTimeSeries(gen)
    mean = sts.online_mean()
    assert mean.produce(5) == de_mean[:5]
    assert mean.produce(5) == [
        6.966666666666666, 7.065714285714285, 7.25125, 7.521111111111111, 7.656
    ]
def test_std():
    """
    A function to test std with size of 15000 and 30000

    """
    finite_data = make_simple_data(15000)
    ts = SimulatedTimeSeries(finite_data)
    finite_data_copy = make_simple_data(15000)
    data_list = []
    for time, value in enumerate(finite_data_copy):
        data_list.append(value) 
    expect_result = np.std(data_list)
    err_std = (ts.std() - expect_result) / expect_result 
    assert abs(err_std) < 1e-4

    infinite_data = make_simple_data(30000)
    ts = SimulatedTimeSeries(infinite_data)
    with raises(ValueError):
        ts.std()
示例#13
0
 def test_valid_nonempty_str_and_repr(self):
     """ All concrete classes should have a __str__() and __repr__(). Repeats are acceptable. """
     ts = TimeSeries([0], [0])
     ats = ArrayTimeSeries([0], [0])
     sts = SimulatedTimeSeries(zero_generator)
     for ts_class in [ts, ats, sts]:
         dunder_str = str(ts_class)
         dunder_repr = repr(ts_class)
         self.assertNotEqual(dunder_str, '')
         self.assertNotEqual(dunder_repr, '')
     scores.append(
         ('#ts', 'all concrete classes should have non-empty str and repr',
          1))
def test_online_std():
    values = [
        10.68, 10.18, 4.10, 9.05, 11.68, 12.30, 9.80, 4.44, 11.40, 6.41, 9.15
    ]
    gen2 = default_generator(values)
    sts = SimulatedTimeSeries(gen2)
    std = sts.online_std()
    #print (mean.produce(5))
    assert std.produce(5) == [
        0, 0.3535533905932738, 3.6631680278141765, 3.0131531103922797,
        2.9712993790596056
    ]
    assert std.produce(5) == [
        2.9545338041728337, 2.697590635751695, 3.110504954413121,
        3.0150612671129, 2.985171500749813
    ]
def test_produce():
    """
    A function to test produce using data size of 50 and 5 different chunk sizes

    """
    # test chunk=1 and chunk>1
    for data_size, chunk_size in [(50, 5), (50, 4), (50, 3), (50, 2), (50, 1)]:
        data = make_simple_data(data_size)
        test_ts = SimulatedTimeSeries(data)
        result = list(test_ts.produce(chunk_size))
        expect_result = []
        for time, value in enumerate(make_simple_data(data_size)):
            if len(expect_result) >= chunk_size:
                assert result == expect_result
                result = list(test_ts.produce(chunk_size))
                expect_result = []
            expect_result.append((time, value))
示例#16
0
 def test_valid_nondefault_str_and_repr(self):
     """ All concrete classes should have non-default __str__() and __repr__(). """
     ts = TimeSeries([0], [0])
     ats = ArrayTimeSeries([0], [0])
     sts = SimulatedTimeSeries(zero_generator)
     self.assertNotRegexpMatches('^<.*.TimeSeries object at .*>$', str(ts))
     self.assertNotRegexpMatches('^<.*.TimeSeries object at .*>$', repr(ts))
     self.assertNotRegexpMatches('^<.*.ArrayTimeSeries object at .*>$',
                                 str(ats))
     self.assertNotRegexpMatches('^<.*.ArrayTimeSeries object at .*>$',
                                 repr(ats))
     self.assertNotRegexpMatches('^<.*.SimulatedTimeSeries object at .*>$',
                                 str(sts))
     self.assertNotRegexpMatches('^<.*.SimulatedTimeSeries object at .*>$',
                                 repr(sts))
     scores.append(
         ('#ts',
          'all concrete classes should have non-default str and repr', 1))
def test_iter():
    ts = SimulatedTimeSeries(make_data(0, 3))
    assert list(iter(ts)) == [(0, 0), (1, 1), (2, 2), (3, 3)]
def test_len():
    gen = default_generator(list_value)
    sts = SimulatedTimeSeries(gen)
    assert len(sts) == 10
def test_str_with_time():
    assert str(SimulatedTimeSeries(make_data(0, 3))) == "SimulatedTimeSeries"
示例#20
0
 def test_simulated_timeseries_produce_tuple_chunks(self):
     """ Test that the timeseries is generated correctly with the right number of chunks. """
     generator = make_tuples(1)
     ts = SimulatedTimeSeries(generator)
     values = list(ts.produce(2))
     self.assertEqual(values, [1, 1])
def test_iter_time():
    ts = SimulatedTimeSeries(make_data(0, 3))
    assert list(ts.itertimes()) == [0, 1, 2, 3]
def test_produce_more():
    ts = SimulatedTimeSeries(make_data(0, 3))
    assert list(ts.produce(2)) == [(0, 0), (1, 1)]
    assert list(ts.produce(4)) == [(2, 2), (3, 3)]
示例#23
0
 def test_simulated_timeseries_produce_chunk(self):
     """ Test that make_ones returns the right number of chunks. """
     generator = make_ones(1)
     ts = SimulatedTimeSeries(generator)
     values = list(ts.produce(2))
     self.assertEqual(values, [1, 1])
def test_init():
    gen = default_generator(list_value)
    SimulatedTimeSeries(gen)
def test_str():
    gen = default_generator(list_value)
    sts = SimulatedTimeSeries(gen)
    assert str(sts) == "this is a generator: <SimulatedTimeSeries>"