for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
import numpy as np
import numpy.random as rnd
from libtlda.suba import SubspaceAlignedClassifier
def test_init():
"""Test for object type."""
clf = SubspaceAlignedClassifier()
assert type(clf) == SubspaceAlignedClassifier
assert not clf.is_trained
def test_subspace_alignment():
"""Test the alignment between datasets."""
X = rnd.randn(100, 10)
Z = np.dot(rnd.randn(100, 10), np.diag(np.arange(1, 11)))
V, CX, CZ = clf.subspace_alignment(X, Z, num_components=3)
assert not np.any(np.isnan(V))
assert CX.shape[1] == 3
assert CZ.shape[1] == 3
def test_fit():
"""Test for fitting the model."""
X = rnd.randn(10, 2)
y = np.hstack((-np.ones((5,)), np.ones((5,))))
Z = rnd.randn(10, 2) + 1
clf.fit(X, y, Z)
assert clf.is_trained
def test_predict():
"""Test for making predictions."""
u_pred = clf.predict(Z)
labels = np.unique(y)
assert len(np.setdiff1d(np.unique(u_pred), labels)) == 0