Completed
Push — master ( 748d0e...582254 )
by Wouter
03:55
created

test_fit()   A

Complexity

Conditions 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
c 2
b 0
f 0
dl 0
loc 8
ccs 7
cts 7
cp 1
crap 2
rs 9.4285
1 1
import numpy as np
2 1
import numpy.random as rnd
3 1
from libtlda.suba import SubspaceAlignedClassifier
4
5
6 1
def test_init01():
7
    """Test for object type."""
8 1
    clf = SubspaceAlignedClassifier()
9 1
    assert type(clf) == SubspaceAlignedClassifier
10
11
12 1
def test_init02():
13
    """Test for is_trained model."""
14 1
    clf = SubspaceAlignedClassifier()
15 1
    assert not clf.is_trained
16
17
18 1
def test_fit():
19
    """Test for fitting the model."""
20 1
    X = rnd.randn(10, 2)
21 1
    y = np.hstack((-np.ones((5,)), np.ones((5,))))
22 1
    Z = rnd.randn(10, 2) + 1
23 1
    clf = SubspaceAlignedClassifier()
24 1
    clf.fit(X, y, Z)
25 1
    assert clf.is_trained
26
27
28 1 View Code Duplication
def test_predict():
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
29
    """Test for making predictions."""
30 1
    X = rnd.randn(10, 2)
31 1
    y = np.hstack((-np.ones((5,)), np.ones((5,))))
32 1
    Z = rnd.randn(10, 2) + 1
33 1
    clf = SubspaceAlignedClassifier()
34 1
    clf.fit(X, y, Z)
35 1
    u_pred = clf.predict(Z)
36 1
    labels = np.unique(y)
37
    assert len(np.setdiff1d(np.unique(u_pred), labels)) == 0
38