Improve "if/else" in "for" test

This commit is contained in:
rocky
2022-10-16 18:24:48 -04:00
parent 1819fc8944
commit bb9b9fb4b3
2 changed files with 14 additions and 6 deletions

View File

@@ -1,15 +1,17 @@
# Issue #413 on 2.7 # Issue #413 on 2.7
# Bug in handling CONTINUE in else block of if-then-else in a for loop # Bug in handling CONTINUE in else block of if-then-else in a for loop
# Bug was "if" and "else" jump back to loop getting detected.
# RUNNABLE!
"""This program is self-checking!""" """This program is self-checking!"""
def test1(a, r = None): def test1(a, r = []):
for b in a: for b in a:
if b: if b:
r = b r.append(3)
else: else:
r.append(5)
continue continue
raise AssertionError("CONTINUE not followed") if r == []:
if b:
pass pass
return r return r
@@ -27,7 +29,13 @@ def test2(a, r = None):
raise AssertionError("CONTINUE not followed") raise AssertionError("CONTINUE not followed")
return r return r
assert test1([True]) == True, "Incorrect flow" assert test1([], []) == [], "For loop not taken"
assert test1([False], []) == [5], "if 'else' should have been taken"
assert test1([True], []) == [3], "if 'then' should have been taken"
assert test1([True, True], []) == [3, 3], "if should have been taken"
assert test1([True, False], []) == [3, 5], "if and then 'else' should have been taken"
assert test1([False, True], []) == [5, 3], "if else and then 'then' should have been taken"
assert test1([False, False], []) == [5, 5], "if else should have been taken twice"
assert test1([True, True], []) == [3, 3], "if 'then' should have been taken twice"
assert test2([True]) is None, "Incorrect flow" assert test2([True]) is None, "Incorrect flow"
assert test1([False]) is None, "Incorrect flow"
assert test2([False]) is None, "Incorrect flow" assert test2([False]) is None, "Incorrect flow"