Best Python code snippet using robotframework-pageobjects_python
test_all.py
Source:test_all.py
...33 2. interpreter zwróciÅ za maÅo linijek (czyli program siÄ nie wykonaÅ)34 3. oczekiwane wyjÅcie nie zgadza siÄ z wyjÅciem faktycznym35Zwraca czas wykonania w postaci stringa.36"""37def run_program(imp_name, given_input, expected_output):38 mr_name = imp_name + ".mr"39 imp_name = imp_name + ".imp"40 with open(imp_name, 'rb') as impf, open(mr_name, 'wb') as mrf:41 compl_proc = subprocess.run(COMPILER_PATH, stdin=impf, stdout=mrf)42 assert compl_proc.returncode == 043 compl_proc = subprocess.run([INTERPRETER_PATH, mr_name], input=given_input, stdout=subprocess.PIPE)44 lines = compl_proc.stdout.split(b'\n')45 if len(lines) < 5:46 assert False47 output = b''48 for line in lines[3:-2]:49 match = re.search(b'.*> (\d+)', line)50 assert match51 output += match.group(1) + b'\n'52 assert output == expected_output53 match = re.search(b'czas: (\d+)', lines[-2])54 return match.group(1)55"""56Tutaj sÄ
testy.57"""58def test_program0():59 run_program("program0", b'0\n', b'')60 run_program("program0", b'1\n', b'1\n')61 run_program("program0", b'2\n', b'0\n1\n')62 run_program("program0", b'1345601\n', b'1\n0\n0\n0\n0\n0\n1\n0\n0\n0\n0\n1\n0\n0\n0\n1\n0\n0\n1\n0\n1\n')63def test_program1():64 run_program("program1", b'', b'2\n3\n5\n7\n11\n13\n17\n19\n23\n29\n31\n37\n41\n43\n47\n53\n59\n61\n67\n71\n73\n79\n83\n89\n97\n')65def test_program2():66 assert len(run_program("program2", b'12345678901\n', b'857\n1\n14405693\n1\n')) <= 867 # assert len(run_program("program2", b'12345678903\n', b'3\n1\n4115226301\n1\n')) <= 968def test_numbers():69 run_program('1-numbers', b'20\n', b'0\n1\n2\n10\n100\n10000\n1234567890\n35\n15\n999\n555555555\n7777\n999\n11\n707\n7777\n')70def test_fib():71 run_program('2-fib', b'1\n', b'121393\n')72def test_fib_factorial():73 run_program('3-fib-factorial', b'20\n', b'2432902008176640000\n17711\n')74def test_factorial():75 run_program('4-factorial', b'20\n', b'2432902008176640000\n')76def test_tab():77 run_program('5-tab', b'', b'0\n23\n44\n63\n80\n95\n108\n119\n128\n135\n140\n143\n144\n143\n140\n135\n128\n119\n108\n95\n80\n63\n44\n23\n0\n')78def test_mod_mult():79 run_program('6-mod-mult', b'1234567890\n1234567890987654321\n987654321\n', b'674106858\n')80def test_loopiii():81 run_program('7-loopiii', b'0\n0\n0\n', b'31000\n40900\n2222010\n')82 run_program('7-loopiii', b'1\n0\n2\n', b'31001\n40900\n2222012\n')83def test_for():84 run_program('8-for', b'12\n23\n34\n', b'507\n4379\n0\n')85def test_sort():86 run_program('9-sort', b'', b'5\n2\n10\n4\n20\n8\n17\n16\n11\n9\n22\n18\n21\n13\n19\n3\n15\n6\n7\n12\n14\n1\n1234567890\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n')87def test_div_mod():88 run_program('0-div-mod', b'1\n0\n', b'1\n0\n0\n0\n')89def test_program6_and_7():90 t1 = run_program('program6', b'20\n', b'2432902008176640000\n')91 t2 = run_program('program7', b'20\n', b'2432902008176640000\n')92 assert t1 == t293def test_test0():94 run_program('test0', b'5\n10\n', b'10\n')95def test_test1():96 run_program('test1', b'', b'10\n')97def test_test2():98 run_program('test2', b'', b'10\n20\n30\n40\n9\n14\n34\n44\n15\n30\n40\n50\n45\n60\n70\n70\n45\n60\n70\n70\n9\n11\n80\n')99def test_test3():100 run_program('test3', b'', b'10\n20\n30\n40\n45\n40\n20\n10\n40\n25\n15\n5\n35\n20\n10\n10\n35\n20\n10\n10\n0\n0\n5\n9\n0\n0\n')101def test_test4():102 run_program('test4', b'', b'0\n0\n0\n1\n2\n2\n15\n27775\n0\n0\n0\n1\n2\n2\n15\n27775\n11376640\n11371085\n11371085\n')103def test_test5():104 run_program('test5', b'', b'0\n0\n0\n1\n0\n2\n2\n130\n0\n0\n0\n1\n0\n2\n2\n130\n')105def test_test6():106 run_program('test6', b'', b'0\n0\n0\n0\n1\n0\n0\n5\n0\n0\n0\n0\n1\n0\n0\n5\n')107def test_test7():108 run_program('test7', b'', b'10\n9\n8\n7\n6\n5\n4\n3\n2\n1\n0\n')109def test_test8():110 run_program('test8', b'', b'0\n0\n0\n1\n1\n0\n1\n0\n1\n1\n0\n0\n1\n1\n0\n1\n0\n1\n0\n1\n0\n1\n2\n')111def test_program3():112 run_program('program3', b'20\n10\n', b'67108864020\n20370359763344860862684456884093781610514683936659362506361404493543812997633367061833973760\n1001\n3999999992000000003\n')113def test_program4():114 with open('program4_out.txt', 'rb') as f:115 run_program('program4', b'100\n3\n', f.read())116 with open('program4_out2.txt', 'rb') as f:117 run_program('program4', b'99\n3\n', f.read())118def test_program5():119 run_program('program5', b'5\n33\n', b'909090909\n27548209\n')120def test_program8():121 run_program('program8', b'34\n15\n56\n', b'529\n4371\n0\n')122def test_program9():123 run_program('program9', b'', b'0\n23\n44\n63\n80\n95\n108\n119\n128\n135\n140\n143\n144\n143\n140\n135\n128\n119\n108\n95\n80\n63\n44\n23\n0\n')124def test_program11():125 run_program('program11', b'9\n7\n6', b'1111111111\n9\n7\n6\n19\n1\n1\n2\n1111111111\n9\n7\n6\n19\n1\n28\n196\n')126 run_program('program11', b'9\n6\n7', b'1111111111\n9\n6\n7\n19\n2\n1\n3\n1111111111\n9\n6\n7\n19\n2\n28\n168\n')127 run_program('program11', b'7\n9\n6', b'1111111111\n7\n9\n6\n17\n1\n1\n2\n1111111111\n7\n9\n6\n17\n1\n24\n168\n')128 run_program('program11', b'7\n6\n9', b'1111111111\n7\n6\n9\n17\n4\n1\n5\n1111111111\n7\n6\n9\n17\n4\n26\n4\n')129 run_program('program11', b'6\n9\n7', b'1111111111\n6\n9\n7\n16\n2\n1\n3\n1111111111\n6\n9\n7\n16\n2\n23\n3\n')130 run_program('program11', b'6\n7\n9', b'1111111111\n6\n7\n9\n16\n4\n1\n5\n1111111111\n6\n7\n9\n16\n4\n25\n4\n')131def test_program11():132 run_program('program11', b'9\n7\n6', b'1111111111\n9\n7\n6\n19\n1\n1\n2\n1111111111\n9\n7\n6\n19\n1\n28\n196\n')133 run_program('program11', b'9\n6\n7', b'1111111111\n9\n6\n7\n19\n2\n1\n3\n1111111111\n9\n6\n7\n19\n2\n28\n168\n')134 run_program('program11', b'7\n9\n6', b'1111111111\n7\n9\n6\n17\n1\n1\n2\n1111111111\n7\n9\n6\n17\n1\n24\n168\n')135 run_program('program11', b'7\n6\n9', b'1111111111\n7\n6\n9\n17\n4\n1\n5\n1111111111\n7\n6\n9\n17\n4\n26\n4\n')136 run_program('program11', b'6\n9\n7', b'1111111111\n6\n9\n7\n16\n2\n1\n3\n1111111111\n6\n9\n7\n16\n2\n23\n3\n')137 run_program('program11', b'6\n7\n9', b'1111111111\n6\n7\n9\n16\n4\n1\n5\n1111111111\n6\n7\n9\n16\n4\n25\n4\n')138def test_program12():139 run_program('program12', b'0\n1\n2\n3', b'0\n0\n0\n0\n0\n1111111111\n0\n0\n0\n0\n1111111111\n0\n0\n0\n0\n1111111111\n1\n0\n0\n1\n1111111111\n')140 run_program('program12', b'3\n2\n1\n0', b'0\n0\n0\n3\n0\n1111111111\n0\n0\n3\n3\n1111111111\n0\n0\n0\n1\n1111111111\n4\n0\n0\n1\n1111111111\n')141 run_program('program12', b'1\n1\n1\n1', b'0\n0\n0\n1\n1\n1111111111\n0\n0\n1\n1\n1111111111\n0\n0\n0\n0\n1111111111\n2\n0\n0\n1\n1111111111\n')142 run_program('program12', b'13\n0\n0\n0', b'0\n0\n0\n13\n0\n1111111111\n0\n0\n13\n13\n1111111111\n0\n0\n0\n1\n1111111111\n14\n0\n0\n1\n1111111111\n')143def test_program13():144 run_program('program13', b'0\n1\n2\n3', b'999999999\n0\n0\n4\n1\n0\n999999999\n1\n1\n6\n1\n0\n')145 run_program('program13', b'3\n2\n1\n0', b'999999999\n6\n0\n1\n0\n0\n999999999\n5\n0\n0\n0\n1\n')146 run_program('program13', b'1\n1\n1\n1', b'999999999\n2\n0\n1\n1\n0\n999999999\n2\n0\n1\n1\n0\n')147 run_program('program13', b'13\n0\n0\n0', b'999999999\n26\n0\n0\n0\n0\n999999999\n13\n0\n0\n0\n0\n')148def test_test9():...
day5.py
Source:day5.py
...31 param_1 = lookup_value(memory, parameter_modes[0], cursor + 1)32 param_2 = lookup_value(memory, parameter_modes[1], cursor + 2)33 param_3 = lookup_value(memory, parameter_modes[2], cursor + 3)34 return param_1, param_2, param_335def run_program(program, cursor=0, input_value=5):36 opcode, parameter_modes = split_instruction(program[cursor])37 params = lookup_values(program, parameter_modes, cursor)38 if opcode is Opcode.HALT:39 return program40 elif opcode is Opcode.ADD:41 program[params[2]] = program[params[0]] + program[params[1]]42 return run_program(program, cursor + 4, input_value)43 elif opcode is Opcode.MULTIPY:44 program[params[2]] = program[params[0]] * program[params[1]]45 return run_program(program, cursor + 4, input_value)46 elif opcode is Opcode.INPUT:47 program[params[0]] = input_value48 return run_program(program, cursor + 2, input_value)49 elif opcode is Opcode.OUTPUT:50 print(program[params[0]])51 return run_program(program, cursor + 2, input_value)52 elif opcode is Opcode.JUMP_IF:53 if program[params[0]]:54 return run_program(program, program[params[1]], input_value)55 return run_program(program, cursor + 3, input_value)56 elif opcode is Opcode.JUMP_NOT_IF:57 if not program[params[0]]:58 return run_program(program, program[params[1]], input_value)59 return run_program(program, cursor + 3, input_value)60 elif opcode is Opcode.LESS_THAN:61 program[params[2]] = 1 if program[params[0]] < program[params[1]] else 062 return run_program(program, cursor + 4, input_value)63 elif opcode is Opcode.EQUAL_TO:64 program[params[2]] = 1 if program[params[0]] == program[params[1]] else 065 return run_program(program, cursor + 4, input_value)66 else:67 print(f"missing opcode: {opcode}")68def main(param=1, filename='input'):69 with open(filename) as input_file:70 program_string = input_file.readlines()[0]71 program = list(parse_program(program_string))72 run_program(program, input_value=param)73if __name__ == "__main__":74 main(1)...
test_interpreter.py
Source:test_interpreter.py
...3from interpreter import run_program4from interpreter import LinkedList5class TestArithmetic(TestCase):6 def test_arithmetic(self):7 self.assertEqual(run_program(' 4 ').result, 4)8 self.assertEqual(run_program('* 9 6').result, 54)9 self.assertEqual(run_program('/ * 9 6 2').result, 27)10 self.assertEqual(run_program('* / 21 3 5').result, 35)11 self.assertEqual(run_program('** 2 3').result, 8)12class TestVariableBinding(TestCase):13 def test_env(self):14 self.assertDictEqual(run_program('<- a * / 21 3 5').env, {'a': 35})15 def test_array_decl(self):16 program = """17 [~] a 10;18 """19 result = run_program(program=program)20 self.assertTupleEqual(result.env['a']._l, tuple([None]*10))21 def test_array_set(self):22 program = """23 [~] arr 10;24 [<-] arr [ 0 ] 9;25 [<-] arr [ 9 ] 7;"""26 result = run_program(program=program)27 self.assertTupleEqual(result.env['arr']._l, (9, *[None] * 8, 7))28 def test_array_get(self):29 program = '''30 [~] arr 4;31 [<-] arr [ 2 ] 7 ;32 <- a [->] arr [ 2 ] ;33'''34 result = run_program(program=program)35 self.assertEqual(result.env['a'], 7)36class TestLeafInput(TestCase):37 def setUp(self) -> None:38 super().setUp()39 @mock.patch('builtins.input', lambda *arg: '89')40 def test_input(self):41 program = '''42 <- e input;'''43 result = run_program(program)44 self.assertEqual(result.env['e'], '89')45class TestWhile(TestCase):46 pass47class TestRunProgram(TestCase):48 def test_if_else(self):49 self.assertEqual(run_program('if True True else False').result, True)50 self.assertEqual(run_program('if 0 True else False').result, False)51 self.assertEqual(run_program('if True 5 else 4').result, 5)52 self.assertEqual(run_program('if True + 4 5 else * 4 9').result, 9)53 self.assertEqual(run_program('if 1 + 4 5 else * 4 9').result, 9)54 self.assertEqual(run_program('if False + 4 5 else * 4 9').result, 36)55 self.assertEqual(run_program('if 0 + 4 5 else * 4 9').result, 36)56 self.assertEqual(run_program('if - 5 5 + 4 5 else * 4 9').result, 36)57 self.assertDictEqual(run_program(58 '<- a if - 5 5 + 4 5 else * 4 9').env, {'a': 36})59 def test_with_nl_in_program(self):60 self.assertEqual(run_program('<- a - 9 8 ;\n<- a + a 1').env, {'a': 2})61class TestLinkedList(TestCase):62 def test_iter(self):63 l = [i for i in range(0, 10)]64 ll = LinkedList()65 [ll.append_val(item) for item in l]66 ll_iterator = iter(ll)67 ll_items = [ll_item.value for ll_item in ll_iterator]...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!