diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2017-01-12 12:57:57 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2017-01-12 12:57:57 +0300 |
commit | 4967f628f78f7648b582a2ae705bd13aede16a76 (patch) | |
tree | 0a15cf64738cd1a63d02e030fed749e24f682c5b | |
parent | fix licensing notices (diff) | |
download | sorting-algorithms-4967f628f78f7648b582a2ae705bd13aede16a76.tar.gz sorting-algorithms-4967f628f78f7648b582a2ae705bd13aede16a76.zip |
mostly Pylint fixes
-rw-r--r-- | .pylintrc | 91 | ||||
-rw-r--r-- | algorithms/algorithm.py | 2 | ||||
-rw-r--r-- | algorithms/impl/bubble_sort.py | 8 | ||||
-rw-r--r-- | algorithms/impl/heapsort.py | 8 | ||||
-rw-r--r-- | algorithms/impl/insertion_sort.py | 8 | ||||
-rw-r--r-- | algorithms/impl/median.py | 8 | ||||
-rw-r--r-- | algorithms/impl/merge_sort.py | 8 | ||||
-rw-r--r-- | algorithms/impl/quicksort.py | 8 | ||||
-rw-r--r-- | algorithms/impl/selection_sort.py | 8 | ||||
-rw-r--r-- | algorithms/inputgen.py | 2 | ||||
-rw-r--r-- | algorithms/params.py | 6 | ||||
-rw-r--r-- | algorithms/timer.py | 3 | ||||
-rw-r--r-- | plot.py | 18 | ||||
-rw-r--r-- | test.py | 16 |
14 files changed, 63 insertions, 131 deletions
@@ -1,92 +1,3 @@ [MESSAGES CONTROL] -# Disable the message, report, category or checker with the given id(s). You -# can either give multiple identifiers separated by comma (,) or put this -# option multiple times (only on the command line, not in the configuration -# file where it should appear only once).You can also use "--disable=all" to -# disable everything first and then reenable specific checks. For example, if -# you want to run only the similarities checker, you can use "--disable=all -# --enable=similarities". If you want to run only the classes checker, but have -# no Warning level messages displayed, use"--disable=all --enable=classes -# --disable=W" -disable=line-too-long,missing-docstring,multiple-imports - -[BASIC] - -# List of builtins function names that should not be used, separated by a comma -bad-functions= - -# Good variable names which should always be accepted, separated by a comma -good-names=i,j,k - -# Bad variable names which should always be refused, separated by a comma -bad-names= - -# Colon-delimited sets of names that determine each other's naming style when -# the name regexes allow several styles. -name-group= - -# Include a hint for the correct naming format with invalid-name -include-naming-hint=no - -# Regular expression matching correct inline iteration names -inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$ - -# Naming hint for inline iteration names -inlinevar-name-hint=[A-Za-z_][A-Za-z0-9_]*$ - -# Regular expression matching correct method names -method-rgx=[a-z_][a-z0-9_]{2,30}$ - -# Naming hint for method names -method-name-hint=[a-z_][a-z0-9_]{2,30}$ - -# Regular expression matching correct class names -class-rgx=[A-Z_][a-zA-Z0-9]+$ - -# Naming hint for class names -class-name-hint=[A-Z_][a-zA-Z0-9]+$ - -# Regular expression matching correct attribute names -attr-rgx=[a-z_][a-z0-9_]{0,30}$ - -# Naming hint for attribute names -attr-name-hint=[a-z_][a-z0-9_]{0,30}$ - -# Regular expression matching correct function names -function-rgx=[a-z_][a-z0-9_]{2,30}$ - -# Naming hint for function names -function-name-hint=[a-z_][a-z0-9_]{2,30}$ - -# Regular expression matching correct module names -module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ - -# Naming hint for module names -module-name-hint=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ - -# Regular expression matching correct class attribute names -class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{1,30}|(__.*__))$ - -# Naming hint for class attribute names -class-attribute-name-hint=([A-Za-z_][A-Za-z0-9_]{1,30}|(__.*__))$ - -# Regular expression matching correct variable names -variable-rgx=[a-z_][a-z0-9_]{0,30}$ - -# Naming hint for variable names -variable-name-hint=[a-z_][a-z0-9_]{0,30}$ - -# Regular expression matching correct argument names -argument-rgx=[a-z_][a-z0-9_]{0,30}$ - -# Naming hint for argument names -argument-name-hint=[a-z_][a-z0-9_]{0,30}$ - -# Regular expression which should only match function or class names that do -# not require a docstring. -no-docstring-rgx=^_ - -# Minimum line length for functions/classes that require docstrings, shorter -# ones are exempt. -docstring-min-length=-1 +disable=invalid-name,missing-docstring diff --git a/algorithms/algorithm.py b/algorithms/algorithm.py index 2d793bc..673a525 100644 --- a/algorithms/algorithm.py +++ b/algorithms/algorithm.py @@ -13,7 +13,7 @@ class Algorithm: @staticmethod def gen_input(n, case=inputgen.InputKind.AVERAGE): - #raise NotImplementedError('inputgen generation is not defined for generic algorithms') + #raise NotImplementedError('input generation is not defined for generic algorithms') return inputgen.gen_input_for_sorting(n, case) class SortingAlgorithm(Algorithm): diff --git a/algorithms/impl/bubble_sort.py b/algorithms/impl/bubble_sort.py index e75ceab..95fb661 100644 --- a/algorithms/impl/bubble_sort.py +++ b/algorithms/impl/bubble_sort.py @@ -36,10 +36,12 @@ _ALGORITHMS = [ SortingAlgorithm('bubble_sort_optimized', 'Bubble sort (optimized)', bubble_sort_optimized), ] -def _parse_args(args=sys.argv): - return list(map(int, args[1:])) +def _parse_args(args=None): + if args is None: + args = sys.argv[1:] + return list(map(int, args)) -def main(args=sys.argv): +def main(args=None): xs = _parse_args(args) print(bubble_sort(list(xs))) print(bubble_sort_optimized(list(xs))) diff --git a/algorithms/impl/heapsort.py b/algorithms/impl/heapsort.py index 6615e14..bf9f464 100644 --- a/algorithms/impl/heapsort.py +++ b/algorithms/impl/heapsort.py @@ -58,10 +58,12 @@ _ALGORITHMS = [ SortingAlgorithm('heapsort', 'Heapsort', heapsort), ] -def _parse_args(args=sys.argv): - return list(map(int, args[1:])) +def _parse_args(args=None): + if args is None: + args = sys.argv[1:] + return list(map(int, args)) -def main(args=sys.argv): +def main(args=None): xs = _parse_args(args) print(heapsort(list(xs))) diff --git a/algorithms/impl/insertion_sort.py b/algorithms/impl/insertion_sort.py index d02b970..1abbf84 100644 --- a/algorithms/impl/insertion_sort.py +++ b/algorithms/impl/insertion_sort.py @@ -19,10 +19,12 @@ _ALGORITHMS = [ SortingAlgorithm('insertion_sort', 'Insertion sort', insertion_sort), ] -def _parse_args(args=sys.argv): - return list(map(int, args[1:])) +def _parse_args(args=None): + if args is None: + args = sys.argv[1:] + return list(map(int, args)) -def main(args=sys.argv): +def main(args=None): xs = _parse_args(args) print(insertion_sort(list(xs))) diff --git a/algorithms/impl/median.py b/algorithms/impl/median.py index d19dec4..b48e511 100644 --- a/algorithms/impl/median.py +++ b/algorithms/impl/median.py @@ -47,10 +47,12 @@ _ALGORITHMS = [ Algorithm('median_heaps', 'Median value (using heaps)', calc_median_heaps), ] -def _parse_args(args=sys.argv): - return list(map(int, args[1:])) +def _parse_args(args=None): + if args is None: + args = sys.argv[1:] + return list(map(int, args)) -def main(args=sys.argv): +def main(args=None): xs = _parse_args(args) print(calc_median_sorting(list(xs))) print(calc_median_heaps(list(xs))) diff --git a/algorithms/impl/merge_sort.py b/algorithms/impl/merge_sort.py index 3dd2bb9..2b96d21 100644 --- a/algorithms/impl/merge_sort.py +++ b/algorithms/impl/merge_sort.py @@ -33,10 +33,12 @@ _ALGORITHMS = [ SortingAlgorithm('merge_sort', 'Merge sort', merge_sort), ] -def _parse_args(args=sys.argv): - return list(map(int, args[1:])) +def _parse_args(args=None): + if args is None: + args = sys.argv[1:] + return list(map(int, args)) -def main(args=sys.argv): +def main(args=None): xs = _parse_args(args) print(merge_sort(list(xs))) diff --git a/algorithms/impl/quicksort.py b/algorithms/impl/quicksort.py index 3c4715a..1e835c4 100644 --- a/algorithms/impl/quicksort.py +++ b/algorithms/impl/quicksort.py @@ -69,10 +69,12 @@ _ALGORITHMS = [ SortingAlgorithm('quicksort_random', 'Quicksort (random element as pivot)', quicksort_random), ] -def _parse_args(args=sys.argv): - return list(map(int, args[1:])) +def _parse_args(args=None): + if args is None: + args = sys.argv[1:] + return list(map(int, args)) -def main(args=sys.argv): +def main(args=None): xs = _parse_args(args) print(quicksort_first(list(xs))) print(quicksort_second(list(xs))) diff --git a/algorithms/impl/selection_sort.py b/algorithms/impl/selection_sort.py index 0dbf4eb..ad4a420 100644 --- a/algorithms/impl/selection_sort.py +++ b/algorithms/impl/selection_sort.py @@ -21,10 +21,12 @@ _ALGORITHMS = [ SortingAlgorithm('selection_sort', 'Selection sort', selection_sort), ] -def _parse_args(args=sys.argv): - return list(map(int, args[1:])) +def _parse_args(args=None): + if args is None: + args = sys.argv[1:] + return list(map(int, args)) -def main(args=sys.argv): +def main(args=None): xs = _parse_args(args) print(selection_sort(list(xs))) diff --git a/algorithms/inputgen.py b/algorithms/inputgen.py index aeb4f29..998f1d6 100644 --- a/algorithms/inputgen.py +++ b/algorithms/inputgen.py @@ -20,7 +20,7 @@ def _gen_input_from(xs): def gen_input_for_sorting(n, case=InputKind.AVERAGE): if n < 0: - raise ValueError('input length must not be a negative number') + raise ValueError('input length cannot be less than zero') if case is InputKind.BEST: return _gen_input_from(range(n)) elif case is InputKind.AVERAGE: diff --git a/algorithms/params.py b/algorithms/params.py index b7fc38e..bf87976 100644 --- a/algorithms/params.py +++ b/algorithms/params.py @@ -57,7 +57,7 @@ class AlgorithmParameters: raise TypeError('must be an integral value') val = int(val) if val < 0: - raise ValueError('must not be a negative number') + raise ValueError('must be non-negative') if self.max_len is not None and self.max_len < val: raise ValueError('must not be greater than the maximum length') self._min_len = val @@ -72,7 +72,7 @@ class AlgorithmParameters: raise TypeError('must be an integral value') val = int(val) if val < 0: - raise ValueError('must not be a negative number') + raise ValueError('must be non-negative') if self.min_len is not None and self.min_len > val: raise ValueError('must not be lesser than the minimum length') self._max_len = val @@ -87,7 +87,7 @@ class AlgorithmParameters: raise TypeError('must be an integral value') val = int(val) if val < 1: - raise ValueError('must be a positive number') + raise ValueError('must be positive') self._iterations = val def measure_running_time(self): diff --git a/algorithms/timer.py b/algorithms/timer.py index 0d37812..bd5d044 100644 --- a/algorithms/timer.py +++ b/algorithms/timer.py @@ -3,7 +3,8 @@ # For details, see https://github.com/egor-tensin/sorting-algorithms. # Distributed under the MIT License. -import gc, time +import gc +import time def get_timestamp(): return time.perf_counter() @@ -29,7 +29,7 @@ def plot_algorithm(algorithm, input_kind=_DEFAULT_INPUT_KIND, iterations=iterations) params.plot_running_time(output_path) -def _parse_natural_number(s): +def _parse_non_negative_integer(s): try: n = int(s) except ValueError: @@ -38,7 +38,7 @@ def _parse_natural_number(s): raise argparse.ArgumentTypeError('must be a non-negative integer') return n -def _parse_positive_number(s): +def _parse_positive_integer(s): try: n = int(s) except ValueError: @@ -69,14 +69,16 @@ def _create_argument_parser(): description=_format_description(), formatter_class=argparse.RawDescriptionHelpFormatter) -def _parse_args(args=sys.argv): +def _parse_args(args=None): + if args is None: + args = sys.argv[1:] parser = _create_argument_parser() parser.add_argument('algorithm', metavar='CODENAME', choices=registry.get_codenames(), help='algorithm codename') parser.add_argument('--iterations', '-r', metavar='N', - type=_parse_positive_number, + type=_parse_positive_integer, default=_DEFAULT_ITERATIONS, help='set number of algorithm iterations') parser.add_argument('--input', '-i', dest='input_kind', @@ -84,19 +86,19 @@ def _parse_args(args=sys.argv): type=_parse_input_kind, default=_DEFAULT_INPUT_KIND, help='specify input kind') parser.add_argument('--min', '-a', metavar='N', dest='min_len', - type=_parse_natural_number, + type=_parse_non_negative_integer, default=_DEFAULT_MIN_LENGTH, help='set min input length') parser.add_argument('--max', '-b', metavar='N', dest='max_len', - type=_parse_natural_number, + type=_parse_non_negative_integer, default=_DEFAULT_MAX_LENGTH, help='set max input length') parser.add_argument('--output', '-o', metavar='PATH', dest='output_path', help='set plot file path') - return parser.parse_args(args[1:]) + return parser.parse_args(args) -def main(args=sys.argv): +def main(args=None): plot_algorithm(**vars(_parse_args(args))) if __name__ == '__main__': @@ -22,7 +22,7 @@ def test(algorithm, input_kind=_DEFAULT_INPUT_KIND, length=_DEFAULT_LENGTH): output = output.tolist() print(output) -def _parse_natural_number(s): +def _parse_non_negative_integer(s): try: n = int(s) except ValueError: @@ -53,7 +53,9 @@ def _create_argument_parser(): description=_format_description(), formatter_class=argparse.RawDescriptionHelpFormatter) -def _parse_args(args=sys.argv): +def _parse_args(args=None): + if args is None: + args = sys.argv[1:] parser = _create_argument_parser() parser.add_argument('algorithm', metavar='CODENAME', @@ -61,15 +63,17 @@ def _parse_args(args=sys.argv): help='algorithm codename') parser.add_argument('--input', '-i', dest='input_kind', choices=InputKind, - type=_parse_input_kind, default=_DEFAULT_INPUT_KIND, + type=_parse_input_kind, + default=_DEFAULT_INPUT_KIND, help='specify input kind') parser.add_argument('--length', '-l', '-n', metavar='N', - type=_parse_natural_number, default=_DEFAULT_LENGTH, + type=_parse_non_negative_integer, + default=_DEFAULT_LENGTH, help='set input length') - return parser.parse_args(args[1:]) + return parser.parse_args(args) -def main(args=sys.argv): +def main(args=None): test(**vars(_parse_args(args))) if __name__ == '__main__': |