-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCheckPermutation.py
53 lines (41 loc) · 1.12 KB
/
CheckPermutation.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
__author__ = 'lanceli'
import unittest
from collections import Counter
def checkIfPermutation(string1, string2):
if len(string1) != len(string2):
return False
counter = Counter()
for char in string1:
print("char is :", char)
if char not in string2 :
return False
else :
counter[char] += 1
for char in counter:
print("counter[", char, "] is ", counter[char])
if counter[char] != 1:
return False
return True
class Test(unittest.TestCase):
dataT = (
('abcd', 'bacd'),
('3563476', '7334566'),
('wef34f', 'wffe34'),
)
dataF = (
('abcd', 'd2cba'),
('2354', '1234'),
('dcw4f', 'dcw5f'),
)
tmux
def test_cp(self):
# true check
for test_strings in self.dataT:
result = checkIfPermutation(*test_strings)
self.assertTrue(result)
# false check
for test_strings in self.dataF:
result = checkIfPermutation(*test_strings)
self.assertFalse(result)
if __name__ == "__main__":
unittest.main()