How to use contains_only method in assertpy

Best Python code snippet using assertpy_python

adv23-2.py

Source:adv23-2.py Github

copy

Full Screen

...36 fourth_depth += rooms[key][3] + "#"37 fourth_depth += "# "38 print(fourth_depth)39 print(" ########### \n")40def contains_only(occupant, rooms):41 for e in rooms[occupant]:42 if(e != occupant and e != "."):43 return False44 return True45def should_move_0(room, rooms):46 for i in range(0, 4):47 if(rooms[room][i] != room and rooms[room][i] != "."):48 return True49 return False50def can_move_into_room(hallway, room, occupant, hall_index):51 room_col = 2*(ord(occupant)-64)52 for e in room:53 if(e != occupant and e != "."):54 return None55 if(room_col < hall_index):56 for index in range(hall_index - 1, room_col - 1, -1):57 if(hallway[index] != "."):58 return None59 elif(room_col > hall_index):60 for index in range(hall_index + 1, room_col + 1, 1):61 if(hallway[index] != "."):62 return None63 if(room[0] == "." and room[1] == occupant):64 distance = abs(hall_index - room_col) + 165 return distance, 066 elif(room[0] == "." and room[1] == "." and room[2] == occupant):67 distance = abs(hall_index - room_col) + 268 return distance, 169 elif(room[0] == "." and room[1] == "." and room[2] == "." and room[3] == occupant):70 distance = abs(hall_index - room_col) + 371 return distance, 272 elif(room[0] == "." and room[1] == "." and room[2] == "." and room[3] == "."):73 distance = abs(hall_index - room_col) + 474 return distance, 375 else:76 return None77def is_done(state):78 rooms = state[0]79 hallway = state[1]80 for key in rooms:81 for element in rooms[key]:82 if(element != key or element == "."):83 return False84 for element in hallway:85 if(element != "."):86 return False87 return True88def get_cost(state):89 rooms = state[0]90 hallway = state[1]91 key = (tuple((k, tuple(v)) for k,v in rooms.items()), tuple(hallway))92 if(is_done(state)):93 DP[key] = 094 return 095 if(key in DP):96 return DP[key]97 else:98 for i in range(0, len(hallway)):99 if(hallway[i] != "."):100 occupant = hallway[i]101 occupant_col = 2*(ord(occupant)-64)102 result = can_move_into_room(hallway, rooms[occupant], occupant, i)103 if(result != None):104 distance, depth = result105 new_hallway = list(hallway)106 updated_room = list(rooms[occupant])107 new_rooms = deepcopy(rooms)108 updated_room[depth] = occupant109 new_hallway[i] = "."110 new_rooms[occupant] = updated_room111 answer = (MOVE_COSTS[occupant] * result[0]) + get_cost((new_rooms, new_hallway))112 DP[key] = answer113 return answer114 min_cost = int(1e9)115 for room in rooms:116 if(rooms[room][0] != "." and should_move_0(room, rooms) ):117 occupant = rooms[room][0]118 room_col = 2*(ord(room)-64)119 occupant_col = 2*(ord(occupant)-64)120 places_can_move_to = []121 for index in range(room_col, len(hallway)):122 if(hallway[index] != "."):123 break124 elif(index == occupant_col):125 if(rooms[occupant][0] == "." and rooms[occupant][1] == occupant and contains_only(occupant, rooms)):126 distance = 2 + abs(index - room_col)127 places_can_move_to.append([-1, distance])128 elif(rooms[occupant][0] == "." and rooms[occupant][1] == "." and rooms[occupant][2] == occupant and contains_only(occupant, rooms)):129 distance = 3 + abs(index - room_col)130 places_can_move_to.append([-2, distance])131 elif(rooms[occupant][0] == "." and rooms[occupant][1] == "." and rooms[occupant][2] == "." and rooms[occupant][3] == occupant and contains_only(occupant, rooms)):132 distance = 4 + abs(index - room_col)133 places_can_move_to.append([-3, distance])134 elif(rooms[occupant][0] == "." and rooms[occupant][1] == "." and rooms[occupant][2] == "." and rooms[occupant][3] == "." and contains_only(occupant, rooms)):135 distance = 5 + abs(index - room_col)136 places_can_move_to.append([-4, distance])137 if(len(places_can_move_to) >= 0):138 for index in range(room_col, -1, -1):139 if(hallway[index] != "."):140 break141 elif(index == occupant_col):142 if(rooms[occupant][0] == "." and rooms[occupant][1] == occupant and contains_only(occupant, rooms)):143 distance = 2 + abs(index - room_col)144 places_can_move_to.append([-1, distance])145 elif(rooms[occupant][0] == "." and rooms[occupant][1] == "." and rooms[occupant][2] == occupant and contains_only(occupant, rooms)):146 distance = 3 + abs(index - room_col)147 places_can_move_to.append([-2, distance])148 elif(rooms[occupant][0] == "." and rooms[occupant][1] == "." and rooms[occupant][2] == "." and rooms[occupant][3] == occupant and contains_only(occupant, rooms)):149 distance = 4 + abs(index - room_col)150 places_can_move_to.append([-3, distance])151 elif(rooms[occupant][0] == "." and rooms[occupant][1] == "." and rooms[occupant][2] == "." and rooms[occupant][3] == "." and contains_only(occupant, rooms)):152 distance = 5 + abs(index - room_col)153 places_can_move_to.append([-4, distance])154 places_can_move_to.sort()155 for p in places_can_move_to:156 depth = -1*p[0] - 1157 new_rooms = deepcopy(rooms)158 new_hallway = list(hallway)159 new_rooms[occupant][depth] = occupant160 new_rooms[room][0] = "."161 min_cost = min(min_cost, (MOVE_COSTS[occupant] * p[1]) + get_cost((new_rooms, new_hallway)))162 DP[key] = min_cost163 return min_cost164 elif(rooms[room][0] == "." and rooms[room][1] != "." and rooms[room][1] != room):165 occupant = rooms[room][0]166 room_col = 2*(ord(room)-64)167 occupant_col = 2*(ord(occupant)-64)168 places_can_move_to = []169 for index in range(room_col, len(hallway)):170 if(hallway[index] != "."):171 break172 elif(index == occupant_col):173 if(rooms[occupant][0] == "." and rooms[occupant][1] == occupant and contains_only(occupant, rooms)):174 distance = 2 + abs(index - room_col)175 places_can_move_to.append([-1, distance])176 elif(rooms[occupant][0] == "." and rooms[occupant][1] == "." and rooms[occupant][2] == occupant and contains_only(occupant, rooms)):177 distance = 3 + abs(index - room_col)178 places_can_move_to.append([-2, distance])179 elif(rooms[occupant][0] == "." and rooms[occupant][1] == "." and rooms[occupant][2] == "." and rooms[occupant][3] == occupant and contains_only(occupant, rooms)):180 distance = 4 + abs(index - room_col)181 places_can_move_to.append([-3, distance])182 elif(rooms[occupant][0] == "." and rooms[occupant][1] == "." and rooms[occupant][2] == "." and rooms[occupant][3] == "." and contains_only(occupant, rooms)):183 distance = 5 + abs(index - room_col)184 places_can_move_to.append([-4, distance])185 if(len(places_can_move_to) >= 0):186 for index in range(room_col, -1, -1):187 if(hallway[index] != "."):188 break189 elif(index == occupant_col):190 if(rooms[occupant][0] == "." and rooms[occupant][1] == occupant and contains_only(occupant, rooms)):191 distance = 2 + abs(index - room_col)192 places_can_move_to.append([-1, distance])193 elif(rooms[occupant][0] == "." and rooms[occupant][1] == "." and rooms[occupant][2] == occupant and contains_only(occupant, rooms)):194 distance = 3 + abs(index - room_col)195 places_can_move_to.append([-2, distance])196 elif(rooms[occupant][0] == "." and rooms[occupant][1] == "." and rooms[occupant][2] == "." and rooms[occupant][3] == occupant and contains_only(occupant, rooms)):197 distance = 4 + abs(index - room_col)198 places_can_move_to.append([-3, distance])199 elif(rooms[occupant][0] == "." and rooms[occupant][1] == "." and rooms[occupant][2] == "." and rooms[occupant][3] == "." and contains_only(occupant, rooms)):200 distance = 5 + abs(index - room_col)201 places_can_move_to.append([-4, distance])202 places_can_move_to.sort()203 for p in places_can_move_to:204 depth = -1*p[0] - 1205 new_rooms = deepcopy(rooms)206 new_hallway = list(hallway)207 new_rooms[occupant][depth] = occupant208 new_rooms[room][1] = "."209 min_cost = min(min_cost, (MOVE_COSTS[occupant] * p[1]) + get_cost((new_rooms, new_hallway)))210 DP[key] = min_cost211 return min_cost212 elif(rooms[room][0] == "." and rooms[room][1] == "." and rooms[room][2] != "." and rooms[room][2] != room):213 occupant = rooms[room][0]214 room_col = 2*(ord(room)-64)215 occupant_col = 2*(ord(occupant)-64)216 places_can_move_to = []217 for index in range(room_col, len(hallway)):218 if(hallway[index] != "."):219 break220 elif(index == occupant_col):221 if(rooms[occupant][0] == "." and rooms[occupant][1] == occupant and contains_only(occupant, rooms)):222 distance = 2 + abs(index - room_col)223 places_can_move_to.append([-1, distance])224 elif(rooms[occupant][0] == "." and rooms[occupant][1] == "." and rooms[occupant][2] == occupant and contains_only(occupant, rooms)):225 distance = 3 + abs(index - room_col)226 places_can_move_to.append([-2, distance])227 elif(rooms[occupant][0] == "." and rooms[occupant][1] == "." and rooms[occupant][2] == "." and rooms[occupant][3] == occupant and contains_only(occupant, rooms)):228 distance = 4 + abs(index - room_col)229 places_can_move_to.append([-3, distance])230 elif(rooms[occupant][0] == "." and rooms[occupant][1] == "." and rooms[occupant][2] == "." and rooms[occupant][3] == "." and contains_only(occupant, rooms)):231 distance = 5 + abs(index - room_col)232 places_can_move_to.append([-4, distance])233 if(len(places_can_move_to) >= 0):234 for index in range(room_col, -1, -1):235 if(hallway[index] != "."):236 break237 elif(index == occupant_col):238 if(rooms[occupant][0] == "." and rooms[occupant][1] == occupant and contains_only(occupant, rooms)):239 distance = 2 + abs(index - room_col)240 places_can_move_to.append([-1, distance])241 elif(rooms[occupant][0] == "." and rooms[occupant][1] == "." and rooms[occupant][2] == occupant and contains_only(occupant, rooms)):242 distance = 3 + abs(index - room_col)243 places_can_move_to.append([-2, distance])244 elif(rooms[occupant][0] == "." and rooms[occupant][1] == "." and rooms[occupant][2] == "." and rooms[occupant][3] == occupant and contains_only(occupant, rooms)):245 distance = 4 + abs(index - room_col)246 places_can_move_to.append([-3, distance])247 elif(rooms[occupant][0] == "." and rooms[occupant][1] == "." and rooms[occupant][2] == "." and rooms[occupant][3] == "." and contains_only(occupant, rooms)):248 distance = 5 + abs(index - room_col)249 places_can_move_to.append([-4, distance])250 places_can_move_to.sort()251 for p in places_can_move_to:252 depth = -1*p[0] - 1253 new_rooms = deepcopy(rooms)254 new_hallway = list(hallway)255 new_rooms[occupant][depth] = occupant256 new_rooms[room][1] = "."257 min_cost = min(min_cost, (MOVE_COSTS[occupant] * p[1]) + get_cost((new_rooms, new_hallway)))258 DP[key] = min_cost259 return min_cost260 min_cost = int(1e9)261 for room in rooms:...

