-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
459 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.