From 97e13d167e5ccdc02e2c1ac34b9179cbe316db14 Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Sat, 13 Oct 2018 23:06:27 +0200 Subject: Fix two tasks --- .../tasks/copy_rename_20_files_tail_env/task.py | 20 ++++++-------- .../tasks/edit_find_grep_compile_convert/task.py | 32 +++++++++++----------- 2 files changed, 25 insertions(+), 27 deletions(-) diff --git a/kpov_judge/tasks/copy_rename_20_files_tail_env/task.py b/kpov_judge/tasks/copy_rename_20_files_tail_env/task.py index 6a4b18a..ce51c9c 100644 --- a/kpov_judge/tasks/copy_rename_20_files_tail_env/task.py +++ b/kpov_judge/tasks/copy_rename_20_files_tail_env/task.py @@ -182,11 +182,7 @@ def task_check(results, params): #TO FINISH SCORING WE REQUIRE DICT KEYS AND FUNCTIONS gen_params AND task TO BE FINISHED # preimenuj 1 - lines = results['preimenuj'].split("\n") - task1_ok = len(lines) == len(fnames) + 4 - task1_ok = task1_ok and lines[0].find(params['file_rename_dirname']) >= 0 - task1_ok = task1_ok and lines[1].strip() == "." - task1_ok = task1_ok and lines[2].strip() == ".." + task1_ok = True for fname in fnames: task1_ok = task1_ok and results['preimenuj'].find(fname) > 0 if task1_ok: @@ -212,14 +208,16 @@ def task_check(results, params): hints += ["wrong mv_command size or owner"] # rename files - pre_src = set([i.strip() for i in results['pre_mv_src'].split('\n')[3:-1]]) - pre_dst = set([i.strip() for i in results['pre_mv_dst'].split('\n')[3:-1]]) + pre_src = set([i.strip() for i in results['pre_mv_src'].splitlines()[2:]]) + pre_dst = set([i.strip() for i in results['pre_mv_dst'].splitlines()[2:]]) + print(set(fnames)) + print(pre_src) task2_ok = task2_ok and pre_src == set(fnames) - task2_ok = task2_ok and len(pre_dst) < 2 - post_src = set([i.strip() for i in results['post_mv_src'].split('\n')[3:-1]]) - post_dst = set([i.strip() for i in results['post_mv_dst'].split('\n')[3:-1]]) + task2_ok = task2_ok and len(pre_dst) < 3 + post_src = set([i.strip() for i in results['post_mv_src'].splitlines()[2:]]) + post_dst = set([i.strip() for i in results['post_mv_dst'].splitlines()[2:]]) task2_ok = task2_ok and post_dst == set(fnames) - task2_ok = task2_ok and len(post_src) < 2 + task2_ok = task2_ok and len(post_src) < 3 if task2_ok: score += 1 else: diff --git a/kpov_judge/tasks/edit_find_grep_compile_convert/task.py b/kpov_judge/tasks/edit_find_grep_compile_convert/task.py index 48b713b..deaac4f 100644 --- a/kpov_judge/tasks/edit_find_grep_compile_convert/task.py +++ b/kpov_judge/tasks/edit_find_grep_compile_convert/task.py @@ -192,7 +192,7 @@ def task(testip, testuser, passwd, magicstr, dstfile, progname, pubseed): tests += [('tita-{:02}'.format(i), 'echo -e "\\{}" | ~/{} {}'.format(x, progname, b))] results = kpov_util.ssh_test(testip, testuser, passwd, tests) - results['tita_return'] = ''.join(val for key, val in results.items() if key.startswith('tita-')) + results['tita_return'] = ''.join(results['tita-{:02}'.format(i)] for i in range(N_TITA)) return results @@ -220,8 +220,13 @@ def task_check(results, params): N_TITA = 40 hints = [] score = 0 - hidden_contents = params['magicstr'] r = random.Random(params['rndseed']) + + if results['ssh'] is not True: + hints += ['ssh failed: ' + results['ssh']] + return score, hints + + expected_contents = params['magicstr'] for i in range(1000): start = "".join([r.choice(["po", "p0", "no", "ko", "fo", "qo"]) for i in range(20)]) mid = "".join([r.choice("uiasdfghjkyxcvbnm1234567890ASDFGHJKYZXCVBNM") for i in range(60)]) @@ -230,20 +235,15 @@ def task_check(results, params): start = "po" mid = "kaka" x = start + mid + end - hidden_contents += x + "\r\n" - expected_contents = hidden_contents + expected_contents += x + "\r\n" if results["dst_file_contents"] == expected_contents: score += 3 else: - diff_pos = "" - for i, c in enumerate(results["dst_file_contents"]): - if len(expected_contents) < i or c != expected_contents[i]: - start = max(0, i-10) - end = min(len(expected_contents), len(results["dst_file_contents"]), i+20) - diff_pos = (i, results["dst_file_contents"][start:end]) + for i, (a, b) in enumerate(zip(expected_contents, results['dst_file_contents'])): + if a != b: break - hints += ["wrong file contents\n" + str(diff_pos[1])] - #hints += ["wrong file contents"] + hints += ['wrong file {} at position {}'.format(params['dstfile'], i)] + expected_ls = "-rw--w---- 1 {testuser} bilbo .*{dstfile}.*\r\n".format(**params) if re.match(expected_ls, results["dst_ls"]): score += 3 @@ -253,20 +253,20 @@ def task_check(results, params): score += 2 else: hints += ["missing program"] + expected_tita = "" r = random.Random(params['pubseed']) for i in range(N_TITA): b = r.randint(0, 7) x_i = r.randint(37, 127) - x = oct(x_i).replace('o', '') if x_i & (1 << b): - expected_tita += "ta\r\n" + expected_tita += "ta" else: - expected_tita += "ti\r\n" + expected_tita += "ti" if results["tita_return"] == expected_tita: score += 2 else: - hints += ["program output incorrect\n" + results["tita_return"]] + hints += ['program output incorrect:\nwanted:\t{}\ngot:\t{}'.format(expected_tita, results["tita_return"])] return score, hints -- cgit v1.2.1