85 lines
4.0 KiB
Python
85 lines
4.0 KiB
Python
import sys
|
|
from subprocess import Popen, PIPE
|
|
|
|
######################################################################################################################
|
|
# TODO: #
|
|
# 1) PUT THIS FILE IN THE SAME FOLDER AS THE PYTHON FILE CONTAINING YOUR SOLUTION #
|
|
# 2) CHANGE THE NAME 'MY_FILE_NAME.py' BELOW THIS BOX TO THE NAME OF YOUR PYTHON FILE #
|
|
# 3) RUN THIS FILE #
|
|
######################################################################################################################
|
|
|
|
YOUR_SOLUTION_FILE_NAME = "paswoordchecker_runevanoverloop_v2.py"
|
|
|
|
######################################################################################################################
|
|
# DO NOT CHANGE ANYTHING BELOW THIS LINE #
|
|
######################################################################################################################
|
|
|
|
|
|
# Parse the given output string into a readable string
|
|
|
|
def parse_output(full_output_string):
|
|
try:
|
|
print(full_output_string)
|
|
output = str(full_output_string).replace('\\n', ' ').replace(',', '').replace('\\r', ' ').replace('(', '')\
|
|
.replace(')', '').replace('"', '').replace('\'', '')
|
|
except:
|
|
output = None
|
|
return output
|
|
|
|
|
|
# Run one test case with given input and output, return True when test succeeds, False when test fails
|
|
def run_one_test_case(inp, expected_output):
|
|
process = Popen([sys.executable, YOUR_SOLUTION_FILE_NAME], stdin=PIPE, stdout=PIPE, stderr=PIPE)
|
|
(output, err) = process.communicate(inp)
|
|
if len(str(err)) > 3:
|
|
print(err)
|
|
print("Je programma gooide een error. "
|
|
"(Kijk eventueel ook na of de naam en locatie van je programma correct zijn.)")
|
|
return False
|
|
process.wait()
|
|
output = output.decode('utf-8').replace("\n", "").replace("\r", "")
|
|
# parsed_output = parse_output(output)
|
|
parsed_output = output
|
|
if parsed_output is None:
|
|
print("Controleer het formaat van je output! Geef enkel de gevraagde numerieke waarden, en géén tekst!"
|
|
" Kijk ook na dat je bij input() geen prompt meegeeft.")
|
|
return False
|
|
print("EXPECTED: ", expected_output.replace(" ", "*"))
|
|
print ("OUTPUT: ", parsed_output.replace(" ", "*"))
|
|
return parsed_output == expected_output
|
|
|
|
|
|
# Retrieve a list containing all test_cases
|
|
def get_test_cases():
|
|
test_cases = []
|
|
# In: 1234560 Uit: ZWAK! LENGTE HOOFDLETTER KLEINELETTER SPECIAALTEKEN
|
|
test_cases.append((b"123456", "ZWAK! LENGTE HOOFDLETTER KLEINELETTER SPECIAALTEKEN "))
|
|
# In: Admin123 Uit: ZWAK! LENGTE SPECIAALTEKEN
|
|
test_cases.append((b"Admin123", "ZWAK! LENGTE SPECIAALTEKEN "))
|
|
# In: paswoord2022 Uit: ZWAK! HOOFDLETTER SPECIAALTEKEN
|
|
test_cases.append((b"paswoord2022", "ZWAK! HOOFDLETTER SPECIAALTEKEN "))
|
|
# In: mi*IS*SUP3Rc88l Uit: STERK!
|
|
test_cases.append((b"mi*IS*SUP3Rc88l", "STERK! "))
|
|
# In: mi*IS*SUP3Rc88l Uit: ZWAK! SPATIE
|
|
test_cases.append((b" mi*IS*SUP3Rc88l ", "ZWAK! SPATIE "))
|
|
# In: Paswoord 2022 Uit: ZWAK! SPECIAALTEKEN
|
|
test_cases.append((b"Paswoord 2022", "ZWAK! SPECIAALTEKEN "))
|
|
return test_cases
|
|
|
|
|
|
# Run all given test_cases
|
|
def run_test_cases(all_tests):
|
|
print("Alle tests worden uitgevoerd")
|
|
print("Spaties zijn vervangen door *")
|
|
for test_nb in range(len(all_tests)):
|
|
(inp, exp_out) = all_tests[test_nb]
|
|
test_result = run_one_test_case(inp, exp_out)
|
|
if test_result:
|
|
print('Test ' + str(test_nb + 1) + ': Succeeded')
|
|
else:
|
|
print('Test ' + str(test_nb + 1) + ': Failed')
|
|
|
|
|
|
# Load all test cases and test them
|
|
run_test_cases(get_test_cases())
|