-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathtest_tfidf.py
More file actions
67 lines (47 loc) · 1.32 KB
/
test_tfidf.py
File metadata and controls
67 lines (47 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# -*- coding: utf-8 -*-
"""
Pytest test cases for tfidf.py
@author: 4oh4
28/03/2020
"""
from numpy.testing import assert_almost_equal
from hypothesis import given
from hypothesis.strategies import text
from tfidf import rank_documents
def test_rank_documents1():
"""
Test similarity match - positive control
"""
# given
search_terms = 'hello world'
documents = [search_terms]
# when
result = rank_documents(search_terms, documents)
# then
assert_almost_equal(result, [1])
@given(search_terms=text())
def test_rank_documents2(search_terms):
"""
Test similarity match - fuzzing
"""
# given
documents = ['the quick brown fox jumped over the lazy dog', 'Joe Jackson dances in Paris']
# when
result = rank_documents(search_terms, documents)
# then
assert isinstance(result, list)
for item in result:
assert isinstance(item, float)
@given(search_terms=text(), document1=text(), document2=text())
def test_rank_documents3(search_terms, document1, document2):
"""
Test similarity match - fuzzing
"""
# given
documents = [document1, document2]
# when
result = rank_documents(search_terms, documents)
# then
assert isinstance(result, list)
for item in result:
assert isinstance(item, float)