Skip to content

Commit

Permalink
Use numpy assert allclose for array testing (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
pkeilbach authored Dec 20, 2023
1 parent 6e7c247 commit f269d6b
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions tests/htwgnlp/test_naive_bayes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pandas as pd
import pytest

from htwgnlp.naive_bayes import NaiveBayes
from htwgnlp.naive_bayes_private import NaiveBayes

model = NaiveBayes()

Expand Down Expand Up @@ -107,7 +107,8 @@ def trained_log_ratios(train_samples, train_samples_labels):
)
def test_set_logprior(labels, expected):
model.logprior = labels
assert model.logprior == expected
np.testing.assert_allclose(model.logprior, expected)
# assert model.logprior == expected


@pytest.mark.parametrize(
Expand Down Expand Up @@ -171,15 +172,15 @@ def test_get_log_ratios(trained_log_ratios):
assert isinstance(trained_log_ratios, pd.Series)
assert trained_log_ratios.index.size == 9

assert trained_log_ratios.loc["happy"] == np.log(0.15 / 0.05)
assert trained_log_ratios.loc["sad"] == np.log(0.05 / 0.15)
assert trained_log_ratios.loc["love"] == np.log(0.1 / 0.05)
assert trained_log_ratios.loc["hate"] == np.log(0.05 / 0.1)
assert trained_log_ratios.loc["weather"] == 0.0
assert trained_log_ratios.loc["I"] == 0.0
assert trained_log_ratios.loc["am"] == 0.0
assert trained_log_ratios.loc["because"] == 0.0
assert trained_log_ratios.loc["the"] == 0.0
np.testing.assert_allclose(trained_log_ratios.loc["happy"], np.log(0.15 / 0.05))
np.testing.assert_allclose(trained_log_ratios.loc["sad"], np.log(0.05 / 0.15))
np.testing.assert_allclose(trained_log_ratios.loc["love"], np.log(0.1 / 0.05))
np.testing.assert_allclose(trained_log_ratios.loc["hate"], np.log(0.05 / 0.1))
np.testing.assert_allclose(trained_log_ratios.loc["weather"], 0.0)
np.testing.assert_allclose(trained_log_ratios.loc["I"], 0.0)
np.testing.assert_allclose(trained_log_ratios.loc["am"], 0.0)
np.testing.assert_allclose(trained_log_ratios.loc["because"], 0.0)
np.testing.assert_allclose(trained_log_ratios.loc["the"], 0.0)


@pytest.mark.parametrize(
Expand Down

0 comments on commit f269d6b

Please sign in to comment.