Skip to content
Snippets Groups Projects
Commit 138d540b authored by “Daniel Griffiths”'s avatar “Daniel Griffiths”
Browse files

feat: added more tfidf tests

parent d96c5522
No related branches found
No related tags found
No related merge requests found
...@@ -39,7 +39,7 @@ class TestTfidfEncoder: ...@@ -39,7 +39,7 @@ class TestTfidfEncoder:
isinstance(sublist, list) for sublist in result isinstance(sublist, list) for sublist in result
), "Each item in result should be a list" ), "Each item in result should be a list"
def test_call_method_no_docs(self, tfidf_encoder): def test_call_method_no_docs_tfidf(self, tfidf_encoder):
with pytest.raises(ValueError): with pytest.raises(ValueError):
tfidf_encoder([]) tfidf_encoder([])
...@@ -60,3 +60,26 @@ class TestTfidfEncoder: ...@@ -60,3 +60,26 @@ class TestTfidfEncoder:
def test_call_method_with_uninitialized_model(self, tfidf_encoder): def test_call_method_with_uninitialized_model(self, tfidf_encoder):
with pytest.raises(ValueError): with pytest.raises(ValueError):
tfidf_encoder(["test"]) tfidf_encoder(["test"])
def test_call_method_no_docs(self, tfidf_encoder):
with pytest.raises(ValueError, match="No documents to encode."):
tfidf_encoder([])
def test_compute_tf_no_word_index(self, tfidf_encoder):
with pytest.raises(ValueError, match="Word index is not initialized."):
tfidf_encoder._compute_tf(["some docs"])
def test_compute_tf_with_word_in_word_index(self, tfidf_encoder):
routes = [
Route(
name="test_route",
utterances=["some docs", "and more docs", "and even more docs"],
)
]
tfidf_encoder.fit(routes)
tf = tfidf_encoder._compute_tf(["some docs"])
assert tf.shape == (1, len(tfidf_encoder.word_index))
def test_compute_idf_no_word_index(self, tfidf_encoder):
with pytest.raises(ValueError, match="Word index is not initialized."):
tfidf_encoder._compute_idf(["some docs"])
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment