diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2023-11-28 23:54:38 +0100 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2023-11-28 23:54:38 +0100 |
commit | a84cbf18f18726535e10696cccc62a13fce507d1 (patch) | |
tree | c4b970f017c5a7c64135966f698cc9b6a70ead52 | |
parent | chmod +x executables (diff) | |
download | sorting-algorithms-a84cbf18f18726535e10696cccc62a13fce507d1.tar.gz sorting-algorithms-a84cbf18f18726535e10696cccc62a13fce507d1.zip |
test.py: formatting fixes
Diffstat (limited to '')
-rwxr-xr-x | test.py | 11 |
1 files changed, 11 insertions, 0 deletions
@@ -12,9 +12,11 @@ import sys from algorithms.input_kind import InputKind import algorithms.registry as registry + _DEFAULT_INPUT_KIND = InputKind.AVERAGE _DEFAULT_LENGTH = 100 + def test(algorithm, input_kind=_DEFAULT_INPUT_KIND, length=_DEFAULT_LENGTH): if isinstance(algorithm, str): algorithm = registry.get(algorithm) @@ -24,6 +26,7 @@ def test(algorithm, input_kind=_DEFAULT_INPUT_KIND, length=_DEFAULT_LENGTH): output = output.tolist() print(output) + def _parse_non_negative_integer(s): try: n = int(s) @@ -33,28 +36,34 @@ def _parse_non_negative_integer(s): raise argparse.ArgumentTypeError('must be a non-negative integer') return n + def _parse_input_kind(s): try: return InputKind(s) except ValueError: raise argparse.ArgumentTypeError('invalid input kind: ' + str(s)) + def _format_algorithm(codename): return '* {}: {}'.format(codename, registry.get(codename).display_name) + def _format_available_algorithms(): descr = 'available algorithms (in the CODENAME: DISPLAY_NAME format):\n' return descr + '\n'.join(map( _format_algorithm, sorted(registry.get_codenames()))) + def _format_description(): return _format_available_algorithms() + def _create_argument_parser(): return argparse.ArgumentParser( description=_format_description(), formatter_class=argparse.RawDescriptionHelpFormatter) + def _parse_args(args=None): if args is None: args = sys.argv[1:] @@ -75,8 +84,10 @@ def _parse_args(args=None): return parser.parse_args(args) + def main(args=None): test(**vars(_parse_args(args))) + if __name__ == '__main__': main() |