Full Screen

Full Screen

test_stream.py

Source:test_stream.py Github

copy

Full Screen

...24 def setup(self):25 self.uut = Stream([0, 1, 2])26 def test_map(self):27 result = self.uut.map(mapper).as_tuple()28 assert_that(result).contains_only(1, 2, 3)29 def test_flat_map_generator(self):30 result = self.uut.flat_map(flat_generator).as_tuple()31 assert_that(result).contains_only(1, 2, 2)32 def test_flat_map_none(self):33 result = self.uut.flat_map(lambda x: None).as_tuple()34 assert_that(result).is_empty()35 def test_flat_map_list(self):36 result = self.uut.flat_map(flat_list).as_tuple()...

Full Screen

Full Screen

1. PPM.py

Source:1. PPM.py Github

copy

Full Screen

1# 1.2def contains_only(nb, tab):3 for c in str(nb):4 if int(c) not in tab:5 return False6 return True7print(contains_only(1212, [1, 2]))8print(contains_only(4456, [4, 5]))9# 2.10def ppm(nb, tab):11 c = 112 while c < 10_000_000:13 if contains_only(c * nb, tab):14 return c * nb15 c += 116 return False17print(ppm(1998, [0, 9]))18# 3. Non, la fonction ne renverra pas toujours un résultat. D'où l'importance d'arrêter la boucle après un certain19# temps.20# 4.3333333330...

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 assertpy 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