Skip to content

Commit 2c5e8f4

Browse files
authored
Merge pull request #2 from misraozoktas/misra
Two tests have been added
2 parents e930323 + 5306bdd commit 2c5e8f4

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed

tests/test_JM_INT_ITEM.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import os
2+
import unittest
3+
4+
branch_coverage = {
5+
"branch_1": False,
6+
"branch_2": False,
7+
}
8+
9+
def JM_INT_ITEM(obj, idx):
10+
if idx < len(obj):
11+
branch_coverage["branch_1"] = True
12+
temp = obj[idx]
13+
if isinstance(temp, (int, float)):
14+
return 0, temp
15+
else:
16+
branch_coverage["branch_2"] = True
17+
return 1, None
18+
19+
def print_coverage():
20+
for branch, hit in branch_coverage.items():
21+
print(f"{branch} was {'hit' if hit else 'not hit'}")
22+
23+
def test_JM_INT_ITEM_within_bounds_returns_0():
24+
result = JM_INT_ITEM("test", 1)
25+
print_coverage()
26+
27+
def test_JM_INT_ITEM_out_of_bounds_returns_1():
28+
result = JM_INT_ITEM("test", 213)
29+
print_coverage()
30+
31+
def test_JM_INT_ITEM_list_within_bounds_returns_0():
32+
result = JM_INT_ITEM([2, 4, 6, 8], 2)
33+
print_coverage()
34+
35+
def test_JM_INT_ITEM_list_out_of_bounds_returns_1():
36+
result = JM_INT_ITEM([3, 6, 9, 12], 10)
37+
print_coverage()
38+
39+
def test_JM_INT_ITEM_empty_returns_1():
40+
result = JM_INT_ITEM([], 0)
41+
print_coverage()
42+
43+
test_JM_INT_ITEM_within_bounds_returns_0()
44+
test_JM_INT_ITEM_out_of_bounds_returns_1()
45+
test_JM_INT_ITEM_list_within_bounds_returns_0()
46+
test_JM_INT_ITEM_list_out_of_bounds_returns_1()
47+
test_JM_INT_ITEM_empty_returns_1()

tests/test_JM_UnicodeFromStr.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import os
2+
import unittest
3+
4+
branch_coverage = {
5+
"branch_1": False,
6+
"branch_2": False
7+
}
8+
9+
def JM_UnicodeFromStr(s):
10+
if s is None:
11+
branch_coverage["branch_1"] = True
12+
return ''
13+
if isinstance(s, bytes):
14+
branch_coverage["branch_2"] = True
15+
s = s.decode('utf8')
16+
assert isinstance(s, str), f'{type(s)=} {s=}'
17+
return s
18+
19+
def print_coverage():
20+
for branch, hit in branch_coverage.items():
21+
print(f"{branch} was {'hit' if hit else 'not hit'}")
22+
23+
def test_JM_UnicodeFromStr_s_is_none_returns_none():
24+
result = JM_UnicodeFromStr(None)
25+
print_coverage()
26+
27+
def test_JM_UnicodeFromStr_s_is_byte_xxx_returns_decoded_s():
28+
result = JM_UnicodeFromStr(b"xxx")
29+
print_coverage()
30+
31+
def test_JM_UnicodeFromStr_s_is_byte_abcdefg_returns_decoded_s():
32+
result = JM_UnicodeFromStr(b"abcdefg")
33+
print_coverage()
34+
35+
def test_JM_UnicodeFromStr_s_is_string_xxx_returns_same_s():
36+
result = JM_UnicodeFromStr("xxx")
37+
print_coverage()
38+
39+
test_JM_UnicodeFromStr_s_is_none_returns_none()
40+
test_JM_UnicodeFromStr_s_is_byte_xxx_returns_decoded_s()
41+
test_JM_UnicodeFromStr_s_is_byte_abcdefg_returns_decoded_s()
42+
test_JM_UnicodeFromStr_s_is_string_xxx_returns_same_s()

0 commit comments

Comments
 (0)