-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_matching.py
79 lines (58 loc) · 2.62 KB
/
test_matching.py
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
68
69
70
71
72
73
74
75
76
77
78
from unittest import TestCase
from matching import *
class Test(TestCase):
def test_search(self):
self.assertEqual(['red and yellow'],
search('red', ['red and yellow', 'blue and yellow', 'predict color']))
def test_string_match__matches(self):
self.assertTrue(string_match('red', 'red and yellow'))
def test_string_match__dont_match(self):
self.assertFalse(string_match('red', 'yellow and blue'))
def test_string_match__match_substring(self):
self.assertTrue(string_match('red', 'predict color'))
#Search
#Empty string as a query
def test_search__empty_string_query(self):
self.assertEqual([], search("", ['red and yellow', 'blue and yellow', 'predict color']))
#Empty string as a document
def test_search__empty_string_document(self):
self.assertEqual([], search("red and yellow", ""))
# Empty document list
def test_search__empty_document_list(self):
self.assertEqual([], search("red and yellow", []))
#Boolean Match
def test_boolean_term_match__matches(self):
self.assertTrue(string_match('red', 'red and yellow'))
def test_boolean_term_match__dont_match(self):
self.assertFalse(string_match('red', 'yellow and blue'))
def test_boolean_term_match__match_substring(self):
self.assertTrue(string_match('red', 'predict color'))
#Empty query
def test_boolean_term_match__empty_query(self):
self.assertFalse(boolean_term_match("", "red"))
#Empty document
def test_boolean_term_match__empty_document(self):
self.assertFalse(boolean_term_match("red", ""))
#Multi Doc
def test_string_match__multi_document(self):
self.assertTrue("yellow and red", "red")
#String Match
#Empty Query
def test_string_match__empty_query(self):
self.assertFalse(string_match("", "red"))
#Empty Doc and doc list (these are the same so i didn't add another one)
def test_string_match__empty_document(self):
self.assertFalse(string_match("red", ""))
#Multi Doc
def test_string_match__multi_document(self):
self.assertTrue("yellow and red", "red")
#Search String match unexpected result
def test_string_match_unexpected_result(self):
query = 'red'
document = 'predict color'
self.assertTrue(string_match(query, document))
self.assertFalse(search(query, [document]) == document)
#Differentiate string and boolean matching
def test_matching_function_difference(self):
self.assertTrue(string_match("red", "[red and yellow]"))
self.assertFalse(boolean_term_match("red", "[red and yellow]"))