Advertisement
Ametrin

testdriver_super

Feb 15th, 2020
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.36 KB | None | 0 0
  1. import subprocess
  2. import os.path
  3. import pickle
  4.  
  5.  
  6. def test_task(tests, task_name, rule):
  7.     scores = []
  8.     for test in tests:
  9.         task = subprocess.Popen(["python", task_name], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
  10.         res, err = task.communicate(test[0])
  11.         if rule == "eq":
  12.             if res.decode("utf-8").rstrip() == test[1]:
  13.                 scores.append(4)
  14.             else:
  15.                 scores.append(0)
  16.         elif "sort":
  17.             res_arr = res.decode("utf-8").rstrip().split(" ")
  18.             res_arr.sort()
  19.             test_arr = test[1].split(" ")
  20.             test_arr.sort()
  21.             if res_arr == test_arr:
  22.                 scores.append(4)
  23.             else:
  24.                 scores.append(0)
  25.     return scores
  26.  
  27.  
  28. if __name__ == "__main__":
  29.     with open("test_cases.pickle", "rb") as f:
  30.         test_cases = pickle.load(f)
  31.  
  32.     total = 0
  33.     for i in range(0, 5):
  34.         file_task = "task{i}.py".format(i=i+1)
  35.         if os.path.exists(file_task) and len(test_cases) > i:
  36.             res = test_task(test_cases[i], file_task, "eq" if i != 4 else "sort")
  37.             total += sum(res)
  38.             print("{task}: {res}. Total: {sum}".format(task=file_task, res=res, sum=sum(res)))
  39.         else:
  40.             print("{task} not found".format(task=file_task))
  41.     print("Total: {total}".format(total=total))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement