예제 #1
0
def test_std_chunk():
    t = SMTimeSeries(range(20), range(20))
    assert (t.std(chunk=1) == np.std(np.array([0])))
    assert (t.std(chunk=3) == np.std(np.array([0, 1, 2])))
    assert (t.std(chunk=20) == np.std(np.array(range(20))))

    delete_test_data()
예제 #2
0
def test_no_id():
    t1 = SMTimeSeries([10, 20], [3, 4])

    t1_stored = FSM_global.get(t1._id)

    assert ((t1.values() == t1_stored.values()).all())
    assert ((t1.times() == t1_stored.times()).all())
예제 #3
0
def test_interpolate_2():
    a = SMTimeSeries([0, 5, 10], [1, 2, 3], 4)
    b = a.interpolate([0, 5, 10])

    assert (np.array_equal(
        FSM_global.get(b._id).values(), np.array([1, 2, 3])))
    assert (np.array_equal(
        FSM_global.get(b._id).times(), np.array([0, 5, 10])))
예제 #4
0
def test_iteritems():
    t = SMTimeSeries(range(4), [1, 5, 3, 6])

    iter_list = []
    for val in t.iteritems():
        iter_list.append(val)

    assert ([(0, 1), (1, 5), (2, 3), (3, 6)] == iter_list)
예제 #5
0
def test_iter_2():
    t = SMTimeSeries(range(-14, 701, 7), range(-14, 701, 7))

    iter_list = []
    for val in t:
        iter_list.append(val)

    assert ((iter_list == t.values()).all())
예제 #6
0
def test_itertimes():
    t = SMTimeSeries(range(4), [1, 5, 3, 6])

    iter_list = []
    for val in t.times():
        iter_list.append(val)

    # Check results
    assert ([0, 1, 2, 3] == iter_list)
예제 #7
0
def test_str_id():
    # Store some time series data
    t1 = SMTimeSeries([1, 2, 3], [4, 5, 6], 'hi')
    t2 = SMTimeSeries([0], [0], 'bye')

    assert t1._id == 'hi'
    assert t2._id == 'bye'

    assert ((np.array([4, 5, 6]) == FSM_global.get('hi').values()).all())
    assert ((np.array([0]) == FSM_global.get('bye').values()).all())
예제 #8
0
def test_int_id():
    # Store some time series data
    t1 = SMTimeSeries([1, 2, 3], [4, 5, 6], 1)
    t2 = SMTimeSeries([0], [0], 2)

    assert t1._id == '1'
    assert t2._id == '2'

    assert ((np.array([4, 5, 6]) == FSM_global.get(1).values()).all())
    assert ((np.array([0]) == FSM_global.get(2).values()).all())
예제 #9
0
def test_sub_valid_int():
    t1 = SMTimeSeries(range(3), [10, 10, 10])
    t2 = SMTimeSeries(range(3), [1, 2, 3])

    ans = t1 - t2
    real_ans = SMTimeSeries(range(3), [9, 8, 7])
    assert (np.array_equal(real_ans.values(), ans.values()))
    assert (np.array_equal(real_ans.times(), ans.times()))
예제 #10
0
def test_add_valid_int():
    t1 = SMTimeSeries(range(5), [1, 2, 3, 4, 5])
    t2 = SMTimeSeries(range(5), [1, 1, 1, 1, 1])

    ans = t1 + t2
    real_ans = SMTimeSeries(range(5), [2, 3, 4, 5, 6])
    assert (np.array_equal(real_ans.values(), ans.values()))
    assert (np.array_equal(real_ans.times(), ans.times()))
예제 #11
0
def test_mul_ints():
    t1 = SMTimeSeries(range(3), [10, 10, 10])
    t2 = SMTimeSeries(range(3), [1, 2, 3])
    ans = t1 * t2

    real_ans = SMTimeSeries(range(3), [10, 20, 30])

    assert (np.array_equal(real_ans.values(), ans.values()))
    assert (np.array_equal(real_ans.times(), ans.times()))
예제 #12
0
def test_std_single_val():
    t = SMTimeSeries([4], [42])
    assert (t.std() == 0)
예제 #13
0
def test_mean_chunk():
    t = SMTimeSeries(range(20), range(20))
    assert (t.mean(chunk=1) == 0)
    assert (t.mean(chunk=3) == 1)
    assert (t.mean(chunk=20) == 9.5)
예제 #14
0
def test_len():
    t1 = SMTimeSeries([1, 2, 3], [1, 2, 3], 3)

    assert (len(t1) == 3)
예제 #15
0
def test_from_db():
    t1 = SMTimeSeries([1, 2, 3], [1, 2, 3], 3)

    t_from_db = t1.from_db('hi')
    assert ((np.array([4, 5, 6]) == t_from_db.values()).all())
예제 #16
0
def test_bool_true():
    t = SMTimeSeries(range(4), [1, 1, 1, 1])
    assert (abs(t))
예제 #17
0
def test_abs_nonint_result():
    t = SMTimeSeries(range(3), [1, 2, 3])
    assert (abs(t), math.sqrt(1 + 4 + 9))
예제 #18
0
def test_std_equal_val():
    t = SMTimeSeries([4, 5, 6, 7, 8], [1, 1, 1, 1, 1])
    assert (t.std() == 0)
예제 #19
0
def test_std_larger():
    t = SMTimeSeries(range(20), range(20))
    assert (t.std() == np.std(np.array(range(20))))
예제 #20
0
def test_time_input_numeric():
    with raises(TypeError):
        SMTimeSeries(['a', 'b'], [1, 2])
예제 #21
0
def test_time_value_diff_length():
    with raises(ValueError):
        SMTimeSeries([1, 2, 3], [1, 2])
예제 #22
0
def test_time_input_sequence():
    with raises(TypeError):
        SMTimeSeries(12, [1, 2])
예제 #23
0
def test_value_input_numeric():
    with raises(TypeError):
        SMTimeSeries([1, 2], ['a', 'b'])
예제 #24
0
def test_bool_false():
    t = SMTimeSeries(range(1), [0])
    assert (not abs(t))
예제 #25
0
def test_value_input_sequence():
    with raises(TypeError):
        SMTimeSeries([1, 2], 12)
예제 #26
0
def test_bool_empty():
    t = SMTimeSeries([], [])
    assert (not abs(t))
예제 #27
0
def test_from_db_no_id():
    t1 = SMTimeSeries([1, 2, 3], [1, 2, 3], 3)

    with raises(KeyError):
        t1.from_db('hey')
예제 #28
0
def test_mean_single_val():
    t = SMTimeSeries([4], [42])
    assert (t.mean() == 42)
예제 #29
0
def test_len_empty():
    t1 = SMTimeSeries([], [], 3)

    assert (len(t1) == 0)
예제 #30
0
def test_mean_larger():
    t = SMTimeSeries(range(20), range(20))
    assert (t.mean() == 9.5)