-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathoccurrences-after-bigram.py
33 lines (23 loc) · 1.06 KB
/
occurrences-after-bigram.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
class Solution:
def findOcurrences(self, text, first, second):
result = []
words = text.split(" ")
if len(words) < 3:
return result
for pos in range(2, len(words)):
if words[pos - 2] == first and words[pos - 1] == second:
result.append(words[pos])
return result
class TestSolution:
def setup(self):
self.sol = Solution()
def test_empty(self):
assert self.sol.findOcurrences("", "", "") == []
assert self.sol.findOcurrences("", "a", "a") == []
def test_custom1(self):
assert self.sol.findOcurrences("alice is a good girl she is a good student", "a", "good") == ["girl", "student"]
assert self.sol.findOcurrences("alice is a good girl she is a good stUdent", "a", "good") == ["girl", "stUdent"]
def test_custom2(self):
assert self.sol.findOcurrences("we will we will rock you", "we", "will") == ["we", "rock"]
def test_custom3(self):
assert self.sol.findOcurrences("a a a a a A a", "a", "a") == ["a", "a", "a", "A"]