Skip to content

Commit

Permalink
Merge pull request #2 from misraozoktas/misra
Browse files Browse the repository at this point in the history
Two tests have been added
  • Loading branch information
misraozoktas authored Jun 14, 2024
2 parents e930323 + 5306bdd commit 2c5e8f4
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
47 changes: 47 additions & 0 deletions tests/test_JM_INT_ITEM.py
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()
42 changes: 42 additions & 0 deletions tests/test_JM_UnicodeFromStr.py
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()

0 comments on commit 2c5e8f4

Please sign in to comment.