Example #1
0
def test_blend_array_shape():
    """[Base] BlendIndex: test the array shape on generation."""
    tr = np.array([0, 1])
    te = np.array([2, 3])

    for tri, tei in BlendIndex(0.45, 0.55, X=X).generate(as_array=True):

        np.testing.assert_array_equal(tri, tr)
        np.testing.assert_array_equal(tei, te)
Example #2
0
def test_blend_index_is_fitted():
    """[Base] BlendIndex: check fit methods."""
    attrs = ['n_samples', 'n_test_samples', 'n_train', 'n_test']

    idx = BlendIndex(2, 3)
    for attr in attrs: assert not hasattr(idx, attr)
    idx.fit(X)
    for attr in attrs: assert hasattr(idx, attr)

    idx = BlendIndex(2, 3)
    for attr in attrs: assert not hasattr(idx, attr)
    for _ in idx.generate(X): pass
    for attr in attrs: assert hasattr(idx, attr)

    idx = BlendIndex(2, 3, X=X)
    for attr in attrs: assert hasattr(idx, attr)
Example #3
0
def test_blend_raises_empty_train():
    """[Base] BlendIndex: check raises error on empty train set."""
    with np.testing.assert_raises(ValueError):
        BlendIndex(10, 0, X=X)
Example #4
0
def test_blend_raises_on_empty():
    """[Base] BlendIndex: check raises error on singular array."""
    with np.testing.assert_raises(ValueError):
        BlendIndex(2, 2, X=np.empty(1))
Example #5
0
def test_blend_raises_on_oversampling():
    """[Base] BlendIndex: check raises error on float sums > 1.0."""
    for tup in [(1.2, None), (0.6, 0.6)]:
        with np.testing.assert_raises(ValueError):
            BlendIndex(*tup, X=X)
Example #6
0
def test_blend_tuple_shape():
    """[Base] BlendIndex: test the tuple shape on generation."""
    tup = [(tri, tei) for tri, tei in BlendIndex(0.4, 0.5).generate(X)]

    assert tup == [((0, 2), (2, 4))]