-
Notifications
You must be signed in to change notification settings - Fork 2
/
unit_tests.py
86 lines (58 loc) · 2.2 KB
/
unit_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
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
79
80
81
82
83
84
85
86
#!/bin/env python
"""
Unit tests for Craigslist project
"""
import unittest
import load_pages as lp
reload(lp)
class Test_find_model(unittest.TestCase):
def setUp(self):
self.models = set(["accord", "camry", "civic", "corolla"])
def test_basic(self):
self.assertEqual(
lp.find_model(
"my honda accord",
self.models),
'accord')
def test_case_insensitive(self):
self.assertEqual(
lp.find_model(
"my honda Accord",
self.models),
'accord')
def test_non_model(self):
self.assertEqual(lp.find_model("Harley", self.models), None)
class Test_find_year(unittest.TestCase):
def test_basic(self):
self.assertEqual(lp.find_year("hello 1999"), 1999)
def test_skip_too_high(self):
self.assertEqual(lp.find_year("2015 2014"), 2014)
def test_skip_too_low(self):
self.assertEqual(lp.find_year("1979 2014"), 2014)
def test_return_only_one(self):
self.assertEqual(lp.find_year("2013 2014"), 2013)
def test_return_none(self):
self.assertEqual(lp.find_year("1979"), None)
class Test_find_miles(unittest.TestCase):
def test_basic(self):
self.assertEqual(lp.find_miles("I have 20000 miles"), 20000)
def test_case_insensitive(self):
self.assertEqual(lp.find_miles("I have 20000 Miles"), 20000)
def test_comma(self):
self.assertEqual(lp.find_miles("I have 20,000 miles"), 20000)
def test_pre(self):
self.assertEqual(lp.find_miles("my miles: 20,000"), 20000)
def test_mileage(self):
self.assertEqual(lp.find_miles("my mileage: 20,000 xx"), 20000)
def test_spaces(self):
self.assertEqual(lp.find_miles("mileage 20,000 adsfadsf"), 20000)
def test_characters1(self):
self.assertEqual(lp.find_miles("mileage,, 20,000 adsfadsf"), 20000)
def test_characters2(self):
self.assertEqual(lp.find_miles("20,000 .?miles"), 20000)
def test_k(self):
self.assertEqual(lp.find_miles("20k .?miles"), 20000)
def test_island(self):
self.assertEqual(lp.find_miles("20,000"), None)
if __name__ == "__main__":
unittest.main()