2021-10-22 15:29:01 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
# IMPORTS
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
import os;
|
2021-10-23 13:20:37 +02:00
|
|
|
import sys
|
2021-10-22 15:29:01 +02:00
|
|
|
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))));
|
|
|
|
|
2021-10-23 13:20:37 +02:00
|
|
|
from code.core.log import *;
|
|
|
|
from code.core.config import *;
|
|
|
|
from code.display.display import *;
|
|
|
|
from code.algorithms.exports import *;
|
2021-10-22 15:29:01 +02:00
|
|
|
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
# GLOBAL VARIABLES/CONSTANTS
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
2021-10-23 11:29:30 +02:00
|
|
|
parser: argparse.ArgumentParser;
|
2021-10-23 13:20:37 +02:00
|
|
|
PATH_TO_CONFIG: str = 'code/config.yml';
|
2021-10-22 15:29:01 +02:00
|
|
|
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
# MAIN PROCESS
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
2021-10-23 13:23:07 +02:00
|
|
|
def enter(quiet: bool, debug: bool, path: Union[str, Any], **_):
|
|
|
|
SetQuietMode(quiet);
|
|
|
|
SetDebugMode(debug);
|
2021-10-23 13:20:37 +02:00
|
|
|
configpath = PATH_TO_CONFIG if args.path is None else args.path;
|
2021-10-23 11:29:30 +02:00
|
|
|
if args.all is not None:
|
2021-10-23 13:20:37 +02:00
|
|
|
LoopThroughCases(path=configpath);
|
2021-10-23 11:29:30 +02:00
|
|
|
else:
|
|
|
|
parser.print_help();
|
2021-10-22 15:29:01 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
# SECONDARY PROCESSES
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
2021-10-23 13:20:37 +02:00
|
|
|
def LoopThroughCases(path: str):
|
|
|
|
'''
|
|
|
|
Durchlauf aller Testfälle.
|
|
|
|
'''
|
|
|
|
config = ReadConfigFile(path);
|
|
|
|
cases = GetAttribute(config, 'parts', 'cases', expectedtype=list, default=[]);
|
|
|
|
for caseindex, case in enumerate(cases):
|
2021-10-24 12:40:09 +02:00
|
|
|
DisplayStartOfCase(caseindex);
|
2021-10-23 13:20:37 +02:00
|
|
|
|
|
|
|
command = GetAttribute(case, 'command', expectedtype=str, default='');
|
|
|
|
inputs = GetAttribute(case, 'inputs', expectedtype=dict, default={});
|
|
|
|
|
2021-10-24 12:28:37 +02:00
|
|
|
try:
|
|
|
|
if command == 'algorithm-search-sequential':
|
|
|
|
SequentialSearch(L=inputs['L'], x=inputs['x']);
|
|
|
|
elif command == 'algorithm-search-binary':
|
|
|
|
BinarySearch(L=inputs['L'], x=inputs['x']);
|
|
|
|
elif command == 'algorithm-search-interpolation':
|
|
|
|
InterpolationSearch(L=inputs['L'], x=inputs['x'], u=0, v=len(inputs['L'])-1);
|
|
|
|
elif command == 'algorithm-search-jump':
|
|
|
|
JumpSearchLinear(L=inputs['L'], x=inputs['x'], m=inputs['m']);
|
|
|
|
else:
|
|
|
|
raise ValueError('Command \033[1m{}\033[0m nicht erkannt'.format(command));
|
|
|
|
except Exception as e:
|
|
|
|
logError(e);
|
2021-10-24 12:40:09 +02:00
|
|
|
DisplayEndOfCase();
|
2021-10-22 15:29:01 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
# EXECUTE CODE
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2021-10-23 13:20:37 +02:00
|
|
|
sys.tracebacklimit = 0;
|
2021-10-23 11:29:30 +02:00
|
|
|
cli_args = sys.argv[1:];
|
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
prog='code/main.py',
|
2021-10-23 17:55:02 +02:00
|
|
|
description='''
|
|
|
|
\033[2;1mBeschreibung:\033[0m
|
|
|
|
\033[2mEin Programm, das verschiedene Algorithmen aus dem Kurs AlgoDat I testet.\033[0m
|
|
|
|
''',
|
2021-10-23 11:29:30 +02:00
|
|
|
);
|
2021-10-23 17:40:16 +02:00
|
|
|
parser.add_argument('all', nargs='?', help='Führt alle Testfälle in der config.yml Datei durch.');
|
|
|
|
parser.add_argument('--path', nargs=1, type=str, help='Pfad zur alternativen Configdatei.');
|
|
|
|
parser.add_argument('config', nargs='?', help='Führt alle Testfälle in der config.yml Datei durch.');
|
|
|
|
parser.add_argument('--debug', action='store_true', help='Debugging Messages stummschalten.')
|
2021-10-23 11:29:30 +02:00
|
|
|
parser.add_argument('-q', '--quiet', action='store_true', help='Alle console-messages bis auf Errors stummschalten.')
|
2021-10-23 13:23:07 +02:00
|
|
|
args = parser.parse_args(cli_args);
|
|
|
|
enter(quiet=args.quiet, debug=args.debug, path=args.path);
|