How to use assertListEqual method in autotest

Best Python code snippet using autotest_python

test_array.py

Source:test_array.py Github

copy

Full Screen

...35 self.assertEqual(next(josephus_generator), '1')36 self.assertRaises(StopIteration, next, josephus_generator)37class TestDeleteNth(unittest.TestCase):38 def test_delete_nth_naive(self):39 self.assertListEqual(delete_nth_naive(40 [20, 37, 20, 21, 37, 21, 21], n=1),41 [20, 37, 21])42 self.assertListEqual(delete_nth_naive(43 [1, 1, 3, 3, 7, 2, 2, 2, 2], n=3),44 [1, 1, 3, 3, 7, 2, 2, 2])45 self.assertListEqual(delete_nth_naive(46 [1, 2, 3, 1, 1, 2, 1, 2, 3, 3, 2, 4, 5, 3, 1],47 n=3),48 [1, 2, 3, 1, 1, 2, 2, 3, 3, 4, 5])49 self.assertListEqual(delete_nth_naive([], n=5),50 [])51 self.assertListEqual(delete_nth_naive(52 [1, 2, 3, 1, 1, 2, 1, 2, 3, 3, 2, 4, 5, 3, 1],53 n=0),54 [])55 def test_delete_nth(self):56 self.assertListEqual(delete_nth([20, 37, 20, 21, 37, 21, 21], n=1),57 [20, 37, 21])58 self.assertListEqual(delete_nth([1, 1, 3, 3, 7, 2, 2, 2, 2], n=3),59 [1, 1, 3, 3, 7, 2, 2, 2])60 self.assertListEqual(delete_nth([1, 2, 3, 1, 1, 2, 1, 2, 3, 3, 2, 4,61 5, 3, 1], n=3),62 [1, 2, 3, 1, 1, 2, 2, 3, 3, 4, 5])63 self.assertListEqual(delete_nth([], n=5),64 [])65 self.assertListEqual(delete_nth([1, 2, 3, 1, 1, 2, 1, 2, 3, 3, 2, 4,66 5, 3, 1], n=0),67 [])68class TestFlatten(unittest.TestCase):69 def test_flatten(self):70 nested_list = [2, 1, [3, [4, 5], 6], 7, [8]]71 flattened = flatten(nested_list)72 self.assertEqual(flattened, [2, 1, 3, 4, 5, 6, 7, 8])73 nested_list = [[3, [4, 5], 6], 7, [8]]74 flattened = flatten(nested_list)75 self.assertEqual(flattened, [3, 4, 5, 6, 7, 8])76 nested_list = [[], [8]]77 flattened = flatten(nested_list)78 self.assertEqual(flattened, [8])79 def test_flatten_iter(self):80 nested_list = [2, 1, [3, [4, 5], 6], 7, [8]]81 flattened = flatten_iter(nested_list)82 self.assertEqual(next(flattened), 2)83 self.assertEqual(next(flattened), 1)84 self.assertEqual(next(flattened), 3)85 self.assertEqual(next(flattened), 4)86 self.assertEqual(next(flattened), 5)87 self.assertEqual(next(flattened), 6)88 self.assertEqual(next(flattened), 7)89 self.assertEqual(next(flattened), 8)90 self.assertRaises(StopIteration, next, flattened)91 nested_list = [[3, [4, 5], 6], 7, [8]]92 flattened = flatten_iter(nested_list)93 self.assertEqual(next(flattened), 3)94 self.assertEqual(next(flattened), 4)95 self.assertEqual(next(flattened), 5)96 self.assertEqual(next(flattened), 6)97 self.assertEqual(next(flattened), 7)98 self.assertEqual(next(flattened), 8)99 self.assertRaises(StopIteration, next, flattened)100 nested_list = [[], [8]]101 flattened = flatten_iter(nested_list)102 self.assertEqual(next(flattened), 8)103 self.assertRaises(StopIteration, next, flattened)104class TestGarage(unittest.TestCase):105 def test_garage(self):106 initial = [1, 2, 3, 0, 4]107 final = [0, 3, 2, 1, 4]108 steps, seq = garage(initial, final)109 self.assertEqual(steps, 4)110 self.assertListEqual(seq, [[0, 2, 3, 1, 4],111 [2, 0, 3, 1, 4],112 [2, 3, 0, 1, 4],113 [0, 3, 2, 1, 4]])114class TestLongestNonRepeat(unittest.TestCase):115 def test_longest_non_repeat_v1(self):116 string = "abcabcbb"117 self.assertEqual(longest_non_repeat_v1(string), 3)118 string = "bbbbb"119 self.assertEqual(longest_non_repeat_v1(string), 1)120 string = "pwwkew"121 self.assertEqual(longest_non_repeat_v1(string), 3)122 string = "dvdf"123 self.assertEqual(longest_non_repeat_v1(string), 3)124 string = "asjrgapa"125 self.assertEqual(longest_non_repeat_v1(string), 6)126 def test_longest_non_repeat_v2(self):127 string = "abcabcbb"128 self.assertEqual(longest_non_repeat_v2(string), 3)129 string = "bbbbb"130 self.assertEqual(longest_non_repeat_v2(string), 1)131 string = "pwwkew"132 self.assertEqual(longest_non_repeat_v2(string), 3)133 string = "dvdf"134 self.assertEqual(longest_non_repeat_v2(string), 3)135 string = "asjrgapa"136 self.assertEqual(longest_non_repeat_v2(string), 6)137 def test_get_longest_non_repeat_v1(self):138 string = "abcabcbb"139 self.assertEqual(get_longest_non_repeat_v1(string), (3, 'abc'))140 string = "bbbbb"141 self.assertEqual(get_longest_non_repeat_v1(string), (1, 'b'))142 string = "pwwkew"143 self.assertEqual(get_longest_non_repeat_v1(string), (3, 'wke'))144 string = "dvdf"145 self.assertEqual(get_longest_non_repeat_v1(string), (3, 'vdf'))146 string = "asjrgapa"147 self.assertEqual(get_longest_non_repeat_v1(string), (6, 'sjrgap'))148 def test_get_longest_non_repeat_v2(self):149 string = "abcabcbb"150 self.assertEqual(get_longest_non_repeat_v2(string), (3, 'abc'))151 string = "bbbbb"152 self.assertEqual(get_longest_non_repeat_v2(string), (1, 'b'))153 string = "pwwkew"154 self.assertEqual(get_longest_non_repeat_v2(string), (3, 'wke'))155 string = "dvdf"156 self.assertEqual(get_longest_non_repeat_v2(string), (3, 'vdf'))157 string = "asjrgapa"158 self.assertEqual(get_longest_non_repeat_v2(string), (6, 'sjrgap'))159class TestMaxOnesIndex(unittest.TestCase):160 def test_max_ones_index(self):161 self.assertEqual(9, max_ones_index([1, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1,162 1, 1]))163 self.assertEqual(3, max_ones_index([1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1,164 1, 1]))165 self.assertEqual(-1, max_ones_index([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,166 1, 1]))167class TestMergeInterval(unittest.TestCase):168 def test_merge(self):169 interval_list = [[1, 3], [2, 6], [8, 10], [15, 18]]170 intervals = [Interval(i[0], i[1]) for i in interval_list]171 merged_intervals = Interval.merge(intervals)172 self.assertEqual(173 merged_intervals,174 [Interval(1, 6), Interval(8, 10), Interval(15, 18)]175 )176 def test_merge_intervals(self):177 interval_list = [[1, 3], [2, 6], [8, 10], [15, 18]]178 merged_intervals = merge_intervals(interval_list)179 self.assertEqual(180 merged_intervals,181 [[1, 6], [8, 10], [15, 18]]182 )183class TestMissingRanges(unittest.TestCase):184 def test_missing_ranges(self):185 arr = [3, 5, 10, 11, 12, 15, 19]186 self.assertListEqual(missing_ranges(arr, 0, 20),187 [(0, 2), (4, 4), (6, 9),188 (13, 14), (16, 18), (20, 20)])189 self.assertListEqual(missing_ranges(arr, 6, 100),190 [(6, 9), (13, 14), (16, 18), (20, 100)])191class TestMoveZeros(unittest.TestCase):192 def test_move_zeros(self):193 self.assertListEqual(move_zeros([False, 1, 0, 1, 2, 0, 1, 3, "a"]),194 [False, 1, 1, 2, 1, 3, "a", 0, 0])195 self.assertListEqual(move_zeros([0, 34, 'rahul', [], None, 0,196 True, 0]),197 [34, 'rahul', [], None, True, 0, 0, 0])198class TestPlusOne(unittest.TestCase):199 def test_plus_one_v1(self):200 self.assertListEqual(plus_one_v1([0]), [1])201 self.assertListEqual(plus_one_v1([9]), [1, 0])202 self.assertListEqual(plus_one_v1([1, 0, 9]), [1, 1, 0])203 self.assertListEqual(plus_one_v1([9, 9, 8, 0, 0, 9]),204 [9, 9, 8, 0, 1, 0])205 self.assertListEqual(plus_one_v1([9, 9, 9, 9]),206 [1, 0, 0, 0, 0])207 def test_plus_one_v2(self):208 self.assertListEqual(plus_one_v2([0]), [1])209 self.assertListEqual(plus_one_v2([9]), [1, 0])210 self.assertListEqual(plus_one_v2([1, 0, 9]), [1, 1, 0])211 self.assertListEqual(plus_one_v2([9, 9, 8, 0, 0, 9]),212 [9, 9, 8, 0, 1, 0])213 self.assertListEqual(plus_one_v2([9, 9, 9, 9]),214 [1, 0, 0, 0, 0])215 def test_plus_one_v3(self):216 self.assertListEqual(plus_one_v3([0]), [1])217 self.assertListEqual(plus_one_v3([9]), [1, 0])218 self.assertListEqual(plus_one_v3([1, 0, 9]), [1, 1, 0])219 self.assertListEqual(plus_one_v3([9, 9, 8, 0, 0, 9]),220 [9, 9, 8, 0, 1, 0])221 self.assertListEqual(plus_one_v3([9, 9, 9, 9]),222 [1, 0, 0, 0, 0])223class TestRotateArray(unittest.TestCase):224 def test_rotate_v1(self):225 self.assertListEqual(rotate_v1([1, 2, 3, 4, 5, 6, 7], k=3),226 [5, 6, 7, 1, 2, 3, 4])227 self.assertListEqual(rotate_v1([1, 2, 3, 4, 5, 6, 7], k=1),228 [7, 1, 2, 3, 4, 5, 6])229 self.assertListEqual(rotate_v1([1, 2, 3, 4, 5, 6, 7], k=7),230 [1, 2, 3, 4, 5, 6, 7])231 self.assertListEqual(rotate_v1([1, 2], k=111), [2, 1])232 def test_rotate_v2(self):233 self.assertListEqual(rotate_v2([1, 2, 3, 4, 5, 6, 7], k=3),234 [5, 6, 7, 1, 2, 3, 4])235 self.assertListEqual(rotate_v2([1, 2, 3, 4, 5, 6, 7], k=1),236 [7, 1, 2, 3, 4, 5, 6])237 self.assertListEqual(rotate_v2([1, 2, 3, 4, 5, 6, 7], k=7),238 [1, 2, 3, 4, 5, 6, 7])239 self.assertListEqual(rotate_v2([1, 2], k=111), [2, 1])240 def test_rotate_v3(self):241 self.assertListEqual(rotate_v3([1, 2, 3, 4, 5, 6, 7], k=3),242 [5, 6, 7, 1, 2, 3, 4])243 self.assertListEqual(rotate_v3([1, 2, 3, 4, 5, 6, 7], k=1),244 [7, 1, 2, 3, 4, 5, 6])245 self.assertListEqual(rotate_v3([1, 2, 3, 4, 5, 6, 7], k=7),246 [1, 2, 3, 4, 5, 6, 7])247 self.assertListEqual(rotate_v3([1, 2], k=111), [2, 1])248class TestSummaryRanges(unittest.TestCase):249 def test_summarize_ranges(self):250 self.assertListEqual(summarize_ranges([0, 1, 2, 4, 5, 7]),251 [(0, 2), (4, 5), (7, 7)])252 self.assertListEqual(summarize_ranges([-5, -4, -3, 1, 2, 4, 5, 6]),253 [(-5, -3), (1, 2), (4, 6)])254 self.assertListEqual(summarize_ranges([-2, -1, 0, 1, 2]),255 [(-2, 2)])256class TestThreeSum(unittest.TestCase):257 def test_three_sum(self):258 self.assertSetEqual(three_sum([-1, 0, 1, 2, -1, -4]),259 {(-1, 0, 1), (-1, -1, 2)})260 self.assertSetEqual(three_sum([-1, 3, 1, 2, -1, -4, -2]),261 {(-4, 1, 3), (-2, -1, 3), (-1, -1, 2)})262class TestTwoSum(unittest.TestCase):263 def test_two_sum(self):264 self.assertTupleEqual((0, 2), two_sum([2, 11, 7, 9], target=9))265 self.assertTupleEqual((0, 3), two_sum([-3, 5, 2, 3, 8, -9], target=0))266 self.assertIsNone(two_sum([-3, 5, 2, 3, 8, -9], target=6))267class TestTrimmean(unittest.TestCase):268 def test_trimmean(self):269 self.assertEqual(trimmean([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 20), 5.5)270 self.assertEqual(trimmean([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], 20),271 6.0)272class TestTop1(unittest.TestCase):273 def test_top_1(self):274 self.assertListEqual(top_1([1, 1, 2, 2, 3]), [1, 2])275 self.assertListEqual(top_1([1, 2, 3, 324, 234, 23, 23, 1, 23, 23]),276 [23])277class TestLimit(unittest.TestCase):278 def test_limit(self):279 self.assertListEqual(limit([1, 2, 3, 4, 5]), [1, 2, 3, 4, 5])280 self.assertListEqual(limit([1, 2, 3, 4, 5], 2, 4), [2, 3, 4])281 self.assertListEqual(limit([1, 2, 3, 4, 5], 2), [2, 3, 4, 5])282 self.assertListEqual(limit([1, 2, 3, 4, 5], None, 4), [1, 2, 3, 4])283class TestNSum(unittest.TestCase):284 def test_n_sum(self):285 self.assertEqual(n_sum(2, [-3, 5, 2, 3, 8, -9], 6), []) # noqa: E501286 self.assertEqual(n_sum(3, [-5, -4, -3, -2, -1, 0, 1, 2, 3], 0),287 sorted([[-5, 2, 3], [-2, 0, 2], [-4, 1, 3],288 [-3, 1, 2], [-1, 0, 1], [-2, -1, 3],289 [-3, 0, 3]])) # noqa: E501290 self.assertEqual(n_sum(3, [-1, 0, 1, 2, -1, -4], 0),291 sorted([[-1, -1, 2], [-1, 0, 1]])) # noqa: E501292 self.assertEqual(n_sum(4, [1, 0, -1, 0, -2, 2], 0),293 sorted([[-2, -1, 1, 2], [-2, 0, 0, 2],294 [-1, 0, 0, 1]])) # noqa: E501295 self.assertEqual(n_sum(4, [7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 6, 4, -3, -2], 10), sorted([[-6, 2, 7, 7], [-6, 3, 6, 7], [-6, 4, 5, 7], [-6, 4, 6, 6], [-5, 1, 7, 7], [-5, 2, 6, 7], [-5, 3, 5, 7], [-5, 3, 6, 6], [-5, 4, 4, 7], [-5, 4, 5, 6], [-4, 0, 7, 7], [-4, 1, 6, 7], [-4, 2, 5, 7], [-4, 2, 6, 6], [-4, 3, 4, 7], [-4, 3, 5, 6], [-4, 4, 4, 6], [-3, -1, 7, 7], [-3, 0, 6, 7], [-3, 1, 5, 7], [-3, 1, 6, 6], [-3, 2, 4, 7], [-3, 2, 5, 6], [-3, 3, 4, 6], [-3, 4, 4, 5], [-2, -2, 7, 7], [-2, -1, 6, 7], [-2, 0, 5, 7], [-2, 0, 6, 6], [-2, 1, 4, 7], [-2, 1, 5, 6], [-2, 2, 3, 7], [-2, 2, 4, 6], [-2, 3, 4, 5], [-1, 0, 4, 7], [-1, 0, 5, 6], [-1, 1, 3, 7], [-1, 1, 4, 6], [-1, 2, 3, 6], [-1, 2, 4, 5], [-1, 3, 4, 4], [0, 1, 2, 7], [0, 1, 3, 6], [0, 1, 4, 5], [0, 2, 3, 5], [0, 2, 4, 4], [1, 2, 3, 4]])) # noqa: E501296 self.assertEqual(n_sum(2, [[-3, 0], [-2, 1], [2, 2], [3, 3], [8, 4],...

Full Screen

Full Screen

test_assembler.py

Source:test_assembler.py Github

copy

Full Screen

...33 0x78,34 0x78,35 0x9A,36 ]37 self.assertListEqual(opcode, expected_opcode)38 def test_operands(self):39 opcode = self.assembler.assemble_code('''40 MOV AX 0x123441 NOP42 SHUTDOWN43 ''')44 expected_opcode = [0x34]45 expected_opcode += get_operand_opcode(Token(TokenType.WORD_REGISTER, 'AX', None))46 expected_opcode += get_operand_opcode(Token(TokenType.WORD_LITERAL, 0x1234, None))47 expected_opcode += [0x78]48 expected_opcode += [0x9A]49 self.assertListEqual(opcode, expected_opcode)50 def test_label_ok(self):51 opcode = self.assembler.assemble_code('''52 loop:53 NOP54 JMP loop55 SHUTDOWN56 ''')57 expected_opcode = [0x78]58 expected_opcode += [0x56]59 expected_opcode += get_operand_opcode(Token(TokenType.ADDRESS_WORD_LITERAL, -1, None))60 expected_opcode += [0x9A]61 self.assertListEqual(opcode, expected_opcode)62 def test_label_error(self):63 with self.assertRaises(AssemblerError):64 self.assembler.assemble_code('''65 loop:66 NOP67 JMP other_loop68 SHUTDOWN69 ''')70 def test_macro_dat_and_datn(self):71 opcode = self.assembler.assemble_code('''72 MOV AX [stuff]73 NOP74 SHUTDOWN75 stuff: .DAT 0x1234 0x56 'ABC'76 .DATN 0x05 0xFF77 .DATN 0x03 0x123478 .DATN 0x02 'ABC'79 ''')80 expected_opcode = [0x34]81 expected_opcode += get_operand_opcode(Token(TokenType.WORD_REGISTER, 'AX', None))82 expected_opcode += get_operand_opcode(Token(83 TokenType.REL_REF_WORD,84 Reference(7, None, 'W'),85 None,86 ))87 expected_opcode += [0x78]88 expected_opcode += [0x9A]89 expected_opcode += [0x12, 0x34, 0x56, 0x41, 0x42, 0x43]90 expected_opcode += [0xFF, 0xFF, 0xFF, 0xFF, 0xFF]91 expected_opcode += [0x12, 0x34, 0x12, 0x34, 0x12, 0x34]92 expected_opcode += [0x41, 0x42, 0x43, 0x41, 0x42, 0x43]93 self.assertListEqual(opcode, expected_opcode)94 def test_macro_dat_and_datn_error(self):95 with self.assertRaises(MacroError):96 self.assembler.assemble_code('''97 .DAT98 ''')99 with self.assertRaises(MacroError):100 self.assembler.assemble_code('''101 .DAT a102 ''')103 with self.assertRaises(MacroError):104 self.assembler.assemble_code('''105 .DATN106 ''')107 with self.assertRaises(MacroError):108 self.assembler.assemble_code('''109 .DATN 0x00110 ''')111 with self.assertRaises(MacroError):112 self.assembler.assemble_code('''113 .DATN 0x00 0x00 0x00114 ''')115 with self.assertRaises(MacroError):116 self.assembler.assemble_code('''117 .DATN a 0x00118 ''')119 with self.assertRaises(MacroError):120 self.assembler.assemble_code('''121 .DATN 'a' 0x00122 ''')123 with self.assertRaises(MacroError):124 self.assembler.assemble_code('''125 .DATN 0x00 a126 ''')127 def test_macro_const(self):128 opcode = self.assembler.assemble_code('''129 .CONST $stuff 0x1234130 .CONST $other_stuff $stuff131 MOV AX $other_stuff132 NOP133 SHUTDOWN134 ''')135 expected_opcode = [0x34]136 expected_opcode += get_operand_opcode(Token(TokenType.WORD_REGISTER, 'AX', None))137 expected_opcode += get_operand_opcode(Token(TokenType.WORD_LITERAL, 0x1234, None))138 expected_opcode += [0x78]139 expected_opcode += [0x9A]140 self.assertListEqual(opcode, expected_opcode)141 def test_macro_const_error(self):142 with self.assertRaises(MacroError):143 self.assembler.assemble_code('''144 .CONST145 ''')146 with self.assertRaises(MacroError):147 self.assembler.assemble_code('''148 .CONST $x149 ''')150 with self.assertRaises(MacroError):151 self.assembler.assemble_code('''152 .CONST a 0x00153 ''')154 with self.assertRaises(MacroError):155 self.assembler.assemble_code('''156 .CONST $x a157 ''')158 with self.assertRaises(VariableError):159 self.assembler.assemble_code('''160 .CONST $x $y161 ''')162 with self.assertRaises(VariableError):163 self.assembler.assemble_code('''164 .CONST $x 0x00165 .CONST $x 0x01166 ''')167 def test_macro_param_and_var(self):168 opcode = self.assembler.assemble_code('''169 ENTER 0x02 0x04170 .CONST $default_value 0x1234171 .PARAM $p172 .VAR $v1173 .VAR $v2 $default_value174 MOV AX $p175 MOV AX $v1176 MOV AX $v2177 NOP178 SHUTDOWN179 ''')180 expected_opcode = [0xBC]181 expected_opcode += get_operand_opcode(Token(TokenType.BYTE_LITERAL, 0x02, None))182 expected_opcode += get_operand_opcode(Token(TokenType.BYTE_LITERAL, 0x04, None))183 expected_opcode += [0x34]184 expected_opcode += get_operand_opcode(Token(185 TokenType.ABS_REF_REG,186 Reference('BP', -3, 'W'),187 None,188 ))189 expected_opcode += get_operand_opcode(Token(TokenType.WORD_LITERAL, 0x1234, None))190 expected_opcode += [0x34]191 expected_opcode += get_operand_opcode(Token(TokenType.WORD_REGISTER, 'AX', None))192 expected_opcode += get_operand_opcode(Token(193 TokenType.ABS_REF_REG,194 Reference('BP', 7, 'W'),195 None,196 ))197 expected_opcode += [0x34]198 expected_opcode += get_operand_opcode(Token(TokenType.WORD_REGISTER, 'AX', None))199 expected_opcode += get_operand_opcode(Token(200 TokenType.ABS_REF_REG,201 Reference('BP', -1, 'W'),202 None,203 ))204 expected_opcode += [0x34]205 expected_opcode += get_operand_opcode(Token(TokenType.WORD_REGISTER, 'AX', None))206 expected_opcode += get_operand_opcode(Token(207 TokenType.ABS_REF_REG,208 Reference('BP', -3, 'W'),209 None,210 ))211 expected_opcode += [0x78]212 expected_opcode += [0x9A]213 self.assertListEqual(opcode, expected_opcode)214 def test_macro_param_and_var_error(self):215 with self.assertRaises(MacroError):216 self.assembler.assemble_code('''217 .PARAM $p218 ''')219 with self.assertRaises(ScopeError):220 self.assembler.assemble_code('''221 ENTER 0x02 0x00222 .PARAM $p1223 .PARAM $p2224 ''')225 with self.assertRaises(VariableError):226 self.assembler.assemble_code('''227 ENTER 0x04 0x00228 .PARAM $p229 .PARAM $p230 ''')231class TestScope(unittest.TestCase):232 def test_params_error_too_many(self):233 scope = _create_scope(0, 0)234 with self.assertRaises(ScopeError):235 scope.add_parameter('$p', 2)236 def test_params_error_wrong_size(self):237 scope = _create_scope(4, 0)238 with self.assertRaises(ScopeError):239 scope.add_parameter('$p', 3)240 def test_params_error_duplicate(self):241 scope = _create_scope(4, 0)242 scope.add_parameter('$p', 2)243 with self.assertRaises(ScopeError):244 scope.add_parameter('$p', 2)245 def test_params_byte_ok(self):246 param_bytes = _get_param_bytes([1, 1, 1, 1, 1])247 self.assertListEqual(param_bytes[0], [11, 11])248 self.assertListEqual(param_bytes[1], [10, 10])249 self.assertListEqual(param_bytes[2], [9, 9])250 self.assertListEqual(param_bytes[3], [8, 8])251 self.assertListEqual(param_bytes[4], [7, 7])252 def test_params_word_ok(self):253 param_bytes = _get_param_bytes([2, 2, 2, 2, 2])254 self.assertListEqual(param_bytes[0], [15, 16])255 self.assertListEqual(param_bytes[1], [13, 14])256 self.assertListEqual(param_bytes[2], [11, 12])257 self.assertListEqual(param_bytes[3], [9, 10])258 self.assertListEqual(param_bytes[4], [7, 8])259 def test_params_mixed_ok(self):260 param_bytes = _get_param_bytes([1, 1, 2, 1, 2])261 self.assertListEqual(param_bytes[0], [13, 13])262 self.assertListEqual(param_bytes[1], [12, 12])263 self.assertListEqual(param_bytes[2], [10, 11])264 self.assertListEqual(param_bytes[3], [9, 9])265 self.assertListEqual(param_bytes[4], [7, 8])266 def test_vars_error_too_many(self):267 scope = _create_scope(0, 0)268 with self.assertRaises(ScopeError):269 scope.add_variable('$v', 2)270 def test_vars_error_wrong_size(self):271 scope = _create_scope(0, 4)272 with self.assertRaises(ScopeError):273 scope.add_variable('$v', 3)274 def test_vars_byte_ok(self):275 var_bytes = _get_var_bytes([1, 1, 1, 1, 1])276 self.assertListEqual(var_bytes[0], [0, 0])277 self.assertListEqual(var_bytes[1], [-1, -1])278 self.assertListEqual(var_bytes[2], [-2, -2])279 self.assertListEqual(var_bytes[3], [-3, -3])280 self.assertListEqual(var_bytes[4], [-4, -4])281 def test_vars_word_ok(self):282 var_bytes = _get_var_bytes([2, 2, 2, 2, 2])283 self.assertListEqual(var_bytes[0], [-1, 0])284 self.assertListEqual(var_bytes[1], [-3, -2])285 self.assertListEqual(var_bytes[2], [-5, -4])286 self.assertListEqual(var_bytes[3], [-7, -6])287 self.assertListEqual(var_bytes[4], [-9, -8])288 def test_vars_mixed_ok(self):289 var_bytes = _get_var_bytes([1, 1, 2, 1, 2])290 self.assertListEqual(var_bytes[0], [0, 0])291 self.assertListEqual(var_bytes[1], [-1, -1])292 self.assertListEqual(var_bytes[2], [-3, -2])293 self.assertListEqual(var_bytes[3], [-4, -4])294 self.assertListEqual(var_bytes[4], [-6, -5])295 def test_params_and_vars_error_duplicate(self):296 scope = _create_scope(2, 2)297 scope.add_parameter('$x', 2)298 with self.assertRaises(ScopeError):299 scope.add_variable('$x', 2)300 def test_params_and_vars_ok(self):301 scope = _create_scope(2, 2)302 scope.add_parameter('$p', 2)303 scope.add_variable('$v', 2)304 self.assertEqual(scope.get_value('$p').value.offset, 7)305 self.assertEqual(scope.get_value('$v').value.offset, -1)306 with self.assertRaises(ScopeError):307 scope.get_value('$x')308def _create_scope(bc_params, bc_vars):...

