Skip to content

Commit ea5de08

Browse files
committed
Added more tests
1 parent 4fab0fe commit ea5de08

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

test/test_jit.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6084,28 +6084,31 @@ def fn():
60846084
self.checkScript(fn, (), outputs=4929, optimize=True)
60856085

60866086
def test_script_for_in_range_start_end_step(self):
6087-
def fn():
6087+
def fn(start, end, step):
6088+
# type: (int, int, int) -> int
60886089
x = 0
6089-
for i in range(7, 100, 7):
6090+
for i in range(start, end, step):
60906091
x += i
60916092
return x
6092-
self.checkScript(fn, (), outputs=735, optimize=True)
60936093

6094-
def test_script_for_in_range_negative_step(self):
6095-
def fn():
6096-
x = 0
6097-
for i in range(2, -11, -3):
6098-
x += i
6099-
return x
6100-
self.checkScript(fn, (), outputs=-20, optimize=True)
6094+
def check(inp):
6095+
self.checkScript(fn, inp, outputs=fn(*inp), optimize=True)
6096+
check((7, 100, 7))
6097+
check((7, 100, -7))
6098+
check((2, -11, -3))
6099+
check((2, -11, 3))
6100+
check((2, 10, 3))
6101+
check((-2, -10, -10))
61016102

61026103
def test_script_for_zero_step(self):
6104+
@torch.jit.script
61036105
def fn():
61046106
x = 0
6105-
for i in range(2, -11, -3):
6107+
for i in range(2, -11, 0):
61066108
x += i
61076109
return x
6108-
self.checkScript(fn, (), outputs=-20, optimize=True)
6110+
with self.assertRaisesRegex(torch.jit.Error, "must not be zero"):
6111+
fn()
61096112

61106113
def test_script_optional_none(self):
61116114
def none_stmt(x):

0 commit comments

Comments
 (0)