aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/test.py
diff options
context:
space:
mode:
Diffstat (limited to 'test.py')
-rw-r--r--test.py26
1 files changed, 13 insertions, 13 deletions
diff --git a/test.py b/test.py
index b3d9dd3..7acc4bf 100644
--- a/test.py
+++ b/test.py
@@ -4,23 +4,23 @@
from enum import Enum
-class InputKind(Enum):
- SORTED, RANDOMIZED, REVERSED = 'sorted', 'randomized', 'reversed'
+class OrderType(Enum):
+ ASCENDING, RANDOM, DESCENDING = 'ascending', 'random', 'descending'
def __str__(self):
return self.value
def gen_input(kind, n):
- if kind is InputKind.SORTED:
+ if kind is OrderType.ASCENDING:
return list(range(n))
- elif kind is InputKind.REVERSED:
+ elif kind is OrderType.DESCENDING:
return sorted(range(n), reverse=True)
- elif kind is InputKind.RANDOMIZED:
+ elif kind is OrderType.RANDOM:
from random import sample
return sample(range(n), n)
else:
raise NotImplementedError(
- 'invalid initial input state \'{}\''.format(kind))
+ 'invalid input ordering: \'{}\''.format(kind))
if __name__ == '__main__':
import algorithms.registry
@@ -30,9 +30,9 @@ if __name__ == '__main__':
if n < 0:
raise argparse.ArgumentTypeError('cannot be negative')
return n
- def input_kind(s):
+ def order(s):
try:
- return InputKind(s)
+ return OrderType(s)
except ValueError:
raise argparse.ArgumentError()
@@ -41,13 +41,13 @@ if __name__ == '__main__':
parser.add_argument('--algorithm', '-l', required=True,
choices=algorithms.registry.get_codenames(),
help='specify algorithm codename')
- parser.add_argument('--input', '-i',
- choices=tuple(x for x in InputKind),
- type=input_kind, default=InputKind.RANDOMIZED,
- help='set initial input state')
+ parser.add_argument('--order', '-i',
+ choices=tuple(x for x in OrderType),
+ type=order, default=OrderType.RANDOM,
+ help='specify input order')
parser.add_argument('--length', '-n',
type=natural_number, default=100,
help='set input length')
args = parser.parse_args()
- xs = gen_input(args.input, args.length)
+ xs = gen_input(args.order, args.length)
print(algorithms.registry.get(args.algorithm).get_function()(xs))