Full Screen

Full Screen

testSnake.py

Source:testSnake.py Github

copy

Full Screen

...8 snake = Snake(Body([9 Segment(Point(0, 0), Point(1, 0)),10 ]))11 snake = snake.grow()12 self.assertListEqual(13 snake.body.occupiedArea(),14 [[1, 1, 1]]15 )16 def testUp(self):17 snake = Snake(Body([18 Segment(Point(0, 0), Point(3, 0)),19 ]))20 self.assertListEqual(21 snake.body.occupiedArea(),22 [23 [1, 1, 1, 1],24 ]25 )26 snake = snake.up()27 self.assertListEqual(28 snake.body.occupiedArea(),29 [30 [0, 0, 1],31 [1, 1, 1],32 ]33 )34 snake = snake.up()35 self.assertListEqual(36 snake.body.occupiedArea(),37 [38 [0, 1],39 [0, 1],40 [1, 1],41 ]42 )43 snake = snake.up()44 self.assertListEqual(45 snake.body.occupiedArea(),46 [47 [1],48 [1],49 [1],50 [1],51 ]52 )53 snake = snake.up()54 self.assertListEqual(55 snake.body.occupiedArea(),56 [57 [1],58 [1],59 [1],60 [1],61 ]62 )63 def testRight(self):64 snake = Snake(Body([65 Segment(Point(0, 0), Point(0, 3)),66 ]))67 self.assertListEqual(68 snake.body.occupiedArea(),69 [70 [1],71 [1],72 [1],73 [1],74 ]75 )76 snake = snake.right()77 self.assertListEqual(78 snake.body.occupiedArea(),79 [80 [1, 0],81 [1, 0],82 [1, 1],83 ]84 )85 snake = snake.right()86 self.assertListEqual(87 snake.body.occupiedArea(),88 [89 [1, 0, 0],90 [1, 1, 1],91 ]92 )93 snake = snake.right()94 self.assertListEqual(95 snake.body.occupiedArea(),96 [97 [1, 1, 1, 1],98 ]99 )100 snake = snake.right()101 self.assertListEqual(102 snake.body.occupiedArea(),103 [104 [1, 1, 1, 1],105 ]106 )107 def testDown(self):108 snake = Snake(Body([109 Segment(Point(0, 0), Point(3, 0)),110 ]))111 self.assertListEqual(112 snake.body.occupiedArea(),113 [114 [1, 1, 1, 1],115 ]116 )117 snake = snake.down()118 self.assertListEqual(119 snake.body.occupiedArea(),120 [121 [1, 1, 1],122 [0, 0, 1],123 ]124 )125 snake = snake.down()126 self.assertListEqual(127 snake.body.occupiedArea(),128 [129 [1, 1],130 [0, 1],131 [0, 1],132 ]133 )134 snake = snake.down()135 self.assertListEqual(136 snake.body.occupiedArea(),137 [138 [1],139 [1],140 [1],141 [1],142 ]143 )144 snake = snake.down()145 self.assertListEqual(146 snake.body.occupiedArea(),147 [148 [1],149 [1],150 [1],151 [1],152 ]153 )154 def testLeft(self):155 snake = Snake(Body([156 Segment(Point(0, 0), Point(0, 3)),157 ]))158 self.assertListEqual(159 snake.body.occupiedArea(),160 [161 [1],162 [1],163 [1],164 [1],165 ]166 )167 snake = snake.left()168 self.assertListEqual(169 snake.body.occupiedArea(),170 [171 [0, 1],172 [0, 1],173 [1, 1],174 ],175 )176 snake = snake.left()177 self.assertListEqual(178 snake.body.occupiedArea(),179 [180 [0, 0, 1],181 [1, 1, 1],182 ]183 )184 snake = snake.left()185 self.assertListEqual(186 snake.body.occupiedArea(),187 [188 [1, 1, 1, 1],189 ]190 )191 snake = snake.left()192 self.assertListEqual(193 snake.body.occupiedArea(), 194 [195 [1, 1, 1, 1],196 ]197 )198 def testForward(self):199 snake = Snake().grow().grow().up()200 snake = snake.forward()201 self.assertListEqual(202 snake.body.occupiedArea(),203 [204 [0, 0, 1],205 [0, 0, 1],206 [1, 1, 1],207 ]208 )209 snake = snake.forward()210 self.assertListEqual(211 snake.body.occupiedArea(),212 [213 [0, 1],214 [0, 1],215 [0, 1],216 [1, 1],217 ]218 )219 snake = snake.forward()220 self.assertListEqual(221 snake.body.occupiedArea(),222 [223 [1],224 [1],225 [1],226 [1],227 [1],228 ]229 )230 snake = snake.forward()231 self.assertListEqual(232 snake.body.occupiedArea(), 233 [234 [1],235 [1],236 [1],237 [1],238 [1],239 ]...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful