/
tests.py
42 lines (39 loc) · 1.2 KB
/
tests.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
import fuzzy
import unittest
class TestFuzzyMatching(unittest.TestCase):
def test_ratio_1(self):
x = 'test'
y = 'test'
assert(fuzzy.ratio(x,y) == 1.0)
def test_ratio_2(self):
x = 'test'
y = 'TEST'
assert(fuzzy.ratio(x,y) == 0.0)
def test_ratio_3(self):
x = 'this is very similar'
y = 'this is very similer'
assert(fuzzy.ratio(x,y) > 0.9)
def test_ratio_4(self):
x = 'this is not very similar'
y = 'here lies a random diff string'
assert(fuzzy.ratio(x,y) < 0.5)
def test_partial_1(self):
x = 'this is longer'
y = 'is lo'
assert(fuzzy.partial_ratio(x,y) == 1.0)
def test_partial_2(self):
x = 'front matchers'
y = 'front'
assert(fuzzy.partial_ratio(x,y) == 1.0)
def test_partial_3(self):
x = 'matchbackend'
y = 'backend'
assert(fuzzy.partial_ratio(x,y) == 1.0)
def test_partial_4(self):
x = 'reverse'
y = 'the reverse is longer'
assert(fuzzy.partial_ratio(x,y) == 1.0)
def test_partial_5(self):
x = 'hump'
y = 'the reverse is longer'
assert(fuzzy.partial_ratio(x,y) < 0.5)