def test(self): main = TestedProgram('main') main.start_in_background() out = main.get_output() if out != '': return wrong('') sleep(0.15) out = main.get_output() if out != "Test\n": return wrong('') sleep(0.2) out = main.get_output() if out != "Test\nTest\n": return wrong('') main.stop() if not main.is_finished(): return wrong("") return correct()
def test(self): pr = TestedProgram('main') out1 = pr.start() if out1 != "Server started!\n": return wrong("") out1 = pr.execute("main") if out1 != "S1: main\n": return wrong("") pr.execute("main2") return correct()
def test(self): if '123.txt' in os.listdir('.'): if open('123.txt').read() == '12345': return correct() return wrong( 'There should be a file named "123.txt" with content "12345"')
def test(self): pr = TestedProgram('main') out1 = pr.start() if out1 != "Program started!\n": return wrong("") out3 = pr.execute("input1") if out3 != "S1: input1\n": return wrong("") out5 = pr.execute("input2") if out5 != "S2: input2\n": return wrong("") return correct()
def test1(self): pr = TestedProgram('main') pr.start() pr2 = TestedProgram('main2') pr2.start("--second", "main") return wrong('')
def test(self): pr = TestedProgram('main') out1 = pr.start() if out1 != "Server started!\n": return wrong("") return None
def test1(self): pr2 = TestedProgram('main2') pr2.start("--second", "main") pr = TestedProgram('main') pr.start("-in", "123", "-out", "234") return wrong('')
def test(self): main = TestedProgram('main') main.set_return_output_after_execution(False) out = main.start() if len(out) != 0: return wrong("Output should be empty") out = main.get_output() if out != "Initial text\n": return wrong("Output is wrong") for i in range(2): if len(main.execute('')) != 0: return wrong("Output should be empty") out = main.get_output() if out != "1 to 2\n2 to 3\n": return wrong("Output is wrong") main.set_return_output_after_execution(True) if main.execute("") != "3 to 4\n": return wrong("Output should not be empty") if len(main.get_output()) != 0: return wrong( "get_output() should return an empty string at the end") return correct()
def test(self): server = TestedProgram('main') server.start_in_background() sleep(0.05) out = server.get_output() if out != "Server started!\n": return wrong("") sleep(0.1) out = server.get_output() if out != "S1\n": return wrong("") sleep(0.2) out = server.get_output() if out != "S2\nS3\n": return wrong("") return correct()
def check(self, reply: str, attach: Any) -> CheckResult: if "Server stopped!\n" in reply: return correct() return wrong('')
def generate(self) -> List[TestCase]: return [TestCase(stdin=[lambda x: wrong("Wrong")])]
def test(self): main = TestedProgram('main') main.start("123", "234", "345") return wrong("")
def test2(self): return wrong('')
def check(self, reply: str, attach: Any) -> CheckResult: reply = self._fix_reply(reply) lines = reply.splitlines() useful_lines = [ i for i in reply.splitlines() if not ("play" in i and "exit" in i) ] if len(lines) == len(useful_lines): return wrong( 'Your output should contain at least such line, found 0: \n' '\'Type "play" to play the game, "exit" to quit: \'') reply = '\n'.join(useful_lines) tries = [i.strip() for i in reply.split('\n\n') if len(i.strip())][1:] if len(tries) == 0: return wrong( "Seems like you didn't print the game or not separated output properly" "(there need to be an empty line between guessing attempts)") full_blocks = [try_ for try_ in tries if len(try_.splitlines()) > 1] blocks = [block.splitlines()[0].strip() for block in full_blocks] for full_block, block in zip(full_blocks, blocks): if ' ' in block: return wrong('Cannot parse this block - it contains spaces ' 'in the first line, but shouldn\'t\n\n' f'{full_block}') survived = 'You survived!' hanged = 'You are hanged!' is_survived = survived in full_blocks[-1] is_hanged = hanged in full_blocks[-1] no_such_letter = 'No such letter in the word' already_typed = 'You already typed this letter' not_ascii = 'It is not an ASCII lowercase letter' print_single = 'You should print a single letter' if is_hanged: if (no_such_letter not in full_blocks[-1]): return wrong( f'Last block contains "{hanged}" ' f'but doesn\'t contain "{no_such_letter}". ' f'Check the first example. These texts ' f'should be within the same block. Your last block:\n\n' f'{full_blocks[-1]}') lengths = set(len(i) for i in blocks) str_lengths = [] for i, curr_len in enumerate(lengths, 1): for curr_block in blocks: if curr_len == len(curr_block): str_lengths += [f'{i}. {curr_block}'] break str_lengths = '\n'.join(str_lengths) if len(lengths) > 1: return wrong( f'Every line with guessed letters should be the same length as others.\n' f'Found lines with guessed letters:\n{str_lengths}') correct = '-' * len(blocks[0]) if blocks[0] != correct: return wrong(f'The first guess should only contain dashes: \n' f'{correct}\n' f'Your first guess:\n' f'{blocks[0]}') wrong_count = 0 typed_letters = set() inputs = '' if is_hanged: blocks += [blocks[-1]] full_blocks += [full_blocks[-1]] for letter, prev, next, prev_full, next_full in zip( attach, blocks[0:], blocks[1:], full_blocks[0:], full_blocks[1:]): # --- detect_not_one = len(letter) != 1 if detect_not_one and print_single not in prev_full: return wrong( f'Before: {prev}\n' f'Letter: {letter}\n' f'After : {next}\n\n' f'There is no \"{print_single}\" message, but should be') elif not detect_not_one and print_single in prev_full: return wrong( f'Before: {prev}\n' f'Letter: {letter}\n' f'After : {next}\n\n' f'There is \"{print_single}\" message, but shouldn\'t be') if detect_not_one: continue # --- detect_not_ascii = letter not in ascii_lowercase if detect_not_ascii and not_ascii not in prev_full: return wrong( f'Before: {prev}\n' f'Letter: {letter}\n' f'After : {next}\n\n' f'There is no \"{not_ascii}\" message, but should be') elif not detect_not_ascii and not_ascii in prev_full: return wrong( f'Before: {prev}\n' f'Letter: {letter}\n' f'After : {next}\n\n' f'There is \"{not_ascii}\" message, but shouldn\'t be') if detect_not_ascii: continue inputs += '\n' + letter # --- detect_typed_letter = letter in typed_letters if detect_typed_letter and already_typed not in prev_full: return wrong( f'Before: {prev}\n' f'Letter: {letter}\n' f'After : {next}\n\n' f'There is no \"{already_typed}\" message, but should be\n' f'Input letters: {inputs}') elif not detect_typed_letter and already_typed in prev_full: return wrong( f'Before: {prev}\n' f'Letter: {letter}\n' f'After : {next}\n\n' f'There is \"{already_typed}\" message, but shouldn\'t be' f'Input letters: {inputs}') if detect_typed_letter: continue # --- detect_no_such_letter = ((letter not in prev) and (letter not in next) and (next == prev) and not detect_typed_letter) if detect_no_such_letter and no_such_letter not in prev_full: return wrong( f'Before: {prev}\n' f'Letter: {letter}\n' f'After : {next}\n\n' f'There is no \"{no_such_letter}\" message, but should be') elif not detect_no_such_letter and no_such_letter in prev_full: return wrong( f'Before: {prev}\n' f'Letter: {letter}\n' f'After : {next}\n\n' f'There is \"{no_such_letter}\" message, but shouldn\'t be' ) if detect_no_such_letter: wrong_count += 1 typed_letters |= {letter} cond1 = ((letter not in prev) and (letter in next) and (set(next) - set(prev) != set(letter))) cond2 = ((letter not in prev) and (letter not in next) and (next != prev)) cond3 = ((letter in prev) and (letter in next) and (next != prev)) if cond1 or cond2 or cond3: return wrong(f'This transition is incorrect:\n' f'Before: {prev}\n' f'Letter: {letter}\n' f'After : {next}') if is_survived and is_hanged: return wrong( f'Looks like your output contains both \"{survived}\"' f' and \"{hanged}\". You should output only one of them.') if not is_survived and not is_hanged: return wrong( f'Looks like your output doesn\'t contain neither \"{survived}\"' f' nor \"{hanged}\". You should output one of them.') if is_hanged: if wrong_count != 8: return wrong( f'User was hanged after {wrong_count} wrong guesses, but should after 8' ) else: return accept() if is_survived: if wrong_count >= 8: return wrong( f'User survived but have {wrong_count} wrong guesses. He should be hanged' ) else: return accept()
def check(self, reply: str, attach: Any) -> CheckResult: return wrong("")
def test1(self): pr = TestedProgram('main') pr.start("-in", "123", "-out", "234") return wrong('')
def test(self): server = TestedProgram('main') server.start_in_background() sleep(0.15) return wrong('')
def test15(self): return wrong(f'x == {self.x}')