Skip to content

Commit 715ce46

Browse files
refactor run tests
1 parent d2edf7b commit 715ce46

File tree

1 file changed

+23
-58
lines changed

1 file changed

+23
-58
lines changed

mypyc/test-data/run-loops.test

Lines changed: 23 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -578,74 +578,39 @@ def f(a: list[int]) -> int:
578578
for x in filter(lambda x: x % 2 == 0, a):
579579
s += x
580580
return s
581-
582-
[file driver.py]
583-
from native import f
584-
print(f([1, 2, 3, 4, 5, 6]))
585-
print(f([1, 3, 5]))
586-
print(f([]))
587-
588-
[out]
589-
12
590-
0
591-
0
592-
593-
[case testRunForFilterNone]
594-
def f(a: list[int]) -> int:
581+
def g(a: list[int]) -> int:
582+
s = 0
583+
for x in filter(lambda x: x > 10, a):
584+
s += x
585+
return s
586+
def with_none(a: list[int]) -> int:
595587
c = 0
596588
for x in filter(None, a):
597589
c += 1
598590
return c
599-
600-
[file driver.py]
601-
from native import f
602-
print(f([0, 1, 2, 3, 4, 5, 6]))
603-
604-
[out]
605-
6
606-
607-
[case testRunForFilterNative]
608-
def f(x: int) -> int:
591+
def native_func(x: int) -> int:
609592
return x % 2
610-
def g(a: list[int]) -> int:
593+
def with_native_func(a: list[int]) -> int:
611594
c = 0
612-
for x in filter(f, a):
595+
for x in filter(native_func, a):
613596
c += 1
614597
return c
615-
616-
[file driver.py]
617-
from native import g
618-
print(g([0, 1, 2, 3, 4, 5, 6]))
619-
620-
[out]
621-
3
622-
623-
[case testRunForFilterPrimitiveOp]
624-
def f(a: list[list[int]]) -> int:
598+
def with_primitive(a: list[list[int]]) -> int:
625599
c = 0
626600
for x in filter(len, a):
627601
c += 1
628602
return c
629603

630-
[file driver.py]
631-
from native import f
632-
print(f([[], [0, 1], [], [], [2, 3, 4], [5, 6]]))
633-
634-
[out]
635-
3
636-
637-
[case testRunForFilterEdgeCases]
638-
def f(a: list[int]) -> int:
639-
s = 0
640-
for x in filter(lambda x: x > 10, a):
641-
s += x
642-
return s
643-
644-
[file driver.py]
645-
from native import f
646-
print(f([5, 15, 25]))
647-
print(f([]))
648-
649-
[out]
650-
40
651-
0
604+
def test_run_for_filter() -> None:
605+
assert f([1, 2, 3, 4, 5, 6]) == 12
606+
assert f([1, 3, 5]) == 0
607+
assert f([]) == 0
608+
def test_run_for_filter_with_none() -> None:
609+
assert with_none([0, 1, 2, 3, 4, 5, 6]) == 6
610+
def test_run_for_filter_with_native_func() -> None:
611+
assert with_native_func([0, 1, 2, 3, 4, 5, 6]) == 3
612+
def test_run_for_filter_with_primitive() -> None:
613+
assert with_primitive([[], [0, 1], [], [], [2, 3, 4], [5, 6]]) == 3
614+
def test_run_for_filter_edge_cases() -> None:
615+
assert g([5, 15, 25]) == 40
616+
assert g([]) == 0

0 commit comments

Comments
 (0)