Skip to content

Commit c7cb85e

Browse files
committed
2 parents cf6dfe6 + 162f9a8 commit c7cb85e

11 files changed

+206
-22
lines changed

README.md

Lines changed: 114 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,92 @@ In order to not put in 8 large images, I will insert the final screenshot, with
2323

2424
### Your own coverage tool
2525

26-
<The following is supposed to be repeated for each group member>
26+
#### Ayman Errahmouni
2727

28-
<Group member name>
28+
##### Function 1: simplify_path_v2
29+
30+
[Link the commit](https://github.com/CatalinAnt/algorithms-SEP-95/pull/2/commits/22ee6fa1df4785596c603af61a725c558973eb0b)
31+
32+
Screenshot of branch measurement (66%):<br>
33+
![image](image-7.png)
34+
35+
##### Function 2: insertion_sort
36+
37+
[Link to commit](https://github.com/CatalinAnt/algorithms-SEP-95/pull/2/commits/5dae7f28036f89b7f6ff673639a922dd714aff3e)
38+
39+
Screenshot of branch measurement (0%, was untested):<br>
40+
![alt text](image-8.png)
41+
42+
#### Catalin Antonescu
43+
44+
##### Function 1: strong_password
45+
46+
Link to commit:
47+
[https://github.com/CatalinAnt/algorithms-SEP-95/commit/eaad6d32ecd73bb8fde876a4d4852cb522aea6f8](https://github.com/CatalinAnt/algorithms-SEP-95/commit/2b0b9187c1c040e4476b1ca14f2c2249273566b7)
48+
49+
Screenshot of branch measurement:
50+
![image](https://github.com/CatalinAnt/algorithms-SEP-95/assets/113595149/e718a47f-5ea0-412c-b250-25a193412164)
51+
52+
##### Function 2: rotate_image
53+
54+
Link to commit:(same as for the first one)
55+
[https://github.com/CatalinAnt/algorithms-SEP-95/commit/eaad6d32ecd73bb8fde876a4d4852cb522aea6f8](https://github.com/CatalinAnt/algorithms-SEP-95/commit/2b0b9187c1c040e4476b1ca14f2c2249273566b7)
56+
57+
Screenshot of branch measurement:
58+
![image](https://github.com/CatalinAnt/algorithms-SEP-95/assets/113595149/94eec9b6-3dd6-46e3-b087-40892eccc10e)
59+
60+
#### Abdullah Abdelkhalik
2961

30-
<Function 1 name>
3162

32-
<Show a patch (diff) or a link to a commit made in your forked repository that shows the instrumented code to gather coverage measurements>
63+
pythagoras
64+
65+
https://github.com/CatalinAnt/algorithms-SEP-95/commit/5651abafebe8ae3a5ea63e74883bb991acf19303
3366

34-
<Provide a screenshot of the coverage results output by the instrumentation>
67+
![pythagoras_hits](https://github.com/CatalinAnt/algorithms-SEP-95/assets/114078193/0df1fa2b-2185-4b9f-ae65-5d969edb009b)
3568

36-
<Function 2 name>
3769

38-
<Provide the same kind of information provided for Function 1>
70+
first_unique_char
71+
72+
https://github.com/CatalinAnt/algorithms-SEP-95/commit/c16f26e952322b2c1729778a4141a57103ba7658
73+
74+
![first_unique_char_hits](https://github.com/CatalinAnt/algorithms-SEP-95/assets/114078193/10d7c45c-398e-4408-8f11-6771f51fa95c)
75+
76+
77+
#### Abdullah Abdelkhalik
78+
79+
80+
pythagoras
81+
82+
https://github.com/CatalinAnt/algorithms-SEP-95/commit/5651abafebe8ae3a5ea63e74883bb991acf19303
83+
84+
![pythagoras_hits](https://github.com/CatalinAnt/algorithms-SEP-95/assets/114078193/0df1fa2b-2185-4b9f-ae65-5d969edb009b)
85+
86+
87+
first_unique_char
88+
89+
https://github.com/CatalinAnt/algorithms-SEP-95/commit/c16f26e952322b2c1729778a4141a57103ba7658
90+
91+
![first_unique_char_hits](https://github.com/CatalinAnt/algorithms-SEP-95/assets/114078193/10d7c45c-398e-4408-8f11-6771f51fa95c)
92+
93+
94+
#### Almuthana Almustafa
95+
96+
##### Function 1: stoogsort in stoog_sort.py
97+
98+
[Link to the commit in the founction files](https://github.com/CatalinAnt/algorithms-SEP-95/commit/57b66879c6ae0f82712c55528f540dfdb3c3ddd3)
99+
100+
result:
101+
102+
![alt text](result_image-2.png)
103+
104+
##### Function 2: word_break in word_break.py
105+
106+
link to commit in founction:
107+
[Link to the commit in the founction files](https://github.com/CatalinAnt/algorithms-SEP-95/commit/57b66879c6ae0f82712c55528f540dfdb3c3ddd3 )
108+
109+
result:
110+
111+
![alt text](result_image_2.png)
39112

40113
#### Ayman Errahmouni
41114

@@ -191,7 +264,6 @@ New coverage:
191264

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

194-
195267
Test 2:
196268

197269
In test_matrix:
@@ -233,6 +305,38 @@ https://github.com/CatalinAnt/algorithms-SEP-95/commit/5651abafebe8ae3a5ea63e748
233305

234306
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.
235307

308+
## Almuthana Almustafa
309+
310+
### Test 1: stoogsort
311+
312+
313+
314+
link to commit in test files:
315+
[Link to the commit in the test files](https://github.com/CatalinAnt/algorithms-SEP-95/commit/157de36fd4c373b67cd03e3b3713be9ba5cf0d97)
316+
317+
existing tool result before:
318+
319+
![alt text](stoog_sort_image1.png)
320+
321+
existing tool result after:
322+
323+
![alt text](stoog_sort_image2.png)
324+
325+
The coverage increased by 89%, largely attributable to the implementation of new tests.
326+
327+
### Test 2: word_break
328+
329+
[Link to the commit in the test files](https://github.com/CatalinAnt/algorithms-SEP-95/commit/157de36fd4c373b67cd03e3b3713be9ba5cf0d97)
330+
331+
existing tool result before:
332+
333+
![alt text](word_break_image1.png)
334+
335+
existing tool result after:
336+
337+
![alt text](word_break_image2.png)
338+
339+
The coverage improved by 86% due to the creation of new tests.
236340

237341
### Overall
238342

@@ -252,3 +356,5 @@ Due to the large size of the project, the percentage only went up by one percent
252356
<Write what each group member did>
253357

254358
Abdullah -> increased the coverage for two functions.
359+
Almuthana Almustafa -> Instrumentation was added to two functions, and test cases were created for them to improve coverage.
360+

algorithms/dp/word_break.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@
1717
"""
1818

1919

20+
# TC: O(N^2) SC: O(N)
21+
branch_coverage = {
22+
"check_5": False,
23+
"check_6": False,
24+
"check_7": False,
25+
"check_8": False,
26+
27+
}
2028
# TC: O(N^2) SC: O(N)
2129
def word_break(word, word_dict):
2230
"""
@@ -27,15 +35,29 @@ def word_break(word, word_dict):
2735
dp_array = [False] * (len(word)+1)
2836
dp_array[0] = True
2937
for i in range(1, len(word)+1):
38+
branch_coverage["check_5"] = True
3039
for j in range(0, i):
40+
branch_coverage["check_6"] = True
3141
if dp_array[j] and word[j:i] in word_dict:
42+
branch_coverage["check_7"] = True
3243
dp_array[i] = True
3344
break
45+
branch_coverage["check_8"] = True
3446
return dp_array[-1]
3547

3648

37-
if __name__ == "__main__":
38-
STR = "keonkim"
39-
dic = ["keon", "kim"]
49+
def print_coverage():
50+
total = len(branch_coverage)
51+
reached = sum(branch_coverage.values())
52+
coverage_percentage = (reached / total) * 100
53+
for branch, hit in branch_coverage.items():
54+
print(f"{branch} was {'hit' if hit else 'not hit'}")
55+
print(f"coverage_percentage: {coverage_percentage}%")
56+
57+
58+
result = word_break("keonkim", {"keon", "kim"})
59+
print_coverage()
60+
61+
62+
4063

41-
print(word_break(str, dic))

algorithms/sort/stooge_sort.py

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,30 @@
66
77
'''
88

9-
9+
branch_coverage = {
10+
"check_1": False, # if branch for x > 0
11+
"check_2": False, # else branch
12+
"check_3": False,
13+
"check_4": False,
14+
}
1015

1116
def stoogesort(arr, l, h):
1217
if l >= h:
18+
branch_coverage["check_1"] = True
1319
return
1420

1521
# If first element is smaller
1622
# than last, swap them
1723
if arr[l]>arr[h]:
24+
branch_coverage["check_2"] = True
1825
t = arr[l]
1926
arr[l] = arr[h]
2027
arr[h] = t
2128

2229
# If there are more than 2 elements in
2330
# the array
2431
if h-l + 1 > 2:
32+
branch_coverage["check_3"] = True
2533
t = (int)((h-l + 1)/3)
2634

2735
# Recursively sort first 2 / 3 elements
@@ -33,11 +41,27 @@ def stoogesort(arr, l, h):
3341
# Recursively sort first 2 / 3 elements
3442
# again to confirm
3543
stoogesort(arr, l, (h-t))
44+
45+
branch_coverage["check_4"] = True
46+
47+
def print_coverage():
48+
total = len(branch_coverage)
49+
reached = sum(branch_coverage.values())
50+
coverage_percentage = (reached / total) * 100
51+
for branch, hit in branch_coverage.items():
52+
print(f"{branch} was {'hit' if hit else 'not hit'}")
53+
print(f"coverage_percentage: {coverage_percentage}%")
54+
55+
arr1 = [10, -1, 2, 3, 0]
56+
arr2 = []
57+
result = stoogesort(arr1, 0, len(arr1) - 1)
58+
result = stoogesort(arr1, 0, len(arr2) - 1)
59+
print_coverage()
3660

3761

38-
if __name__ == "__main__":
39-
array = [1,3,64,5,7,8]
40-
n = len(array)
41-
stoogesort(array, 0, n-1)
42-
for i in range(0, n):
43-
print(array[i], end = ' ')
62+
# if __name__ == "__main__":
63+
# array = [1,3,64,5,7,8]
64+
# n = len(array)
65+
# stoogesort(array, 0, n-1)
66+
# for i in range(0, n):
67+
# print(array[i], end = ' ')

result_image-2.png

3.61 KB
Loading

result_image_2.png

3.47 KB
Loading

stoog_sort_image1.png

2.51 KB
Loading

stoog_sort_image2.png

2.48 KB
Loading

tests/test_dp.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
longest_increasing_subsequence_optimized,
1515
longest_increasing_subsequence_optimized2,
1616
int_divide,find_k_factor,
17-
planting_trees, regex_matching
17+
planting_trees, regex_matching,
18+
word_break,
1819
)
1920

2021

@@ -258,6 +259,16 @@ def test_symbol_2(self):
258259
p = "ab*"
259260
self.assertTrue(regex_matching.is_match(s, p))
260261

262+
class TestWordBreak(unittest.TestCase):
263+
"""Test for interpolation_search and word_break"""
264+
265+
def test_word_break(self):
266+
self.assertTrue(word_break("keonkim", {"keon", "kim"}))
267+
self.assertTrue(word_break("leetcode", {"leet", "code"}))
268+
self.assertFalse(word_break("catsandog", {"cats", "dog", "sand", "and", "cat"}))
269+
self.assertTrue(word_break("applepenapple", {"apple", "pen"}))
270+
self.assertFalse(word_break("pineapplepenapple", {"apple", "pen"}))
271+
self.assertTrue(word_break("aaaaaaa", {"aaaa", "aaa"}))
261272

262273
if __name__ == '__main__':
263274
unittest.main()

tests/test_sort.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
radix_sort,
1818
gnome_sort,
1919
cocktail_shaker_sort,
20-
top_sort, top_sort_recursive
20+
top_sort, top_sort_recursive,
21+
stoogesort
2122
)
2223

2324
import unittest
@@ -124,7 +125,27 @@ def test_topsort(self):
124125
self.assertTrue(res.index('g') < res.index('e'))
125126
res = top_sort(self.depGraph)
126127
self.assertTrue(res.index('g') < res.index('e'))
127-
128+
class TestStoog(unittest.TestCase):
129+
def test_stoogesort(self):
130+
arr1 = [1, 3, 64, 5, 7, 8]
131+
stoogesort(arr1, 0, len(arr1) - 1)
132+
self.assertEqual(arr1, [1, 3, 5, 7, 8, 64])
133+
134+
arr2 = [5, 4, 3, 2, 1]
135+
stoogesort(arr2, 0, len(arr2) - 1)
136+
self.assertEqual(arr2, [1, 2, 3, 4, 5])
137+
138+
arr3 = [1, 2, 3, 4, 5]
139+
stoogesort(arr3, 0, len(arr3) - 1)
140+
self.assertEqual(arr3, [1, 2, 3, 4, 5])
141+
142+
arr4 = [10, -1, 2, 3, 0]
143+
stoogesort(arr4, 0, len(arr4) - 1)
144+
self.assertEqual(arr4, [-1, 0, 2, 3, 10])
145+
146+
arr5 = []
147+
stoogesort(arr5, 0, len(arr5) - 1)
148+
self.assertEqual(arr5, [])
128149

129150
if __name__ == "__main__":
130151
unittest.main()

word_break_image1.png

2.62 KB
Loading

0 commit comments

Comments
 (0)