Beispiel #1
0
def test_sort():
    idx = np.arange(0, 100.0)
    data = Data(idx, idx**2, "test")
    data.idx[:10] += 101
    data.sort()
    assert len(data) == 100
    assert all(np.diff(data.idx) > 0)
    assert all(data.rec[:90] == data.idx[:90]**2)
Beispiel #2
0
def test_cut_idx():
    idx = np.arange(0, 100.0)
    data = Data(idx, idx**2, "test")
    left, right = data.cut_idx(50)
    assert len(left) == 50
    assert len(right) == 50
    data2, data3 = left.merge(right)
    assert len(data3) == 0
    assert data2.compare(data)
Beispiel #3
0
def test_merge():
    idx = np.arange(0, 100.0)
    data = Data(idx, idx**2, "test")
    idx = np.array([0, 1, 2.5, 3.7, 4, 7, 8])
    data2 = Data(idx, idx**3)
    data3, data4 = data.merge(data2)
    for tt in idx:
        ii = data3.idx == tt
        assert data3.rec[ii] == data3.idx[ii]**3
    for tt in [0, 1, 4, 7, 8]:
        ii = data4.idx == tt
        assert data4.rec[ii] == data4.idx[ii]**2
Beispiel #4
0
def test_read_write(tmp_path):
    idx = np.arange(0, 100.0)
    data = Data(idx, idx ** 2, "test")
    page = Page.from_data(123, data)
    basedir = tmp_path
    page.write(data, basedir)
    page.check(basedir)
    page.delete(basedir)
Beispiel #5
0
def test_to_list():
    idx = np.arange(0, 100.0)
    data = Data(idx, idx ** 2, "test")
    page = Page.from_data(123, data)
    page2 = Page(*page.to_list())
    check_same(page, page2)
Beispiel #6
0
def test_page():
    idx = np.arange(0, 100.0)
    data = Data(idx, idx ** 2, "test")
    page = Page.from_data(123, data)
    page.check_with_data(data)
Beispiel #7
0
def mk_data(a, b, n, name):
    idx = np.linspace(a, b, n)
    rec = idx**3
    return Data(idx, rec, name)
Beispiel #8
0
def test_filter():
    idx = np.arange(0, 100.0)
    data = Data(idx, idx**2, "test")
    data1 = data.filter(data.rec % 2 == 0)
    assert all(data1.rec % 2 == 0)
    assert all(data1.rec == data1.idx**2)
Beispiel #9
0
def test_append():
    idx = np.arange(0, 100.0)
    data = Data(idx, idx**2, "test")
    left, right = data.cut_idx(50)
    left.append(right)
    assert left.compare(data)
Beispiel #10
0
def test_trim():
    idx = np.arange(0, 100.0)
    data = Data(idx, idx**2, "test")
    data1 = data.trim(13, 15)
    assert all(data1.idx == [13, 14, 15])
    assert all(data1.rec == data1.idx**2)
Beispiel #11
0
def test_cut_nbytes():
    idx = np.arange(0, 100.0)
    data = Data(idx, idx**2, "test")
    left, right = data.cut_nbytes(280)
    assert left.get_size() <= 280
    assert right.get_size() > 280
Beispiel #12
0
def test_cut_lt():
    idx = np.arange(0, 100.0)
    data = Data(idx, idx**2, "test")
    left, right = data.cut_lt(30.0)
    assert left.idx[-1] == 29.0
    assert right.idx[0] == 30.0