Skip to content

Commit 6f2fbd0

Browse files
Merge branch 'master' into Almu
2 parents 39e7967 + 0416cab commit 6f2fbd0

24 files changed

+389
-29
lines changed

README.md

+69-8
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,75 @@ https://github.com/CatalinAnt/algorithms-SEP-95/commit/c16f26e952322b2c1729778a4
9292

9393

9494

95+
#### Ayman Errahmouni
96+
97+
##### Function 1: simplify_path_v2
98+
99+
[Link the commit](https://github.com/CatalinAnt/algorithms-SEP-95/pull/2/commits/22ee6fa1df4785596c603af61a725c558973eb0b)
100+
101+
Screenshot of branch measurement (66%):<br>
102+
![image](image-7.png)
103+
104+
##### Function 2: insertion_sort
105+
106+
[Link to commit](https://github.com/CatalinAnt/algorithms-SEP-95/pull/2/commits/5dae7f28036f89b7f6ff673639a922dd714aff3e)
107+
108+
Screenshot of branch measurement (0%, was untested):<br>
109+
![alt text](image-8.png)
110+
111+
#### Catalin Antonescu
112+
113+
##### Function 1: strong_password
114+
115+
Link to commit:
116+
[https://github.com/CatalinAnt/algorithms-SEP-95/commit/eaad6d32ecd73bb8fde876a4d4852cb522aea6f8](https://github.com/CatalinAnt/algorithms-SEP-95/commit/2b0b9187c1c040e4476b1ca14f2c2249273566b7)
117+
118+
Screenshot of branch measurement:
119+
![image](https://github.com/CatalinAnt/algorithms-SEP-95/assets/113595149/e718a47f-5ea0-412c-b250-25a193412164)
120+
121+
##### Function 2: rotate_image
122+
123+
Link to commit:(same as for the first one)
124+
[https://github.com/CatalinAnt/algorithms-SEP-95/commit/eaad6d32ecd73bb8fde876a4d4852cb522aea6f8](https://github.com/CatalinAnt/algorithms-SEP-95/commit/2b0b9187c1c040e4476b1ca14f2c2249273566b7)
125+
126+
Screenshot of branch measurement:
127+
![image](https://github.com/CatalinAnt/algorithms-SEP-95/assets/113595149/94eec9b6-3dd6-46e3-b087-40892eccc10e)
128+
129+
#### Abdullah Abdelkhalik
130+
131+
132+
pythagoras
133+
134+
https://github.com/CatalinAnt/algorithms-SEP-95/commit/5651abafebe8ae3a5ea63e74883bb991acf19303
135+
136+
![pythagoras_hits](https://github.com/CatalinAnt/algorithms-SEP-95/assets/114078193/0df1fa2b-2185-4b9f-ae65-5d969edb009b)
137+
138+
139+
first_unique_char
140+
141+
https://github.com/CatalinAnt/algorithms-SEP-95/commit/c16f26e952322b2c1729778a4141a57103ba7658
142+
143+
![first_unique_char_hits](https://github.com/CatalinAnt/algorithms-SEP-95/assets/114078193/10d7c45c-398e-4408-8f11-6771f51fa95c)
144+
145+
146+
#### Abdullah Abdelkhalik
147+
148+
149+
pythagoras
150+
151+
https://github.com/CatalinAnt/algorithms-SEP-95/commit/5651abafebe8ae3a5ea63e74883bb991acf19303
152+
153+
![pythagoras_hits](https://github.com/CatalinAnt/algorithms-SEP-95/assets/114078193/0df1fa2b-2185-4b9f-ae65-5d969edb009b)
154+
155+
156+
first_unique_char
157+
158+
https://github.com/CatalinAnt/algorithms-SEP-95/commit/c16f26e952322b2c1729778a4141a57103ba7658
159+
160+
![first_unique_char_hits](https://github.com/CatalinAnt/algorithms-SEP-95/assets/114078193/10d7c45c-398e-4408-8f11-6771f51fa95c)
161+
162+
163+
95164
## Coverage improvement
96165

97166
### Individual tests
@@ -174,7 +243,6 @@ New coverage:
174243

175244
For strong_password there was a 26% coverage improvement with the existing tool and 40% with manual measurement tool.
176245

177-
178246
Test 2:
179247

180248
In test_matrix:
@@ -216,7 +284,6 @@ https://github.com/CatalinAnt/algorithms-SEP-95/commit/5651abafebe8ae3a5ea63e748
216284

217285
The coverage is improved by 13%, the code only hit three out of five branches and only set up two examples. I added a case where there is no unique letter.
218286

219-
220287
## Almuthana Almustafa
221288

222289
stoogsort in stoog_sort.py
@@ -291,9 +358,3 @@ Due to the large size of the project, the percentage only went up by one percent
291358
Abdullah -> increased the coverage for two functions.
292359
Almuthana Almustafa -> Instrumentation was added to two functions, and test cases were created for them to improve coverage.
293360

294-
295-
296-
297-
298-
299-

algorithms/maths/find_order_simple.py

+25
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,42 @@
1111

1212
import math
1313

14+
branch_coverage = {
15+
"branch_6": False,
16+
"branch_7": False,
17+
"branch_8": False,
18+
"branch_9": False,
19+
"branch_10": False
20+
}
21+
1422
def find_order(a, n):
1523
"""
1624
Find order for positive integer n and given integer a that satisfies gcd(a, n) = 1.
1725
"""
26+
1827
if (a == 1) & (n == 1):
1928
# Exception Handeling : 1 is the order of of 1
29+
branch_coverage["branch_6"] = True
30+
print("branch_6")
2031
return 1
2132
if math.gcd(a, n) != 1:
33+
branch_coverage["branch_7"] = True
34+
print("branch_7")
2235
print ("a and n should be relative prime!")
2336
return -1
2437
for i in range(1, n):
38+
branch_coverage["branch_8"] = True
39+
print("branch_8")
2540
if pow(a, i) % n == 1:
41+
branch_coverage["branch_9"] = True
42+
print("branch_9")
2643
return i
44+
branch_coverage["branch_10"] = True
45+
print("branch_10")
2746
return -1
47+
48+
def print_coverage():
49+
for branch, hit in branch_coverage.items():
50+
print(f"{branch} was {'hit' if hit else 'not hit'}")
51+
52+
print_coverage()

algorithms/maths/prime_check.py

+25
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,42 @@
1+
branch_coverage = {
2+
"branch_1": False, # n <= 1
3+
"branch_2": False, # n == 2 or n == 3
4+
"branch_3": False, # n % 2 == 0 or n % 3 == 0
5+
"branch_4": False, # while j * j <= n
6+
"branch_5": False # n % j == 0 or n % (j + 2) == 0
7+
}
18
def prime_check(n):
29
"""Return True if n is a prime number
310
Else return False.
411
"""
12+
print(f"Checking {n}") # Debugging statement
513

614
if n <= 1:
15+
branch_coverage["branch_1"] = True
16+
print("branch_1")
717
return False
18+
819
if n == 2 or n == 3:
20+
branch_coverage["branch_2"] = True
21+
print("branch_2")
922
return True
1023
if n % 2 == 0 or n % 3 == 0:
24+
branch_coverage["branch_3"] = True
25+
print("branch_3")
1126
return False
1227
j = 5
1328
while j * j <= n:
29+
branch_coverage["branch_4"] = True
30+
print("branch_4")
1431
if n % j == 0 or n % (j + 2) == 0:
32+
branch_coverage["branch_5"] = True
33+
print("branch_5")
1534
return False
1635
j += 6
1736
return True
37+
38+
def print_coverage():
39+
for branch, hit in branch_coverage.items():
40+
print(f"{branch} was {'hit' if hit else 'not hit'}")
41+
42+
print_coverage()

algorithms/maths/pythagoras.py

+21
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
Given the lengths of two of the three sides of a right angled triangle, this function returns the
33
length of the third side.
44
"""
5+
branch_coverage = {
6+
"branch_31": False,
7+
"branch_32": False,
8+
"branch_33": False,
9+
"branch_34": False,
10+
"branch_35": False
11+
}
512

613
def pythagoras(opposite, adjacent, hypotenuse):
714
"""
@@ -10,11 +17,25 @@ def pythagoras(opposite, adjacent, hypotenuse):
1017
"""
1118
try:
1219
if opposite == str("?"):
20+
branch_coverage["branch_31"] = True
1321
return ("Opposite = " + str(((hypotenuse**2) - (adjacent**2))**0.5))
1422
if adjacent == str("?"):
23+
branch_coverage["branch_32"] = True
1524
return ("Adjacent = " + str(((hypotenuse**2) - (opposite**2))**0.5))
1625
if hypotenuse == str("?"):
26+
branch_coverage["branch_33"] = True
1727
return ("Hypotenuse = " + str(((opposite**2) + (adjacent**2))**0.5))
28+
branch_coverage["branch_34"] = True
1829
return "You already know the answer!"
1930
except:
31+
branch_coverage["branch_35"] = True
2032
raise ValueError("invalid argument(s) were given.")
33+
34+
def print_coverage():
35+
for branch, hit in branch_coverage.items():
36+
print(f"{branch} was {'hit' if hit else 'not hit'}")
37+
38+
pythagoras(3, 2, "?")
39+
40+
print_coverage()
41+

algorithms/matrix/rotate_image.py

+35-7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@
77
Could you do this in-place?
88
"""
99

10+
branch_coverage = {
11+
"rotate_matrix_1": False, # if not branch for mat
12+
"rotate_matrix_2": False, # invisible else branch
13+
"rotate_matrix_3": False, # for branch
14+
"rotate_matrix_4": False, # for branch
15+
16+
}
17+
1018

1119
# clockwise rotate
1220
# first reverse up to down, then swap the symmetry
@@ -16,18 +24,38 @@
1624

1725
def rotate(mat):
1826
if not mat:
27+
branch_coverage["rotate_matrix_1"] = True
1928
return mat
29+
30+
branch_coverage["rotate_matrix_2"] = True
31+
2032
mat.reverse()
2133
for i in range(len(mat)):
34+
branch_coverage["rotate_matrix_3"] = True
35+
2236
for j in range(i):
37+
branch_coverage["rotate_matrix_4"] = True
38+
2339
mat[i][j], mat[j][i] = mat[j][i], mat[i][j]
2440
return mat
2541

2642

27-
if __name__ == "__main__":
28-
mat = [[1, 2, 3],
29-
[4, 5, 6],
30-
[7, 8, 9]]
31-
print(mat)
32-
rotate(mat)
33-
print(mat)
43+
def print_coverage():
44+
for branch, hit in branch_coverage.items():
45+
print(f"{branch} was {'hit' if hit else 'not hit'}")
46+
total = len(branch_coverage)
47+
hit = sum(branch_coverage.values())
48+
result = hit / total * 100
49+
50+
print("The total branch coverage is:", result, "%")
51+
52+
53+
rotate([])
54+
print_coverage()
55+
print("\n")
56+
print_coverage()
57+
rotate([[1, 2], [3, 4]])
58+
print("\n")
59+
print_coverage()
60+
rotate([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
61+
print("\n")

algorithms/search/interpolation_search.py

+22-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@
1313

1414
from typing import List
1515

16+
branch_coverage = {
17+
"branch_60": False,
18+
"branch_61": False,
19+
"branch_62": False,
20+
"branch_63": False,
21+
"branch_64": False,
22+
23+
}
24+
1625

1726
def interpolation_search(array: List[int], search_key: int) -> int:
1827
"""
@@ -38,24 +47,36 @@ def interpolation_search(array: List[int], search_key: int) -> int:
3847

3948
while (low <= high) and (array[low] <= search_key <= array[high]):
4049
# calculate the search position
50+
branch_coverage["branch_60"] = True
4151
pos = low + int(((search_key - array[low]) *
4252
(high - low) / (array[high] - array[low])))
4353

4454
# search_key is found
4555
if array[pos] == search_key:
56+
branch_coverage["branch_61"] = True
4657
return pos
4758

4859
# if search_key is larger, search_key is in upper part
4960
if array[pos] < search_key:
61+
branch_coverage["branch_62"] = True
5062
low = pos + 1
5163

5264
# if search_key is smaller, search_key is in lower part
5365
else:
66+
branch_coverage["branch_63"] = True
5467
high = pos - 1
55-
68+
69+
branch_coverage["branch_64"] = True
5670
return -1
5771

72+
def print_coverage():
73+
for branch, hit in branch_coverage.items():
74+
print(f"{branch} was {'hit' if hit else 'not hit'}")
75+
76+
5877

5978
if __name__ == "__main__":
6079
import doctest
6180
doctest.testmod()
81+
print_coverage()
82+

algorithms/sort/insertion_sort.py

+17
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,42 @@
1+
branch_coverage = {
2+
"simulation": False,
3+
"for": False,
4+
"while": False,
5+
"simulation-nested": False,
6+
}
7+
18
def insertion_sort(arr, simulation=False):
29
""" Insertion Sort
310
Complexity: O(n^2)
411
"""
512

613
iteration = 0
714
if simulation:
15+
branch_coverage["simulation"] = True
816
print("iteration",iteration,":",*arr)
917

1018
for i in range(len(arr)):
19+
branch_coverage["for"] = True
1120
cursor = arr[i]
1221
pos = i
1322

1423
while pos > 0 and arr[pos - 1] > cursor:
24+
branch_coverage["while"] = True
1525
# Swap the number down the list
1626
arr[pos] = arr[pos - 1]
1727
pos = pos - 1
1828
# Break and do the final swap
1929
arr[pos] = cursor
2030

2131
if simulation:
32+
branch_coverage["simulation-nested"] = True
2233
iteration = iteration + 1
2334
print("iteration",iteration,":",*arr)
2435

2536
return arr
37+
38+
def print_coverage():
39+
print("branch coverage for `insertion_sort`:")
40+
for branch, hit in branch_coverage.items():
41+
print(f"{branch} was {'hit' if hit else 'not hit'}")
42+

0 commit comments

Comments
 (0)