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()
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())
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])))
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)
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())
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)
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())
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())
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()))
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()))
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()))
def test_std_single_val(): t = SMTimeSeries([4], [42]) assert (t.std() == 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)
def test_len(): t1 = SMTimeSeries([1, 2, 3], [1, 2, 3], 3) assert (len(t1) == 3)
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())
def test_bool_true(): t = SMTimeSeries(range(4), [1, 1, 1, 1]) assert (abs(t))
def test_abs_nonint_result(): t = SMTimeSeries(range(3), [1, 2, 3]) assert (abs(t), math.sqrt(1 + 4 + 9))
def test_std_equal_val(): t = SMTimeSeries([4, 5, 6, 7, 8], [1, 1, 1, 1, 1]) assert (t.std() == 0)
def test_std_larger(): t = SMTimeSeries(range(20), range(20)) assert (t.std() == np.std(np.array(range(20))))
def test_time_input_numeric(): with raises(TypeError): SMTimeSeries(['a', 'b'], [1, 2])
def test_time_value_diff_length(): with raises(ValueError): SMTimeSeries([1, 2, 3], [1, 2])
def test_time_input_sequence(): with raises(TypeError): SMTimeSeries(12, [1, 2])
def test_value_input_numeric(): with raises(TypeError): SMTimeSeries([1, 2], ['a', 'b'])
def test_bool_false(): t = SMTimeSeries(range(1), [0]) assert (not abs(t))
def test_value_input_sequence(): with raises(TypeError): SMTimeSeries([1, 2], 12)
def test_bool_empty(): t = SMTimeSeries([], []) assert (not abs(t))
def test_from_db_no_id(): t1 = SMTimeSeries([1, 2, 3], [1, 2, 3], 3) with raises(KeyError): t1.from_db('hey')
def test_mean_single_val(): t = SMTimeSeries([4], [42]) assert (t.mean() == 42)
def test_len_empty(): t1 = SMTimeSeries([], [], 3) assert (len(t1) == 0)
def test_mean_larger(): t = SMTimeSeries(range(20), range(20)) assert (t.mean() == 9.5)