diff options
| author | Egor Tensin <Egor.Tensin@gmail.com> | 2017-05-29 06:55:50 +0300 |
|---|---|---|
| committer | Egor Tensin <Egor.Tensin@gmail.com> | 2017-05-29 06:55:50 +0300 |
| commit | d90a93d7f1224a43ef4baf24281e0df7bdde5413 (patch) | |
| tree | d11f2dc3eeecca8de5722cbe998ad222cdcc7e9b /algorithms/inputgen.py | |
| parent | code style (diff) | |
| download | sorting-algorithms-d90a93d7f1224a43ef4baf24281e0df7bdde5413.tar.gz sorting-algorithms-d90a93d7f1224a43ef4baf24281e0df7bdde5413.zip | |
algorithms.inputgen -> algorithms.input_kind
Diffstat (limited to 'algorithms/inputgen.py')
| -rw-r--r-- | algorithms/inputgen.py | 31 |
1 files changed, 0 insertions, 31 deletions
diff --git a/algorithms/inputgen.py b/algorithms/inputgen.py deleted file mode 100644 index 998f1d6..0000000 --- a/algorithms/inputgen.py +++ /dev/null @@ -1,31 +0,0 @@ -# Copyright (c) 2016 Egor Tensin <Egor.Tensin@gmail.com> -# This file is part of the "Sorting algorithms" project. -# For details, see https://github.com/egor-tensin/sorting-algorithms. -# Distributed under the MIT License. - -from array import array -from enum import Enum -from random import seed, sample - -seed() - -class InputKind(Enum): - BEST, AVERAGE, WORST = 'best', 'average', 'worst' - - def __str__(self): - return self.value - -def _gen_input_from(xs): - return array('l', xs) - -def gen_input_for_sorting(n, case=InputKind.AVERAGE): - if n < 0: - 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: - return _gen_input_from(sample(range(n), n)) - elif case is InputKind.WORST: - return _gen_input_from(range(n - 1, -1, -1)) - else: - raise NotImplementedError('invalid input kind: ' + str(case)) |
