Skip to content

Commit 7538ade

Browse files
authored
Merge pull request #48 from lhchavez/unittest
This change standardizes all Python files so that they can run using the unittest module.
2 parents e74872a + 72cc532 commit 7538ade

File tree

86 files changed

+639
-448
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+639
-448
lines changed

Python/chapter01/1.1 - Is Unique/camilo_sol.py renamed to Python/chapter01/1.1 - Is Unique/camilosalazar98.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
characters. What if you cannot use additional data structures?
44
"""
55

6+
import unittest
7+
8+
#This soluation is O(n^2)
69

710
def isUnique(string_):
811
for i in range(len(string_)):
@@ -12,8 +15,6 @@ def isUnique(string_):
1215
return False
1316
return True
1417

15-
print(isUnique("GeeksforGeeks"))
16-
#This soluation is O(n^2)
1718

1819
#let's see if we can go faster
1920

@@ -30,4 +31,14 @@ def isUnique_(string_):
3031
return False
3132
return True
3233

33-
print(isUnique_("camilo"))
34+
35+
class Test(unittest.TestCase):
36+
def test_quadradic(self):
37+
self.assertFalse(isUnique("GeeksforGeeks"))
38+
39+
def test_linear(self):
40+
self.assertTrue(isUnique_("camilo"))
41+
42+
43+
if __name__ == '__main__':
44+
unittest.main()

Python/chapter01/1.1 - Is Unique/Q1.1.py renamed to Python/chapter01/1.1 - Is Unique/ismael_duran.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import unittest
12

23
# Note that this solution assumes a unique string
34
# implies a lowercase letter and the uppercase of
@@ -15,13 +16,18 @@ def uniqueChar(passedStr):
1516

1617
# If the string had unique characters the string
1718
# length remains the same
18-
# If the string has duplicates then size
19+
# If the string has duplicates then size
1920
if len(deleteDuplicateIfAny) == len(passedStr):
2021
return "Unique"
2122
else:
2223
return "Not Unique"
2324

2425

25-
example = "Helloh"
26+
class Test(unittest.TestCase):
27+
def test_uniqueChar(self):
28+
example = "Helloh"
29+
self.assertEqual(uniqueChar(example), "Not Unique")
2630

27-
print(uniqueChar(example))
31+
32+
if __name__ == '__main__':
33+
unittest.main()

Python/chapter01/1.1 - Is Unique/lomeli_1.1.py renamed to Python/chapter01/1.1 - Is Unique/lomeli_noe.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# are 128 unique values.
66

77
import array
8+
import unittest
89

910
def isUnique(str):
1011

@@ -26,5 +27,11 @@ def isUnique(str):
2627
return True
2728

2829

29-
print("%s" % (isUnique("test")))
30-
print("%s" % (isUnique("abc123")))
30+
class Test(unittest.TestCase):
31+
def test_is_unique(self):
32+
self.assertFalse(isUnique("test"))
33+
self.assertTrue(isUnique("abc123"))
34+
35+
36+
if __name__ == '__main__':
37+
unittest.main()

Python/chapter01/1.1 - Is Unique/solution.py

Whitespace-only changes.

Python/chapter01/1.2 - Check Perm/Q1.2.py

Lines changed: 0 additions & 18 deletions
This file was deleted.

Python/chapter01/1.2 - Check Perm/camilo_sol_1.2.py renamed to Python/chapter01/1.2 - Check Perm/camilosalazar98.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
one is a permutation of the other.
44
"""
55

6+
import unittest
67

78

8-
9+
#O(n) sol?
910
def perm_check(str_1,str_2):
1011
if len(str_1) != len(str_2):#If both str are diiferent lenghts return false
1112
return False
@@ -29,9 +30,12 @@ def perm_check(str_1,str_2):
2930
return True
3031

3132

32-
#O(n) sol?
33-
print(perm_check("camilo","pop")) #False
33+
class Test(unittest.TestCase):
34+
def test_perm_check(self):
35+
self.assertFalse(perm_check("camilo","pop"))
36+
self.assertFalse(perm_check("camilo","camplo"))
37+
self.assertTrue(perm_check("camilo","olimac"))
3438

35-
print(perm_check("camilo","camplo")) #false
3639

37-
print(perm_check("camilo","olimac")) #True
40+
if __name__ == '__main__':
41+
unittest.main()
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import unittest
2+
3+
4+
def check_perm(example, example2):
5+
for letter in example:
6+
if letter in example2:
7+
index = example2.index(letter)
8+
example2 = example2[:index] + example2[index+1:]
9+
10+
if example2 == '':
11+
return True
12+
else:
13+
continue
14+
else:
15+
return False
16+
17+
18+
class Test(unittest.TestCase):
19+
def test_perm_check(self):
20+
self.assertFalse(check_perm("hello", "ehloe"))
21+
22+
23+
if __name__ == '__main__':
24+
unittest.main()
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Given two strings, write a method to decide if one is a permutation of the other
22

3+
import unittest
4+
35
def isPermutation(str1, str2):
46
if len(str1) != len(str2):
57
return False
@@ -9,5 +11,12 @@ def isPermutation(str1, str2):
911

1012
return sort1 == sort2
1113

12-
print("%s" % (isPermutation("stop", "pots")))
13-
print("%s" % (isPermutation("stops", "ponds")))
14+
15+
class Test(unittest.TestCase):
16+
def test_perm_check(self):
17+
self.assertTrue(isPermutation("stop", "pots"))
18+
self.assertFalse(isPermutation("stops", "ponds"))
19+
20+
21+
if __name__ == '__main__':
22+
unittest.main()

0 commit comments

Comments
 (0)