diff options
| author | Egor Tensin <Egor.Tensin@gmail.com> | 2019-12-23 07:32:18 +0300 |
|---|---|---|
| committer | Egor Tensin <Egor.Tensin@gmail.com> | 2019-12-23 07:32:18 +0300 |
| commit | 0d25b5d6957d76bab486e2279c99e130c19d5c31 (patch) | |
| tree | c8c7d6fe4766470bda03e49a004afaa03c967b16 /algorithms/input_kind.py | |
| parent | Travis: add badge to README (diff) | |
| download | sorting-algorithms-0d25b5d6957d76bab486e2279c99e130c19d5c31.tar.gz sorting-algorithms-0d25b5d6957d76bab486e2279c99e130c19d5c31.zip | |
pylint/pep8 fixes
Diffstat (limited to 'algorithms/input_kind.py')
| -rw-r--r-- | algorithms/input_kind.py | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/algorithms/input_kind.py b/algorithms/input_kind.py index 998f1d6..08e1c9e 100644 --- a/algorithms/input_kind.py +++ b/algorithms/input_kind.py @@ -7,25 +7,28 @@ 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: + if case is InputKind.AVERAGE: return _gen_input_from(sample(range(n), n)) - elif case is InputKind.WORST: + if case is InputKind.WORST: return _gen_input_from(range(n - 1, -1, -1)) - else: - raise NotImplementedError('invalid input kind: ' + str(case)) + raise NotImplementedError('invalid input kind: ' + str(case)) |
