-
Notifications
You must be signed in to change notification settings - Fork 561
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
1 parent
7c77f7b
commit 5306bdd
Showing
2 changed files
with
89 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import os | ||
import unittest | ||
|
||
branch_coverage = { | ||
"branch_1": False, | ||
"branch_2": False, | ||
} | ||
|
||
def JM_INT_ITEM(obj, idx): | ||
if idx < len(obj): | ||
branch_coverage["branch_1"] = True | ||
temp = obj[idx] | ||
if isinstance(temp, (int, float)): | ||
return 0, temp | ||
else: | ||
branch_coverage["branch_2"] = True | ||
return 1, None | ||
|
||
def print_coverage(): | ||
for branch, hit in branch_coverage.items(): | ||
print(f"{branch} was {'hit' if hit else 'not hit'}") | ||
|
||
def test_JM_INT_ITEM_within_bounds_returns_0(): | ||
result = JM_INT_ITEM("test", 1) | ||
print_coverage() | ||
|
||
def test_JM_INT_ITEM_out_of_bounds_returns_1(): | ||
result = JM_INT_ITEM("test", 213) | ||
print_coverage() | ||
|
||
def test_JM_INT_ITEM_list_within_bounds_returns_0(): | ||
result = JM_INT_ITEM([2, 4, 6, 8], 2) | ||
print_coverage() | ||
|
||
def test_JM_INT_ITEM_list_out_of_bounds_returns_1(): | ||
result = JM_INT_ITEM([3, 6, 9, 12], 10) | ||
print_coverage() | ||
|
||
def test_JM_INT_ITEM_empty_returns_1(): | ||
result = JM_INT_ITEM([], 0) | ||
print_coverage() | ||
|
||
test_JM_INT_ITEM_within_bounds_returns_0() | ||
test_JM_INT_ITEM_out_of_bounds_returns_1() | ||
test_JM_INT_ITEM_list_within_bounds_returns_0() | ||
test_JM_INT_ITEM_list_out_of_bounds_returns_1() | ||
test_JM_INT_ITEM_empty_returns_1() |
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import os | ||
import unittest | ||
|
||
branch_coverage = { | ||
"branch_1": False, | ||
"branch_2": False | ||
} | ||
|
||
def JM_UnicodeFromStr(s): | ||
if s is None: | ||
branch_coverage["branch_1"] = True | ||
return '' | ||
if isinstance(s, bytes): | ||
branch_coverage["branch_2"] = True | ||
s = s.decode('utf8') | ||
assert isinstance(s, str), f'{type(s)=} {s=}' | ||
return s | ||
|
||
def print_coverage(): | ||
for branch, hit in branch_coverage.items(): | ||
print(f"{branch} was {'hit' if hit else 'not hit'}") | ||
|
||
def test_JM_UnicodeFromStr_s_is_none_returns_none(): | ||
result = JM_UnicodeFromStr(None) | ||
print_coverage() | ||
|
||
def test_JM_UnicodeFromStr_s_is_byte_xxx_returns_decoded_s(): | ||
result = JM_UnicodeFromStr(b"xxx") | ||
print_coverage() | ||
|
||
def test_JM_UnicodeFromStr_s_is_byte_abcdefg_returns_decoded_s(): | ||
result = JM_UnicodeFromStr(b"abcdefg") | ||
print_coverage() | ||
|
||
def test_JM_UnicodeFromStr_s_is_string_xxx_returns_same_s(): | ||
result = JM_UnicodeFromStr("xxx") | ||
print_coverage() | ||
|
||
test_JM_UnicodeFromStr_s_is_none_returns_none() | ||
test_JM_UnicodeFromStr_s_is_byte_xxx_returns_decoded_s() | ||
test_JM_UnicodeFromStr_s_is_byte_abcdefg_returns_decoded_s() | ||
test_JM_UnicodeFromStr_s_is_string_xxx_returns_same_s() |