Skip to content

Commit

Permalink
Merge branch 'master' into Almu
Browse files Browse the repository at this point in the history
  • Loading branch information
MuthanaMustafa authored Jun 27, 2024
2 parents 2017fe3 + bc42bcc commit d19bc03
Show file tree
Hide file tree
Showing 27 changed files with 459 additions and 63 deletions.
159 changes: 117 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,38 +57,17 @@ Link to commit:(same as for the first one)
Screenshot of branch measurement:
![image](https://github.com/CatalinAnt/algorithms-SEP-95/assets/113595149/94eec9b6-3dd6-46e3-b087-40892eccc10e)

#### Abdullah Abdelkhalik


pythagoras

https://github.com/CatalinAnt/algorithms-SEP-95/commit/5651abafebe8ae3a5ea63e74883bb991acf19303

![pythagoras_hits](https://github.com/CatalinAnt/algorithms-SEP-95/assets/114078193/0df1fa2b-2185-4b9f-ae65-5d969edb009b)


first_unique_char

https://github.com/CatalinAnt/algorithms-SEP-95/commit/c16f26e952322b2c1729778a4141a57103ba7658

![first_unique_char_hits](https://github.com/CatalinAnt/algorithms-SEP-95/assets/114078193/10d7c45c-398e-4408-8f11-6771f51fa95c)


#### Abdullah Abdelkhalik


pythagoras

https://github.com/CatalinAnt/algorithms-SEP-95/commit/5651abafebe8ae3a5ea63e74883bb991acf19303

![pythagoras_hits](https://github.com/CatalinAnt/algorithms-SEP-95/assets/114078193/0df1fa2b-2185-4b9f-ae65-5d969edb009b)


first_unique_char

https://github.com/CatalinAnt/algorithms-SEP-95/commit/c16f26e952322b2c1729778a4141a57103ba7658

![first_unique_char_hits](https://github.com/CatalinAnt/algorithms-SEP-95/assets/114078193/10d7c45c-398e-4408-8f11-6771f51fa95c)


#### Almuthana Almustafa
Expand All @@ -110,6 +89,41 @@ result:

![alt text](result_image_2.png)

#### Ayman Errahmouni

##### Function 1: simplify_path_v2

[Link the commit](https://github.com/CatalinAnt/algorithms-SEP-95/pull/2/commits/22ee6fa1df4785596c603af61a725c558973eb0b)

Screenshot of branch measurement:<br>
![alt text](image-7.png)

##### Function 2: insertion_sort

[Link to commit](https://github.com/CatalinAnt/algorithms-SEP-95/pull/2/commits/5dae7f28036f89b7f6ff673639a922dd714aff3e)

Screenshot of branch measurement:<br>
![alt text](image-11.png)

#### Catalin Antonescu

##### Function 1: strong_password

Link to commit:
[https://github.com/CatalinAnt/algorithms-SEP-95/commit/eaad6d32ecd73bb8fde876a4d4852cb522aea6f8](https://github.com/CatalinAnt/algorithms-SEP-95/commit/2b0b9187c1c040e4476b1ca14f2c2249273566b7)

Screenshot of branch measurement:
![image](https://github.com/CatalinAnt/algorithms-SEP-95/assets/113595149/e718a47f-5ea0-412c-b250-25a193412164)

##### Function 2: rotate_image

Link to commit:(same as for the first one)
[https://github.com/CatalinAnt/algorithms-SEP-95/commit/eaad6d32ecd73bb8fde876a4d4852cb522aea6f8](https://github.com/CatalinAnt/algorithms-SEP-95/commit/2b0b9187c1c040e4476b1ca14f2c2249273566b7)

Screenshot of branch measurement:
![image](https://github.com/CatalinAnt/algorithms-SEP-95/assets/113595149/94eec9b6-3dd6-46e3-b087-40892eccc10e)


## Coverage improvement

### Individual tests
Expand Down Expand Up @@ -143,6 +157,7 @@ Old coverage:<br>

Diff (LHS = new code, RHS = old code):<br>
![LHS: new code, RHS: old code](image.png)
![alt text](image-9.png)

New coverage:<br>
![new coverage result (100%)](image-1.png)
Expand All @@ -161,6 +176,8 @@ Diff (LHS: new code, RHS: old code):<br>
![LHS: new code, RHS: old code](image-5.png)<br>
(Changes in imports)<br>
![LHS: new code, RHS: old code](image-6.png)
(Instrumentation)<br>
![alt text](image-8.png)

Old coverage:<br>
![Old coverage result (4%)](image-3.png)
Expand Down Expand Up @@ -192,7 +209,6 @@ New coverage:

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


Test 2:

In test_matrix:
Expand All @@ -212,27 +228,7 @@ New coverage:
For rotate_image, thre was a 33% coverage improvement with the existing tool and 25% with manual tool.


## Abdullah Abdelkhalik

test_maths

https://github.com/CatalinAnt/algorithms-SEP-95/commit/60832d9c672efd586848077cc41a52630d34371b

![pythagoras_before](https://github.com/CatalinAnt/algorithms-SEP-95/assets/114078193/cf57112b-1aef-4a10-a41f-bd4b797e2012)

![pythagoras_after](https://github.com/CatalinAnt/algorithms-SEP-95/assets/114078193/1aa45c17-46fc-49d3-944a-03c2276d1be6)

the coverage is improved by 28%, the code only hit one of the five branches and cover only one of the three cases of the pythagoras theory. I added the other two cases, i could have a fourth case where none of the cases is present.

test_strings

https://github.com/CatalinAnt/algorithms-SEP-95/commit/5651abafebe8ae3a5ea63e74883bb991acf19303

![first_unique_char_before](https://github.com/CatalinAnt/algorithms-SEP-95/assets/114078193/9910ec69-73b0-4c87-afc8-abc01f65a423)

![first_unique_char_after](https://github.com/CatalinAnt/algorithms-SEP-95/assets/114078193/10859fac-776c-4a48-8a1c-9531afcbfa9b)

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.

## Almuthana Almustafa

Expand Down Expand Up @@ -267,6 +263,85 @@ existing tool result after:

The coverage improved by 86% due to the creation of new tests.
























#### Abdullah Abdelkhalik


pythagoras

https://github.com/CatalinAnt/algorithms-SEP-95/commit/5651abafebe8ae3a5ea63e74883bb991acf19303

![pythagoras_hits](https://github.com/CatalinAnt/algorithms-SEP-95/assets/114078193/c61bff67-be7e-4bd2-b892-0a0f2dada1f3)




first_unique_char

https://github.com/CatalinAnt/algorithms-SEP-95/commit/c16f26e952322b2c1729778a4141a57103ba7658

![first_unique_char_hits (2)](https://github.com/CatalinAnt/algorithms-SEP-95/assets/114078193/8c1b704e-cadb-4f54-aea7-795005348538)





## Improvements

test_maths

https://github.com/CatalinAnt/algorithms-SEP-95/commit/60832d9c672efd586848077cc41a52630d34371b

![pythagoras_before](https://github.com/CatalinAnt/algorithms-SEP-95/assets/114078193/cf57112b-1aef-4a10-a41f-bd4b797e2012)

![pythagoras_after](https://github.com/CatalinAnt/algorithms-SEP-95/assets/114078193/1aa45c17-46fc-49d3-944a-03c2276d1be6)

the coverage is improved by 28%, the code only hit one of the five branches and cover only one of the three cases of the pythagoras theory. I added the other two cases, i could have a fourth case where none of the cases is present.

test_strings

https://github.com/CatalinAnt/algorithms-SEP-95/commit/5651abafebe8ae3a5ea63e74883bb991acf19303

![first_unique_char_before](https://github.com/CatalinAnt/algorithms-SEP-95/assets/114078193/9910ec69-73b0-4c87-afc8-abc01f65a423)

![first_unique_char_after](https://github.com/CatalinAnt/algorithms-SEP-95/assets/114078193/10859fac-776c-4a48-8a1c-9531afcbfa9b)

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.













### Overall

<Provide a screenshot of the old coverage results by running an existing tool (the same as you already showed above)>
Expand Down
25 changes: 25 additions & 0 deletions algorithms/maths/find_order_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,42 @@

import math

branch_coverage = {
"branch_6": False,
"branch_7": False,
"branch_8": False,
"branch_9": False,
"branch_10": False
}

def find_order(a, n):
"""
Find order for positive integer n and given integer a that satisfies gcd(a, n) = 1.
"""

if (a == 1) & (n == 1):
# Exception Handeling : 1 is the order of of 1
branch_coverage["branch_6"] = True
print("branch_6")
return 1
if math.gcd(a, n) != 1:
branch_coverage["branch_7"] = True
print("branch_7")
print ("a and n should be relative prime!")
return -1
for i in range(1, n):
branch_coverage["branch_8"] = True
print("branch_8")
if pow(a, i) % n == 1:
branch_coverage["branch_9"] = True
print("branch_9")
return i
branch_coverage["branch_10"] = True
print("branch_10")
return -1

def print_coverage():
for branch, hit in branch_coverage.items():
print(f"{branch} was {'hit' if hit else 'not hit'}")

print_coverage()
25 changes: 25 additions & 0 deletions algorithms/maths/prime_check.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,42 @@
branch_coverage = {
"branch_1": False, # n <= 1
"branch_2": False, # n == 2 or n == 3
"branch_3": False, # n % 2 == 0 or n % 3 == 0
"branch_4": False, # while j * j <= n
"branch_5": False # n % j == 0 or n % (j + 2) == 0
}
def prime_check(n):
"""Return True if n is a prime number
Else return False.
"""
print(f"Checking {n}") # Debugging statement

if n <= 1:
branch_coverage["branch_1"] = True
print("branch_1")
return False

if n == 2 or n == 3:
branch_coverage["branch_2"] = True
print("branch_2")
return True
if n % 2 == 0 or n % 3 == 0:
branch_coverage["branch_3"] = True
print("branch_3")
return False
j = 5
while j * j <= n:
branch_coverage["branch_4"] = True
print("branch_4")
if n % j == 0 or n % (j + 2) == 0:
branch_coverage["branch_5"] = True
print("branch_5")
return False
j += 6
return True

def print_coverage():
for branch, hit in branch_coverage.items():
print(f"{branch} was {'hit' if hit else 'not hit'}")

print_coverage()
21 changes: 21 additions & 0 deletions algorithms/maths/pythagoras.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
Given the lengths of two of the three sides of a right angled triangle, this function returns the
length of the third side.
"""
branch_coverage = {
"branch_31": False,
"branch_32": False,
"branch_33": False,
"branch_34": False,
"branch_35": False
}

def pythagoras(opposite, adjacent, hypotenuse):
"""
Expand All @@ -10,11 +17,25 @@ def pythagoras(opposite, adjacent, hypotenuse):
"""
try:
if opposite == str("?"):
branch_coverage["branch_31"] = True
return ("Opposite = " + str(((hypotenuse**2) - (adjacent**2))**0.5))
if adjacent == str("?"):
branch_coverage["branch_32"] = True
return ("Adjacent = " + str(((hypotenuse**2) - (opposite**2))**0.5))
if hypotenuse == str("?"):
branch_coverage["branch_33"] = True
return ("Hypotenuse = " + str(((opposite**2) + (adjacent**2))**0.5))
branch_coverage["branch_34"] = True
return "You already know the answer!"
except:
branch_coverage["branch_35"] = True
raise ValueError("invalid argument(s) were given.")

def print_coverage():
for branch, hit in branch_coverage.items():
print(f"{branch} was {'hit' if hit else 'not hit'}")

pythagoras(3, 2, "?")

print_coverage()

Loading

0 comments on commit d19bc03

Please sign in to comment.