File tree Expand file tree Collapse file tree 3 files changed +25
-10
lines changed Expand file tree Collapse file tree 3 files changed +25
-10
lines changed Original file line number Diff line number Diff line change @@ -41,7 +41,7 @@ def int_to_factoradic(num: int) -> str:
4141 return Stream (digits ).map (DIGITS .__getitem__ ).collect ("" .join )
4242
4343
44- def test () -> None :
44+ def test () -> int | str :
4545 """Test this."""
4646 test_cases : tuple [tuple [int , str ], ...] = (
4747 (1 , "1" ),
@@ -59,8 +59,12 @@ def test() -> None:
5959 )
6060
6161 for i , f in test_cases :
62- assert (_ := factoradic_to_int (f )) == i , f"{ _ !r} != { i !r} "
63- assert (_ := int_to_factoradic (i )) == f , f"{ _ !r} != { f !r} "
62+ if (_ := factoradic_to_int (f )) != i :
63+ return f"{ _ !r} != { i !r} "
64+ if (_ := int_to_factoradic (i )) != f :
65+ return f"{ _ !r} != { f !r} "
66+
67+ return 0
6468
6569
6670if __name__ == "__main__" :
Original file line number Diff line number Diff line change 11#! /bin/sh
2+ set -e
3+
24if [ -z " $1 " ]; then
35 N=" 1"
46else
57 N=" $1 "
68fi
79
10+ set -u
11+
812if [ -f " ./nth_prime.sh" ]; then
913 DIR=" ."
1014elif [ -f " ./examples/nth_prime.sh" ]; then
Original file line number Diff line number Diff line change 33from __future__ import annotations
44
55from pathlib import Path
6- from subprocess import PIPE , run
6+ from subprocess import PIPE , run # nosec
77
88from ..factoradic import test
99from ..print_primes import test_prime_stream
1616
1717def _get_nth_prime (num : int ) -> int :
1818 """Run nth_prime.sh."""
19- command = [(EXAMPLES_DIR / "nth_prime.sh" ).as_posix (), str (num )]
20- return int (run (command , check = True , stdout = PIPE ).stdout )
21-
22-
23- assert _get_nth_prime (100_000 ) == 1299709
24- assert _get_nth_prime (200_000 ) == 2750159
19+ return int (
20+ run ( # nosec
21+ ["./nth_prime.sh" , str (num )],
22+ check = True ,
23+ stdout = PIPE ,
24+ shell = False ,
25+ cwd = EXAMPLES_DIR ,
26+ ).stdout
27+ )
28+
29+
30+ assert _get_nth_prime (100_000 ) == 1299709 # nosec
31+ assert _get_nth_prime (200_000 ) == 2750159 # nosec
You can’t perform that action at this time.
0 commit comments