Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[patch:test] Add docstrings to test cases #115

Merged
merged 18 commits into from
Dec 28, 2020
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
7695019
[release] 0.7.1 🎉 (#94)
eonu May 21, 2020
6072ebb
Merge branch 'master' into dev
eonu May 21, 2020
16ecb2b
Merge branch 'dev' of https://github.com/eonu/sequentia into dev
eonu Jul 7, 2020
9dfd62b
Merge branch 'dev' of https://github.com/eonu/sequentia into dev
eonu Jul 7, 2020
35abe17
Merge branch 'dev' of https://github.com/eonu/sequentia into dev
eonu Jul 7, 2020
91fe63e
Merge branch 'dev' of https://github.com/eonu/sequentia into dev
eonu Aug 24, 2020
43492e0
Merge branch 'dev' of https://github.com/eonu/sequentia into dev
eonu Aug 24, 2020
cad2810
Merge branch 'dev' of https://github.com/eonu/sequentia into dev
eonu Dec 25, 2020
e91a834
Merge branch 'dev' of https://github.com/eonu/sequentia into dev
eonu Dec 27, 2020
fa790dc
Merge branch 'dev' of https://github.com/eonu/sequentia into dev
eonu Dec 28, 2020
c8a88d6
Merge branch 'dev' of https://github.com/eonu/sequentia into dev
eonu Dec 28, 2020
8009527
Merge branch 'dev' of https://github.com/eonu/sequentia into dev
eonu Dec 28, 2020
6d99f04
Merge branch 'dev' of https://github.com/eonu/sequentia into dev
eonu Dec 28, 2020
e72d662
Merge branch 'dev' of https://github.com/eonu/sequentia into dev
eonu Dec 28, 2020
688ec2e
Merge branch 'dev' of https://github.com/eonu/sequentia into dev
eonu Dec 28, 2020
f3ede88
Merge branch 'dev' of https://github.com/eonu/sequentia into dev
eonu Dec 28, 2020
ae2b38a
Merge branch 'dev' of https://github.com/eonu/sequentia into dev
eonu Dec 28, 2020
2b1d301
Add docstrings to test cases
eonu Dec 28, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/test/lib/classifiers/hmm/test_hmm_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,17 @@ def test_predict_single_frequency_prior():
assert prediction == 4

def test_predict_single_uniform_prior():
"""Predict a single observation sequence with a uniform prior"""
prediction = hmm_clf.predict(x, prior='uniform', return_scores=False, original_labels=False)
assert prediction == 4

def test_predict_single_custom_prior():
"""Predict a single observation sequence with a custom prior"""
prediction = hmm_clf.predict(x, prior=([1-4e-10]+[1e-10]*4), return_scores=False, original_labels=False)
assert prediction == 0

def test_predict_single_return_scores():
"""Predict a single observation sequence and return the transformed label, with the un-normalized posterior scores"""
prediction = hmm_clf.predict(x, prior='frequency', return_scores=True, original_labels=False)
assert isinstance(prediction, tuple)
assert prediction[0] == 4
Expand All @@ -79,10 +82,12 @@ def test_predict_single_return_scores():
]))

def test_predict_single_original_labels():
"""Predict a single observation sequence and return the original label, without the un-normalized posterior scores"""
prediction = hmm_clf.predict(x, prior='uniform', return_scores=False, original_labels=True)
assert prediction == 'c4'

def test_predict_single_return_scores_original_labels():
"""Predict a single observation sequence and return the original label, with the un-normalized posterior scores"""
prediction = hmm_clf.predict(x, prior='frequency', return_scores=True, original_labels=True)
assert isinstance(prediction, tuple)
assert prediction[0] == 'c4'
Expand All @@ -96,14 +101,17 @@ def test_predict_multiple_frequency_prior():
assert_equal(predictions, np.array([4, 4, 0]))

def test_predict_multiple_uniform_prior():
"""Predict multiple observation sequences with a uniform prior"""
predictions = hmm_clf.predict(X, prior='uniform', return_scores=False, original_labels=False)
assert_equal(predictions, np.array([4, 4, 0]))

def test_predict_multiple_custom_prior():
"""Predict multiple observation sequences with a custom prior"""
predictions = hmm_clf.predict(X, prior=([1-4e-10]+[1e-10]*4), return_scores=False, original_labels=False)
assert_equal(predictions, np.array([0, 0, 0]))

def test_predict_multiple_return_scores():
"""Predict multiple observation sequences and return the transformed labels, with the un-normalized posterior scores"""
predictions = hmm_clf.predict(X, prior='frequency', return_scores=True, original_labels=False)
assert isinstance(predictions, tuple)
assert_equal(predictions[0], np.array([4, 4, 0]))
Expand All @@ -114,10 +122,12 @@ def test_predict_multiple_return_scores():
]))

def test_predict_multiple_original_labels():
"""Predict multiple observation sequences and return the original labels, without the un-normalized posterior scores"""
predictions = hmm_clf.predict(X, prior='frequency', return_scores=False, original_labels=True)
assert all(np.equal(predictions.astype(object), np.array(['c4', 'c4', 'c0'], dtype=object)))

def test_predict_multiple_return_scores_original_labels():
"""Predict multiple observation sequences and return the original labels, with the un-normalized posterior scores"""
predictions = hmm_clf.predict(X, prior='frequency', return_scores=True, original_labels=True)
assert isinstance(predictions, tuple)
assert all(np.equal(predictions[0].astype(object), np.array(['c4', 'c4', 'c0'], dtype=object)))
Expand All @@ -132,6 +142,7 @@ def test_predict_multiple_return_scores_original_labels():
# ======================== #

def test_evaluate():
"""Evaluate performance on some observation sequences and labels"""
acc, cm = hmm_clf.evaluate(X, Y, prior='frequency')
assert acc == 0.0
assert_equal(cm, np.array([
Expand All @@ -147,6 +158,7 @@ def test_evaluate():
# ===================================== #

def test_serialization():
"""Serialize and deserialize the classifier"""
model_file = 'test.pkl'
try:
with open(model_file, 'wb') as file:
Expand Down