Skip to content

Commit a2b2642

Browse files
authored
Merge pull request #836 from KachanovYev/issue_810
Fix NPath metric calculating for 'if' conditions
2 parents 1a8af21 + 03e78f9 commit a2b2642

2 files changed

Lines changed: 1 addition & 17 deletions

File tree

aibolit/metrics/npath/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def _if_npath(self, node: ASTNode) -> int:
125125
if node.else_statement is not None
126126
else 1
127127
)
128-
return condition_npath * (then_npath + else_npath)
128+
return condition_npath * then_npath + else_npath
129129

130130
def _switch_npath(self, node: ASTNode) -> int:
131131
def _group_npath(case_group: ASTNode) -> int:

test/metrics/npath/test_all_types.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -191,15 +191,7 @@ def test_complex_if_else_with_npath_complexity_of_5(self) -> None:
191191
).strip()
192192
assert self._value(content) == 5
193193

194-
@pytest.mark.xfail(
195-
reason='Probably wrong implementation for If',
196-
strict=True,
197-
)
198194
def test_if_with_and_condition(self) -> None:
199-
# TODO #807:30min/DEV Fix NPath metric for if with AND (&&) condition.
200-
# Refer to https://checkstyle.org/checks/metrics/npathcomplexity.html
201-
# for details on NPath metric.
202-
# Once implemented, remove `xfail` mark from this test.
203195
content = '''
204196
class Test {
205197
void check(int a, int b) {
@@ -213,15 +205,7 @@ class Test {
213205
'''
214206
assert self._value(content) == 3
215207

216-
@pytest.mark.xfail(
217-
reason='Probably wrong implementation for If',
218-
strict=True,
219-
)
220208
def test_if_with_or_condition(self) -> None:
221-
# TODO #807:30min/DEV Fix NPath metric for if with OR (||) condition.
222-
# Refer to https://checkstyle.org/checks/metrics/npathcomplexity.html
223-
# for details on NPath metric.
224-
# Once implemented, remove `xfail` mark from this test.
225209
content = '''
226210
class Test {
227211
void validate(int x, int y) {

0 commit comments

Comments
 (0)