Skip to content

Commit

Permalink
Simplify the nested condition in textcov (#496)
Browse files Browse the repository at this point in the history
The conditional check of array_count larger than 0 is not necessary
since it is only used in repeating '[]' in the next_arg and the repeat
of string won't happen if the array_count is less than or equals 0. This
PR removes the unnecessary conditional check to simplify the logic and
decrease the amount of nested conditional checking.

---------

Signed-off-by: Arthur Chan <[email protected]>
  • Loading branch information
arthurscchan authored Jul 19, 2024
1 parent 4309def commit dee000b
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions experiment/textcov.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ def subtract_covered_lines(self, other: Function, language: str = 'c++'):
"""Subtract covered lines."""

if language == 'jvm':
for line_no in self.lines:
line = self.lines[line_no]
for line_no, line in self.lines.items():
other_line = other.lines.get(line_no)
if other_line and other_line.hit_count > 0:
self.lines[line_no].hit_count = 0
Expand Down Expand Up @@ -396,9 +395,8 @@ class name specification use single upper case letter for
if c == 'L':
start = True
if next_arg:
if array_count > 0:
next_arg = f'{next_arg}{"[]" * array_count}'
array_count = 0
next_arg += '[]' * array_count
array_count = 0
args.append(next_arg)
arg = ''
next_arg = ''
Expand All @@ -407,14 +405,12 @@ class name specification use single upper case letter for
else:
if c in JVM_CLASS_MAPPING:
if next_arg:
if array_count > 0:
next_arg = f'{next_arg}{"[]" * array_count}'
array_count = 0
next_arg += '[]' * array_count
array_count = 0
args.append(next_arg)
next_arg = JVM_CLASS_MAPPING[c]

if next_arg:
if array_count > 0:
next_arg = f'{next_arg}{"[]" * array_count}'
next_arg += '[]' * array_count
args.append(next_arg)
return args

0 comments on commit dee000b

Please sign in to comment.