Best Python code snippet using avocado_python
main.py
Source:main.py
...49 for x in range(self.board_size):50 if self.is_computer(x, y):51 # horizontal check - a marks current field52 # [a][x][ ]53 if self.is_computer(x + 1, y) and self.is_available(x + 2, y):54 self.log_move(x + 2, y)55 return56 # [a][ ][ ]57 elif self.is_available(x + 1, y) and self.is_available(x + 2, y):58 self.log_move(x + 1, y)59 return60 # [ ][a][ ]61 elif self.is_available(x - 1, y) and self.is_available(x + 1, y):62 self.log_move(x + 1, y)63 return64 # [ ][ ][a]65 elif self.is_available(x - 1, y) and self.is_available(x - 2, y):66 self.log_move(x - 1, y)67 return68 # [ ][x][a]69 elif self.is_computer(x - 1, y) and self.is_available(x - 2, y):70 self.log_move(x - 2, y)71 return72 # vertical check - a marks current field73 # [a][x][ ]74 elif self.is_computer(x, y + 1) and self.is_available(x, y + 2):75 self.log_move(x, y + 2)76 return77 # [a][ ][ ]78 elif self.is_available(x, y + 1) and self.is_available(x, y + 2):79 self.log_move(x, y + 1)80 return81 # [ ][a][ ]82 elif self.is_available(x, y - 1) and self.is_available(x, y + 1):83 self.log_move(x, y + 1)84 return85 # [ ][ ][a]86 elif self.is_available(x, y - 1) and self.is_available(x, y - 2):87 self.log_move(x, y - 1)88 return89 # [ ][x][a]90 elif self.is_computer(x, y - 1) and self.is_available(x, y - 2):91 self.log_move(x, y - 2)92 return93 # angle check 1 - - a marks current field94 # [a][x][ ]95 elif self.is_computer(x + 1, y + 1) and self.is_available(x + 2, y + 2):96 self.log_move(x + 2, y + 2)97 return98 # [a][ ][ ]99 elif self.is_available(x + 1, y + 1) and self.is_available(x + 2, y + 2):100 self.log_move(x + 1, y + 1)101 return102 # [ ][a][ ]103 elif self.is_available(x - 1, y - 1) and self.is_available(x + 1, y + 1):104 self.log_move(x + 1, y + 1)105 return106 # [ ][ ][a]107 elif self.is_available(x - 1, y - 1) and self.is_available(x - 2, y - 2):108 self.log_move(x - 1, y - 1)109 return110 # [ ][x][a]111 elif self.is_computer(x - 1, y - 1) and self.is_available(x - 2, y - 2):112 self.log_move(x - 2, y - 2)113 return114 # angle check 2 - a marks current field115 # [a][x][ ]116 elif self.is_computer(x - 1, y + 1) and self.is_available(x - 2, y + 2):117 self.log_move(x - 2, y + 2)118 return119 # [a][ ][ ]120 elif self.is_available(x - 1, y + 1) and self.is_available(x - 2, y + 2):121 self.log_move(x - 1, y + 1)122 return123 # [ ][a][ ]124 elif self.is_available(x + 1, y - 1) and self.is_available(x - 1, y + 1):125 self.log_move(x - 1, y + 1)126 return127 # [ ][ ][a]128 elif self.is_available(x + 1, y - 1) and self.is_available(x + 2, y - 2):129 self.log_move(x + 1, y - 1)130 return131 # [ ][x][a]132 elif self.is_computer(x + 1, y - 1) and self.is_available(x + 2, y - 2):133 self.log_move(x + 2, y - 2)134 return135 elif self.is_available(x, y) and self.is_available(x + 1, y) and self.is_available(x + 2, y):136 self.log_move(x, y)137 return138 elif self.is_available(x, y) and self.is_available(x, y + 1) and self.is_available(x, y + 2):139 self.log_move(x, y)140 return141 elif self.is_available(x, y) and self.is_available(x + 1, y + 1) and self.is_available(x + 2, y + 2):142 self.log_move(x, y)143 return144 elif self.is_available(x, y) and self.is_available(x - 1, y + 1) and self.is_available(x - 2, y + 2):145 self.log_move(x, y)146 return147 # check if field exists and is empty148 def is_available(self, coord_x, coord_y):149 if coord_x <= self.board_size - 1 and coord_y <= self.board_size - 1:150 if self.board[coord_y][coord_x] == '[ ]':151 return True152 else:153 return False154 def is_computer(self, coord_x, coord_y):155 if coord_x <= self.board_size - 1 and coord_y <= self.board_size - 1:156 if self.board[coord_y][coord_x] == self.mark_computer:157 return True158 else:159 return False160 def check_victory(self):161 # horizontal check162 counter = 0...
test_backfill_allocator.py
Source:test_backfill_allocator.py
...5def test_merge_blocks_operations():6 candidates = CompletedKeys(10)7 assert candidates.num_remaining == 108 candidates.mark_completed(1, 5)9 assert candidates.is_available(5)10 assert candidates.is_available(0)11 assert not candidates.is_available(1)12 assert not candidates.is_available(4)13 assert not candidates.is_available(11)14 assert not candidates.is_available(10)15 assert len(candidates._slabs) == 116 assert candidates.num_remaining == 617 candidates.mark_completed(5, 6)18 assert not candidates.is_available(5)19 assert candidates.is_available(6)20 assert len(candidates._slabs) == 121 assert candidates.num_remaining == 522 candidates.mark_completed(3, 8)23 assert candidates.is_available(9)24 assert candidates.is_available(8)25 assert not candidates.is_available(7)26 assert len(candidates._slabs) == 127 assert candidates.num_remaining == 328def test_adjust_max():29 candidates = CompletedKeys(10)30 assert candidates.num_remaining == 1031 assert len(candidates._slabs) == 032 assert candidates.is_available(9)33 candidates.mark_completed(5, 12)34 assert len(candidates._slabs) == 035 assert candidates.num_remaining == 536 assert not candidates.is_available(9)37 assert candidates.is_available(4)38def test_adjust_min():39 candidates = CompletedKeys(10)40 assert candidates.num_remaining == 1041 assert len(candidates._slabs) == 042 assert candidates.is_available(2)43 candidates.mark_completed(0, 3)44 assert len(candidates._slabs) == 045 assert candidates.num_remaining == 746 assert not candidates.is_available(2)47 assert candidates.is_available(4)48def test_inside_block():49 candidates = CompletedKeys(10)50 assert candidates.num_remaining == 1051 candidates.mark_completed(1, 8)52 assert len(candidates._slabs) == 153 assert candidates.num_remaining == 354 candidates.mark_completed(2, 5)55 assert len(candidates._slabs) == 156 assert candidates.num_remaining == 357 assert not candidates.is_available(1)58 assert not candidates.is_available(5)59def test_wrap_block():60 candidates = CompletedKeys(10)61 assert candidates.num_remaining == 1062 candidates.mark_completed(2, 5)63 assert len(candidates._slabs) == 164 assert candidates.num_remaining == 765 candidates.mark_completed(1, 8)66 assert len(candidates._slabs) == 167 assert candidates.num_remaining == 368 assert not candidates.is_available(1)69 assert not candidates.is_available(5)70def test_non_contiguous():71 candidates = CompletedKeys(10)72 assert candidates.num_remaining == 1073 candidates.mark_completed(1, 5)74 assert len(candidates._slabs) == 175 assert candidates.num_remaining == 676 assert candidates.is_available(5)77 assert candidates.is_available(6)78 candidates.mark_completed(6, 8)79 assert len(candidates._slabs) == 280 assert candidates.num_remaining == 481 assert candidates.is_available(5)82 assert not candidates.is_available(6)83def test_big_merge():84 candidates = CompletedKeys(10)85 assert candidates.num_remaining == 1086 candidates.mark_completed(1, 5)87 assert len(candidates._slabs) == 188 assert candidates.num_remaining == 689 candidates.mark_completed(6, 8)90 assert len(candidates._slabs) == 291 assert candidates.num_remaining == 492 candidates.mark_completed(5, 6)93 assert len(candidates._slabs) == 194 assert candidates.num_remaining == 395def test_range_limits():96 candidates = CompletedKeys(10)97 assert not candidates.is_available(-1)98 assert not candidates.is_available(10)99 assert candidates.is_available(9)100 assert candidates.is_available(0)101def test_random_saturation():102 candidates = CompletedKeys(100)103 with pytest.raises(NoAvailableKeysError):104 for _ in range(101):105 start = candidates.get_block_start_index(10)106 assert candidates.is_available(start)107 candidates.mark_completed(start, start + 10)108 assert candidates.num_remaining == 0109def test_huge_dataset():110 candidates = CompletedKeys(1024 * 1024)111 start_time = datetime.now()112 iterations = 0113 with pytest.raises(NoAvailableKeysError):114 while (datetime.now() - start_time) < timedelta(seconds=10):115 start = candidates.get_block_start_index(1024)116 assert candidates.is_available(start)117 candidates.mark_completed(start, start + random.randint(512, 1024))118 iterations += 1119 assert iterations > 1024120 assert candidates.num_remaining == 0121class FakeQuery(object):122 def __init__(self, result_list):123 self._result_list = result_list124 def limit(self, *args, **kwargs):125 return self126 def where(self, *args, **kwargs):127 return self128 def order_by(self, *args, **kwargs):129 return self130 def __iter__(self):...
limited_capability_engine_test.py
Source:limited_capability_engine_test.py
...21def test_limited_capability_engine_default():22 eng = LimitedCapabilityEngine()23 m = MainEngine(backend=DummyEngine(), engine_list=[eng])24 q = m.allocate_qureg(2)25 assert eng.is_available(Measure.generate_command(q))26 assert not eng.is_available(H.generate_command(q))27 assert not eng.is_available(Z.generate_command(q))28 assert not eng.is_available(CNOT.generate_command(tuple(q)))29def test_limited_capability_engine_classes():30 eng = LimitedCapabilityEngine(allow_classes=[H.__class__, X.__class__],31 ban_classes=[X.__class__, Y.__class__])32 m = MainEngine(backend=DummyEngine(), engine_list=[eng])33 q = m.allocate_qureg(5)34 assert eng.is_available(Measure.generate_command(q)) # Default.35 assert eng.is_available(H.generate_command(q)) # Allowed.36 assert not eng.is_available(X.generate_command(q)) # Ban overrides allow.37 assert not eng.is_available(Y.generate_command(q)) # Banned.38 assert not eng.is_available(Z.generate_command(q)) # Not mentioned.39def test_limited_capability_engine_arithmetic():40 default_eng = LimitedCapabilityEngine()41 eng = LimitedCapabilityEngine(allow_arithmetic=True)42 m = MainEngine(backend=DummyEngine(), engine_list=[eng])43 q = m.allocate_qureg(5)44 inc = BasicMathGate(lambda x: x + 1)45 assert not default_eng.is_available(inc.generate_command(q))46 assert eng.is_available(inc.generate_command(q))47def test_limited_capability_engine_classical_instructions():48 default_eng = LimitedCapabilityEngine()49 eng = LimitedCapabilityEngine(allow_classical_instructions=False,50 allow_classes=[FlushGate])51 m = MainEngine(backend=DummyEngine(), engine_list=[eng])52 with pytest.raises(ValueError):53 _ = m.allocate_qubit()54 q = Qubit(m, 0)55 assert default_eng.is_available(Measure.generate_command(q))56 assert not eng.is_available(Measure.generate_command(q))57def test_limited_capability_engine_allow_toffoli():58 default_eng = LimitedCapabilityEngine()59 eng = LimitedCapabilityEngine(allow_toffoli=True)60 m = MainEngine(backend=DummyEngine(), engine_list=[eng])61 q = m.allocate_qureg(4)62 assert not default_eng.is_available(Z.generate_command(q))63 assert not default_eng.is_available(X.generate_command(q))64 assert not default_eng.is_available((X & q[1:2]).generate_command(q[0]))65 assert not default_eng.is_available((X & q[1:3]).generate_command(q[0]))66 assert not default_eng.is_available((X & q[1:4]).generate_command(q[0]))67 assert not eng.is_available(Z.generate_command(q))68 assert eng.is_available(X.generate_command(q))69 assert eng.is_available((X & q[1:2]).generate_command(q[0]))70 assert eng.is_available((X & q[1:3]).generate_command(q[0]))...
data_provenance_output_inner.py
Source:data_provenance_output_inner.py
...34 :rtype: DataProvenanceOutputInner35 """36 return util.deserialize_model(dikt, cls)37 @property38 def is_available(self) -> bool:39 """Gets the is_available of this DataProvenanceOutputInner.40 :return: The is_available of this DataProvenanceOutputInner.41 :rtype: bool42 """43 return self._is_available44 @is_available.setter45 def is_available(self, is_available: bool):46 """Sets the is_available of this DataProvenanceOutputInner.47 :param is_available: The is_available of this DataProvenanceOutputInner.48 :type is_available: bool49 """50 self._is_available = is_available51 @property52 def provenance_metadata(self) -> List[Dict[str, str]]:53 """Gets the provenance_metadata of this DataProvenanceOutputInner.54 :return: The provenance_metadata of this DataProvenanceOutputInner.55 :rtype: List[Dict[str, str]]56 """57 return self._provenance_metadata58 @provenance_metadata.setter59 def provenance_metadata(self, provenance_metadata: List[Dict[str, str]]):...
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!!