-
Notifications
You must be signed in to change notification settings - Fork 17
/
camelcase-matching.py
50 lines (33 loc) · 1.62 KB
/
camelcase-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
import unittest
class Solution:
def check(self, query, pattern):
pattern_pos = 0
for q in query:
if pattern_pos < len(pattern) and q == pattern[pattern_pos]:
pattern_pos += 1
else:
if q.upper() == q:
return False
return pattern_pos == len(pattern)
def camelMatch(self, queries, pattern):
result = []
for query in queries:
result.append(self.check(query, pattern))
return result
class TestSolution(unittest.TestCase):
def setUp(self):
self.sol = Solution()
def test_empty1(self):
self.assertListEqual(self.sol.camelMatch([], ""), [])
def test_empty2(self):
self.assertListEqual(self.sol.camelMatch([], "FB"), [])
def test_custom1(self):
self.assertListEqual(self.sol.camelMatch(["FooBar","FooBarTest","FootBall","FrameBuffer","ForceFeedBack"], "FB"), [True,False,True,True,False])
def test_custom2(self):
self.assertListEqual(self.sol.camelMatch(["FooBar","FooBarTest","FootBall","FrameBuffer","ForceFeedBack"], "FoBa"), [True,False,True,False,False])
def test_custom3(self):
self.assertListEqual(self.sol.camelMatch(["FooBar","FooBarTest","FootBall","FrameBuffer","ForceFeedBack","FooBarTestT"], "FoBaT"), [False,True,False,False,False,False])
def test_custom4(self):
self.assertListEqual(self.sol.camelMatch(["kqshppmjgjfB","mkqsthpypmgB","kqshppmtgttB","lklqsphppmgB","kqesshppwmgB","kqshpzlcpmgB","kqsyhppmhfgB"], "kqshppmgB"), [True,True,True,True,True,True,True])
if __name__ == "__main__":
unittest.main()