Skip to content

Commit 138d540

Browse files
committed
feat: added more tfidf tests
1 parent d96c552 commit 138d540

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

tests/unit/encoders/test_tfidf.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def test_call_method(self, tfidf_encoder):
3939
isinstance(sublist, list) for sublist in result
4040
), "Each item in result should be a list"
4141

42-
def test_call_method_no_docs(self, tfidf_encoder):
42+
def test_call_method_no_docs_tfidf(self, tfidf_encoder):
4343
with pytest.raises(ValueError):
4444
tfidf_encoder([])
4545

@@ -60,3 +60,26 @@ def test_call_method_no_word(self, tfidf_encoder):
6060
def test_call_method_with_uninitialized_model(self, tfidf_encoder):
6161
with pytest.raises(ValueError):
6262
tfidf_encoder(["test"])
63+
64+
def test_call_method_no_docs(self, tfidf_encoder):
65+
with pytest.raises(ValueError, match="No documents to encode."):
66+
tfidf_encoder([])
67+
68+
def test_compute_tf_no_word_index(self, tfidf_encoder):
69+
with pytest.raises(ValueError, match="Word index is not initialized."):
70+
tfidf_encoder._compute_tf(["some docs"])
71+
72+
def test_compute_tf_with_word_in_word_index(self, tfidf_encoder):
73+
routes = [
74+
Route(
75+
name="test_route",
76+
utterances=["some docs", "and more docs", "and even more docs"],
77+
)
78+
]
79+
tfidf_encoder.fit(routes)
80+
tf = tfidf_encoder._compute_tf(["some docs"])
81+
assert tf.shape == (1, len(tfidf_encoder.word_index))
82+
83+
def test_compute_idf_no_word_index(self, tfidf_encoder):
84+
with pytest.raises(ValueError, match="Word index is not initialized."):
85+
tfidf_encoder._compute_idf(["some docs"])

0 commit comments

Comments
 (0)