SHARE
TWEET

testdriver

Ametrin Feb 14th, 2020 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import subprocess
  2. import os.path
  3.  
  4. test_cases = [[(b"""19
  5. 24
  6. 23
  7. 25
  8. 22
  9. 40
  10. 57
  11. 14
  12. 12
  13. 23
  14. """, "34"),
  15.              (b"""1
  16. 1
  17. 1
  18. 1
  19. 1
  20. 1
  21. 1
  22. 1
  23. 1
  24. 1
  25. """, "1"),
  26.              (b"""-4
  27. -3
  28. -2
  29. -1
  30. 0
  31. 1
  32. 2
  33. 3
  34. 4
  35. 5
  36. """, "0"),
  37.              (b"""0
  38. 0
  39. 0
  40. 0
  41. 0
  42. 0
  43. 0
  44. 0
  45. 0
  46. 0
  47. """, "0"),
  48.              (b"""1
  49. 11
  50. 111
  51. 2
  52. 22
  53. 222
  54. 3
  55. 333
  56. 33
  57. 123
  58. """, "167") ],
  59.             [(b"abc de f gh hij klmn opqrs", "opqrs"),
  60.              (b"qwerty asdf zxc", "qwerty"),
  61.              (b"aaa bbb ccc", "aaa"),
  62.              (b"a v z", "a"),
  63.              (b"testestestestestestestestestestestestestestestestsetset", "testestestestestestestestestestestestestestestestsetset")],
  64.          [(b"123456789", "97531"),
  65.           (b"5000 rubley menshe 100 dollarov no bolshe 1300 yen", "5311"),
  66.           (b"ne imei 100 rubley a imey horoshih druzey", "1"),
  67.           (b"9 zaytcev sobraly 99 morkovok ostalas 1", "9991"),
  68.           (b"7", "7")],
  69.          [(b"abcde", "zcded"),
  70.           (b"qWeRtY", "rXdSuX"),
  71.           (b"asdf JKL", "zteg KLM"),
  72.           (b"Clannad Kanon Air", "Dmzooze Lzono Zhs"),
  73.           (b"test", "udtu")],
  74.          [(b"a", "a"),
  75.           (b"a b c", "a b c"),
  76.           (b"test estt stte ttes", "t"),
  77.           (b"abc baC xyz YxZ", "c z"),
  78.           (b"A AND B", "a d b")]]
  79.  
  80.  
  81. def test_task(tests, task_name):
  82.     scores = []
  83.     for test in tests:
  84.         task = subprocess.Popen(["python", task_name], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
  85.         res, err = task.communicate(test[0])
  86.         if res.decode("utf-8").rstrip() == test[1]:
  87.             scores.append(4)
  88.         else:
  89.             scores.append(0)
  90.     return scores
  91.  
  92.  
  93. if __name__ == "__main__":
  94.     total = 0
  95.     for i in range(0, 5):
  96.         file_task = "task{i}.py".format(i=i+1)
  97.         if os.path.exists(file_task) and len(test_cases) > i:
  98.             res = test_task(test_cases[i], file_task)
  99.             total += sum(res)
  100.             print("{task}: {res}. Total: {sum}".format(task=file_task, res=res, sum=sum(res)))
  101.         else:
  102.             print("{task} not found".format(task=file_task))
  103.     print("Total: {total}".format(total=total))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top