How to use mask method in wpt

Best JavaScript code snippet using wpt

mask_test.py

Source:mask_test.py Github

copy

Full Screen

...3import unittest4import pygame5import pygame.mask6from pygame.locals import *7def random_mask(size = (100,100)):8 """random_mask(size=(100,100)): return Mask9 Create a mask of the given size, with roughly half the bits set at random."""10 m = pygame.Mask(size)11 for i in range(size[0] * size[1] // 2):12 x, y = random.randint(0,size[0] - 1), random.randint(0, size[1] - 1)13 m.set_at((x,y))14 return m15def maskFromSurface(surface, threshold = 127):16 mask = pygame.Mask(surface.get_size())17 key = surface.get_colorkey()18 if key:19 for y in range(surface.get_height()):20 for x in range(surface.get_width()):21 if surface.get_at((x+0.1,y+0.1)) != key:22 mask.set_at((x,y),1)23 else:24 for y in range(surface.get_height()):25 for x in range (surface.get_width()):26 if surface.get_at((x,y))[3] > threshold:27 mask.set_at((x,y),1)28 return mask29class MaskTypeTest(unittest.TestCase):30 ORIGIN_OFFSETS = ((0, 0), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1),31 (-1, -1), (-1, 0), (-1, 1))32 def _assertMaskEqual(self, m1, m2, msg=None):33 # Checks to see if the 2 given masks are equal.34 m1_count = m1.count()35 self.assertEqual(m1.get_size(), m2.get_size(), msg=msg)36 self.assertEqual(m1_count, m2.count(), msg=msg)37 self.assertEqual(m1_count, m1.overlap_area(m2, (0, 0)), msg=msg)38 # This can be used to help debug exact locations.39 ##for i in range(m1.get_size()[0]):40 ## for j in range(m1.get_size()[1]):41 ## self.assertEqual(m1.get_at((i, j)), m2.get_at((i, j)))42 def test_mask(self):43 """Ensure masks are created correctly without fill parameter."""44 expected_count = 045 expected_size = (11, 23)46 mask1 = pygame.mask.Mask(expected_size)47 mask2 = pygame.mask.Mask(size=expected_size)48 self.assertEqual(mask1.count(), expected_count)49 self.assertEqual(mask1.get_size(), expected_size)50 self.assertEqual(mask2.count(), expected_count)51 self.assertEqual(mask2.get_size(), expected_size)52 def test_mask__negative_size(self):53 """Ensure the mask constructor handles negative sizes correctly."""54 for size in ((1, -1), (-1, 1), (-1, -1)):55 with self.assertRaises(ValueError):56 mask = pygame.Mask(size)57 def test_mask__fill_kwarg(self):58 """Ensure masks are created correctly using the fill keyword."""59 width, height = 37, 4760 expected_size = (width, height)61 fill_counts = {True : width * height, False : 0 }62 for fill, expected_count in fill_counts.items():63 msg = 'fill={}'.format(fill)64 mask = pygame.mask.Mask(expected_size, fill=fill)65 self.assertEqual(mask.count(), expected_count, msg)66 self.assertEqual(mask.get_size(), expected_size, msg)67 def test_mask__fill_arg(self):68 """Ensure masks are created correctly using a fill arg."""69 width, height = 59, 7170 expected_size = (width, height)71 fill_counts = {True : width * height, False : 0 }72 for fill, expected_count in fill_counts.items():73 msg = 'fill={}'.format(fill)74 mask = pygame.mask.Mask(expected_size, fill)75 self.assertEqual(mask.count(), expected_count, msg)76 self.assertEqual(mask.get_size(), expected_size, msg)77 def test_mask__size_kwarg(self):78 """Ensure masks are created correctly using the size keyword."""79 width, height = 73, 8380 expected_size = (width, height)81 fill_counts = {True : width * height, False : 0 }82 for fill, expected_count in fill_counts.items():83 msg = 'fill={}'.format(fill)84 mask1 = pygame.mask.Mask(fill=fill, size=expected_size)85 mask2 = pygame.mask.Mask(size=expected_size, fill=fill)86 self.assertEqual(mask1.count(), expected_count, msg)87 self.assertEqual(mask2.count(), expected_count, msg)88 self.assertEqual(mask1.get_size(), expected_size, msg)89 self.assertEqual(mask2.get_size(), expected_size, msg)90 def test_get_size(self):91 """Ensure a mask's size is correctly retrieved."""92 expected_size = (93, 101)93 mask = pygame.mask.Mask(expected_size)94 self.assertEqual(mask.get_size(), expected_size)95 def test_get_at(self):96 """Ensure individual mask bits are correctly retrieved."""97 width, height = 5, 798 mask0 = pygame.mask.Mask((width, height))99 mask1 = pygame.mask.Mask((width, height), fill=True)100 mask0_expected_bit = 0101 mask1_expected_bit = 1102 pos = (width - 1, height - 1)103 # Check twice to make sure bits aren't toggled.104 self.assertEqual(mask0.get_at(pos), mask0_expected_bit)105 self.assertEqual(mask0.get_at(pos), mask0_expected_bit)106 self.assertEqual(mask1.get_at(pos), mask1_expected_bit)107 self.assertEqual(mask1.get_at(pos), mask1_expected_bit)108 def test_get_at__out_of_bounds(self):109 """Ensure get_at() checks bounds."""110 width, height = 11, 3111 mask = pygame.mask.Mask((width, height))112 with self.assertRaises(IndexError):113 mask.get_at((width, 0))114 with self.assertRaises(IndexError):115 mask.get_at((0, height))116 with self.assertRaises(IndexError):117 mask.get_at((-1, 0))118 with self.assertRaises(IndexError):119 mask.get_at((0, -1))120 def test_set_at(self):121 """Ensure individual mask bits are set to 1."""122 width, height = 13, 17123 mask0 = pygame.mask.Mask((width, height))124 mask1 = pygame.mask.Mask((width, height), fill=True)125 mask0_expected_count = 1126 mask1_expected_count = mask1.count()127 expected_bit = 1128 pos = (width - 1, height - 1)129 mask0.set_at(pos, expected_bit) # set 0 to 1130 mask1.set_at(pos, expected_bit) # set 1 to 1131 self.assertEqual(mask0.get_at(pos), expected_bit)132 self.assertEqual(mask0.count(), mask0_expected_count)133 self.assertEqual(mask1.get_at(pos), expected_bit)134 self.assertEqual(mask1.count(), mask1_expected_count)135 def test_set_at__to_0(self):136 """Ensure individual mask bits are set to 0."""137 width, height = 11, 7138 mask0 = pygame.mask.Mask((width, height))139 mask1 = pygame.mask.Mask((width, height), fill=True)140 mask0_expected_count = 0141 mask1_expected_count = mask1.count() - 1142 expected_bit = 0143 pos = (width - 1, height - 1)144 mask0.set_at(pos, expected_bit) # set 0 to 0145 mask1.set_at(pos, expected_bit) # set 1 to 0146 self.assertEqual(mask0.get_at(pos), expected_bit)147 self.assertEqual(mask0.count(), mask0_expected_count)148 self.assertEqual(mask1.get_at(pos), expected_bit)149 self.assertEqual(mask1.count(), mask1_expected_count)150 def test_set_at__default_value(self):151 """Ensure individual mask bits are set using the default value."""152 width, height = 3, 21153 mask0 = pygame.mask.Mask((width, height))154 mask1 = pygame.mask.Mask((width, height), fill=True)155 mask0_expected_count = 1156 mask1_expected_count = mask1.count()157 expected_bit = 1158 pos = (width - 1, height - 1)159 mask0.set_at(pos) # set 0 to 1160 mask1.set_at(pos) # set 1 to 1161 self.assertEqual(mask0.get_at(pos), expected_bit)162 self.assertEqual(mask0.count(), mask0_expected_count)163 self.assertEqual(mask1.get_at(pos), expected_bit)164 self.assertEqual(mask1.count(), mask1_expected_count)165 def test_set_at__out_of_bounds(self):166 """Ensure set_at() checks bounds."""167 width, height = 11, 3168 mask = pygame.mask.Mask((width, height))169 with self.assertRaises(IndexError):170 mask.set_at((width, 0))171 with self.assertRaises(IndexError):172 mask.set_at((0, height))173 with self.assertRaises(IndexError):174 mask.set_at((-1, 0))175 with self.assertRaises(IndexError):176 mask.set_at((0, -1))177 def test_overlap(self):178 """Ensure the overlap intersection is correctly calculated.179 Testing the different combinations of full/empty masks:180 (mask1-filled) 1 overlap 1 (mask2-filled)181 (mask1-empty) 0 overlap 1 (mask2-filled)182 (mask1-filled) 1 overlap 0 (mask2-empty)183 (mask1-empty) 0 overlap 0 (mask2-empty)184 """185 expected_size = (4, 4)186 offset = (0, 0)187 expected_default = None188 expected_overlaps = {(True, True) : offset}189 for fill2 in (True, False):190 mask2 = pygame.mask.Mask(expected_size, fill=fill2)191 mask2_count = mask2.count()192 for fill1 in (True, False):193 key = (fill1, fill2)194 msg = 'key={}'.format(key)195 mask1 = pygame.mask.Mask(expected_size, fill=fill1)196 mask1_count = mask1.count()197 expected_pos = expected_overlaps.get(key, expected_default)198 overlap_pos = mask1.overlap(mask2, offset)199 self.assertEqual(overlap_pos, expected_pos, msg)200 # Ensure mask1/mask2 unchanged.201 self.assertEqual(mask1.count(), mask1_count, msg)202 self.assertEqual(mask2.count(), mask2_count, msg)203 self.assertEqual(mask1.get_size(), expected_size, msg)204 self.assertEqual(mask2.get_size(), expected_size, msg)205 def test_overlap__offset(self):206 """Ensure an offset overlap intersection is correctly calculated."""207 mask1 = pygame.mask.Mask((65, 3), fill=True)208 mask2 = pygame.mask.Mask((66, 4), fill=True)209 mask1_count = mask1.count()210 mask2_count = mask2.count()211 mask1_size = mask1.get_size()212 mask2_size = mask2.get_size()213 for offset in self.ORIGIN_OFFSETS:214 msg = 'offset={}'.format(offset)215 expected_pos = (max(offset[0], 0), max(offset[1], 0))216 overlap_pos = mask1.overlap(mask2, offset)217 self.assertEqual(overlap_pos, expected_pos, msg)218 # Ensure mask1/mask2 unchanged.219 self.assertEqual(mask1.count(), mask1_count, msg)220 self.assertEqual(mask2.count(), mask2_count, msg)221 self.assertEqual(mask1.get_size(), mask1_size, msg)222 self.assertEqual(mask2.get_size(), mask2_size, msg)223 def test_overlap__offset_with_unset_bits(self):224 """Ensure an offset overlap intersection is correctly calculated225 when (0, 0) bits not set."""226 mask1 = pygame.mask.Mask((65, 3), fill=True)227 mask2 = pygame.mask.Mask((66, 4), fill=True)228 unset_pos = (0, 0)229 mask1.set_at(unset_pos, 0)230 mask2.set_at(unset_pos, 0)231 mask1_count = mask1.count()232 mask2_count = mask2.count()233 mask1_size = mask1.get_size()234 mask2_size = mask2.get_size()235 for offset in self.ORIGIN_OFFSETS:236 msg = 'offset={}'.format(offset)237 x, y = offset238 expected_y = max(y, 0)239 if 0 == y:240 expected_x = max(x + 1, 1)241 elif 0 < y:242 expected_x = max(x + 1, 0)243 else:244 expected_x = max(x, 1)245 overlap_pos = mask1.overlap(mask2, offset)246 self.assertEqual(overlap_pos, (expected_x, expected_y), msg)247 # Ensure mask1/mask2 unchanged.248 self.assertEqual(mask1.count(), mask1_count, msg)249 self.assertEqual(mask2.count(), mask2_count, msg)250 self.assertEqual(mask1.get_size(), mask1_size, msg)251 self.assertEqual(mask2.get_size(), mask2_size, msg)252 self.assertEqual(mask1.get_at(unset_pos), 0, msg)253 self.assertEqual(mask2.get_at(unset_pos), 0, msg)254 def test_overlap__no_overlap(self):255 """Ensure an offset overlap intersection is correctly calculated256 when there is no overlap."""257 mask1 = pygame.mask.Mask((65, 3), fill=True)258 mask1_count = mask1.count()259 mask1_size = mask1.get_size()260 mask2_w, mask2_h = 67, 5261 mask2_size = (mask2_w, mask2_h)262 mask2 = pygame.mask.Mask(mask2_size)263 set_pos = (mask2_w - 1, mask2_h - 1)264 mask2.set_at(set_pos)265 mask2_count = 1266 for offset in self.ORIGIN_OFFSETS:267 msg = 'offset={}'.format(offset)268 overlap_pos = mask1.overlap(mask2, offset)269 self.assertIsNone(overlap_pos, msg)270 # Ensure mask1/mask2 unchanged.271 self.assertEqual(mask1.count(), mask1_count, msg)272 self.assertEqual(mask2.count(), mask2_count, msg)273 self.assertEqual(mask1.get_size(), mask1_size, msg)274 self.assertEqual(mask2.get_size(), mask2_size, msg)275 self.assertEqual(mask2.get_at(set_pos), 1, msg)276 def test_overlap__offset_boundary(self):277 """Ensures overlap handles offsets and boundaries correctly."""278 mask1 = pygame.mask.Mask((13, 3), fill=True)279 mask2 = pygame.mask.Mask((7, 5), fill=True)280 mask1_count = mask1.count()281 mask2_count = mask2.count()282 mask1_size = mask1.get_size()283 mask2_size = mask2.get_size()284 # Check the 4 boundaries.285 offsets = ((mask1_size[0], 0), # off right286 (0, mask1_size[1]), # off bottom287 (-mask2_size[0], 0), # off left288 (0, -mask2_size[1])) # off top289 for offset in offsets:290 msg = 'offset={}'.format(offset)291 overlap_pos = mask1.overlap(mask2, offset)292 self.assertIsNone(overlap_pos, msg)293 # Ensure mask1/mask2 unchanged.294 self.assertEqual(mask1.count(), mask1_count, msg)295 self.assertEqual(mask2.count(), mask2_count, msg)296 self.assertEqual(mask1.get_size(), mask1_size, msg)297 self.assertEqual(mask2.get_size(), mask2_size, msg)298 def test_overlap__invalid_mask_arg(self):299 """Ensure overlap handles invalid mask arguments correctly."""300 size = (5, 3)301 offset = (0, 0)302 mask = pygame.mask.Mask(size)303 invalid_mask = pygame.Surface(size)304 with self.assertRaises(TypeError):305 overlap_pos = mask.overlap(invalid_mask, offset)306 def test_overlap__invalid_offset_arg(self):307 """Ensure overlap handles invalid offset arguments correctly."""308 size = (2, 7)309 offset = '(0, 0)'310 mask1 = pygame.mask.Mask(size)311 mask2 = pygame.mask.Mask(size)312 with self.assertRaises(TypeError):313 overlap_pos = mask1.overlap(mask2, offset)314 def test_overlap_area(self):315 """Ensure the overlap_area is correctly calculated.316 Testing the different combinations of full/empty masks:317 (mask1-filled) 1 overlap_area 1 (mask2-filled)318 (mask1-empty) 0 overlap_area 1 (mask2-filled)319 (mask1-filled) 1 overlap_area 0 (mask2-empty)320 (mask1-empty) 0 overlap_area 0 (mask2-empty)321 """322 expected_size = width, height = (4, 4)323 offset = (0, 0)324 expected_default = 0325 expected_counts = {(True, True) : width * height}326 for fill2 in (True, False):327 mask2 = pygame.mask.Mask(expected_size, fill=fill2)328 mask2_count = mask2.count()329 for fill1 in (True, False):330 key = (fill1, fill2)331 msg = 'key={}'.format(key)332 mask1 = pygame.mask.Mask(expected_size, fill=fill1)333 mask1_count = mask1.count()334 expected_count = expected_counts.get(key, expected_default)335 overlap_count = mask1.overlap_area(mask2, offset)336 self.assertEqual(overlap_count, expected_count, msg)337 # Ensure mask1/mask2 unchanged.338 self.assertEqual(mask1.count(), mask1_count, msg)339 self.assertEqual(mask2.count(), mask2_count, msg)340 self.assertEqual(mask1.get_size(), expected_size, msg)341 self.assertEqual(mask2.get_size(), expected_size, msg)342 def test_overlap_area__offset(self):343 """Ensure an offset overlap_area is correctly calculated."""344 mask1 = pygame.mask.Mask((65, 3), fill=True)345 mask2 = pygame.mask.Mask((66, 4), fill=True)346 mask1_count = mask1.count()347 mask2_count = mask2.count()348 mask1_size = mask1.get_size()349 mask2_size = mask2.get_size()350 # Using rects to help determine the overlapping area.351 rect1 = pygame.Rect((0, 0), mask1_size)352 rect2 = pygame.Rect((0, 0), mask2_size)353 for offset in self.ORIGIN_OFFSETS:354 msg = 'offset={}'.format(offset)355 rect2.topleft = offset356 overlap_rect = rect1.clip(rect2)357 expected_count = overlap_rect.w * overlap_rect.h358 overlap_count = mask1.overlap_area(mask2, offset)359 self.assertEqual(overlap_count, expected_count, msg)360 # Ensure mask1/mask2 unchanged.361 self.assertEqual(mask1.count(), mask1_count, msg)362 self.assertEqual(mask2.count(), mask2_count, msg)363 self.assertEqual(mask1.get_size(), mask1_size, msg)364 self.assertEqual(mask2.get_size(), mask2_size, msg)365 def test_overlap_area__offset_boundary(self):366 """Ensures overlap_area handles offsets and boundaries correctly."""367 mask1 = pygame.mask.Mask((11, 3), fill=True)368 mask2 = pygame.mask.Mask((5, 7), fill=True)369 mask1_count = mask1.count()370 mask2_count = mask2.count()371 mask1_size = mask1.get_size()372 mask2_size = mask2.get_size()373 expected_count = 0374 # Check the 4 boundaries.375 offsets = ((mask1_size[0], 0), # off right376 (0, mask1_size[1]), # off bottom377 (-mask2_size[0], 0), # off left378 (0, -mask2_size[1])) # off top379 for offset in offsets:380 msg = 'offset={}'.format(offset)381 overlap_count = mask1.overlap_area(mask2, offset)382 self.assertEqual(overlap_count, expected_count, msg)383 # Ensure mask1/mask2 unchanged.384 self.assertEqual(mask1.count(), mask1_count, msg)385 self.assertEqual(mask2.count(), mask2_count, msg)386 self.assertEqual(mask1.get_size(), mask1_size, msg)387 self.assertEqual(mask2.get_size(), mask2_size, msg)388 def test_overlap_area__invalid_mask_arg(self):389 """Ensure overlap_area handles invalid mask arguments correctly."""390 size = (3, 5)391 offset = (0, 0)392 mask = pygame.mask.Mask(size)393 invalid_mask = pygame.Surface(size)394 with self.assertRaises(TypeError):395 overlap_count = mask.overlap_area(invalid_mask, offset)396 def test_overlap_area__invalid_offset_arg(self):397 """Ensure overlap_area handles invalid offset arguments correctly."""398 size = (7, 2)399 offset = '(0, 0)'400 mask1 = pygame.mask.Mask(size)401 mask2 = pygame.mask.Mask(size)402 with self.assertRaises(TypeError):403 overlap_count = mask1.overlap_area(mask2, offset)404 def test_overlap_mask(self):405 """Ensure overlap_mask's mask has correct bits set.406 Testing the different combinations of full/empty masks:407 (mask1-filled) 1 overlap_mask 1 (mask2-filled)408 (mask1-empty) 0 overlap_mask 1 (mask2-filled)409 (mask1-filled) 1 overlap_mask 0 (mask2-empty)410 (mask1-empty) 0 overlap_mask 0 (mask2-empty)411 """412 expected_size = (4, 4)413 offset = (0, 0)414 expected_default = pygame.mask.Mask(expected_size)415 expected_masks = {416 (True, True) : pygame.mask.Mask(expected_size, fill=True)}417 for fill2 in (True, False):418 mask2 = pygame.mask.Mask(expected_size, fill=fill2)419 mask2_count = mask2.count()420 for fill1 in (True, False):421 key = (fill1, fill2)422 msg = 'key={}'.format(key)423 mask1 = pygame.mask.Mask(expected_size, fill=fill1)424 mask1_count = mask1.count()425 expected_mask = expected_masks.get(key, expected_default)426 overlap_mask = mask1.overlap_mask(mask2, offset)427 self._assertMaskEqual(overlap_mask, expected_mask, msg)428 # Ensure mask1/mask2 unchanged.429 self.assertEqual(mask1.count(), mask1_count, msg)430 self.assertEqual(mask2.count(), mask2_count, msg)431 self.assertEqual(mask1.get_size(), expected_size, msg)432 self.assertEqual(mask2.get_size(), expected_size, msg)433 def test_overlap_mask__bits_set(self):434 """Ensure overlap_mask's mask has correct bits set."""435 mask1 = pygame.mask.Mask((50, 50), fill=True)436 mask2 = pygame.mask.Mask((300, 10), fill=True)437 mask1_count = mask1.count()438 mask2_count = mask2.count()439 mask1_size = mask1.get_size()440 mask2_size = mask2.get_size()441 mask3 = mask1.overlap_mask(mask2, (-1, 0))442 for i in range(50):443 for j in range(10):444 self.assertEqual(mask3.get_at((i, j)), 1,445 '({}, {})'.format(i, j))446 for i in range(50):447 for j in range(11, 50):448 self.assertEqual(mask3.get_at((i, j)), 0,449 '({}, {})'.format(i, j))450 # Ensure mask1/mask2 unchanged.451 self.assertEqual(mask1.count(), mask1_count)452 self.assertEqual(mask2.count(), mask2_count)453 self.assertEqual(mask1.get_size(), mask1_size)454 self.assertEqual(mask2.get_size(), mask2_size)455 def test_overlap_mask__offset(self):456 """Ensure an offset overlap_mask's mask is correctly calculated."""457 mask1 = pygame.mask.Mask((65, 3), fill=True)458 mask2 = pygame.mask.Mask((66, 4), fill=True)459 mask1_count = mask1.count()460 mask2_count = mask2.count()461 expected_size = mask1.get_size()462 mask2_size = mask2.get_size()463 # Using rects to help determine the overlapping area.464 rect1 = pygame.Rect((0, 0), expected_size)465 rect2 = pygame.Rect((0, 0), mask2_size)466 for offset in self.ORIGIN_OFFSETS:467 msg = 'offset={}'.format(offset)468 rect2.topleft = offset469 overlap_rect = rect1.clip(rect2)470 expected_count = overlap_rect.w * overlap_rect.h471 overlap_mask = mask1.overlap_mask(mask2, offset)472 self.assertEqual(overlap_mask.count(), expected_count, msg)473 self.assertEqual(overlap_mask.get_size(), expected_size, msg)474 # Ensure mask1/mask2 unchanged.475 self.assertEqual(mask1.count(), mask1_count, msg)476 self.assertEqual(mask2.count(), mask2_count, msg)477 self.assertEqual(mask1.get_size(), expected_size, msg)478 self.assertEqual(mask2.get_size(), mask2_size, msg)479 def test_overlap_mask__offset_boundary(self):480 """Ensures overlap_mask handles offsets and boundaries correctly."""481 mask1 = pygame.mask.Mask((9, 3), fill=True)482 mask2 = pygame.mask.Mask((11, 5), fill=True)483 mask1_count = mask1.count()484 mask2_count = mask2.count()485 mask1_size = mask1.get_size()486 mask2_size = mask2.get_size()487 expected_count = 0488 expected_size = mask1_size489 # Check the 4 boundaries.490 offsets = ((mask1_size[0], 0), # off right491 (0, mask1_size[1]), # off bottom492 (-mask2_size[0], 0), # off left493 (0, -mask2_size[1])) # off top494 for offset in offsets:495 msg = 'offset={}'.format(offset)496 overlap_mask = mask1.overlap_mask(mask2, offset)497 self.assertEqual(overlap_mask.count(), expected_count, msg)498 self.assertEqual(overlap_mask.get_size(), expected_size, msg)499 # Ensure mask1/mask2 unchanged.500 self.assertEqual(mask1.count(), mask1_count, msg)501 self.assertEqual(mask2.count(), mask2_count, msg)502 self.assertEqual(mask1.get_size(), mask1_size, msg)503 self.assertEqual(mask2.get_size(), mask2_size, msg)504 def test_overlap_mask__invalid_mask_arg(self):505 """Ensure overlap_mask handles invalid mask arguments correctly."""506 size = (3, 2)507 offset = (0, 0)508 mask = pygame.mask.Mask(size)509 invalid_mask = pygame.Surface(size)510 with self.assertRaises(TypeError):511 overlap_mask = mask.overlap_mask(invalid_mask, offset)512 def test_overlap_mask__invalid_offset_arg(self):513 """Ensure overlap_mask handles invalid offset arguments correctly."""514 size = (5, 2)515 offset = '(0, 0)'516 mask1 = pygame.mask.Mask(size)517 mask2 = pygame.mask.Mask(size)518 with self.assertRaises(TypeError):519 overlap_mask = mask1.overlap_mask(mask2, offset)520 def test_mask_access( self ):521 """ do the set_at, and get_at parts work correctly?522 """523 m = pygame.Mask((10,10))524 m.set_at((0,0), 1)525 self.assertEqual(m.get_at((0,0)), 1)526 m.set_at((9,0), 1)527 self.assertEqual(m.get_at((9,0)), 1)528 #s = pygame.Surface((10,10))529 #s.set_at((1,0), (0, 0, 1, 255))530 #self.assertEqual(s.get_at((1,0)), (0, 0, 1, 255))531 #s.set_at((-1,0), (0, 0, 1, 255))532 # out of bounds, should get IndexError533 self.assertRaises(IndexError, lambda : m.get_at((-1,0)) )534 self.assertRaises(IndexError, lambda : m.set_at((-1,0), 1) )535 self.assertRaises(IndexError, lambda : m.set_at((10,0), 1) )536 self.assertRaises(IndexError, lambda : m.set_at((0,10), 1) )537 def test_fill(self):538 """Ensure a mask can be filled."""539 width, height = 11, 23540 expected_count = width * height541 expected_size = (width, height)542 mask = pygame.mask.Mask(expected_size)543 mask.fill()544 self.assertEqual(mask.count(), expected_count)545 self.assertEqual(mask.get_size(), expected_size)546 def test_clear(self):547 """Ensure a mask can be cleared."""548 expected_count = 0549 expected_size = (13, 27)550 mask = pygame.mask.Mask(expected_size, fill=True)551 mask.clear()552 self.assertEqual(mask.count(), expected_count)553 self.assertEqual(mask.get_size(), expected_size)554 def test_invert(self):555 """Ensure a mask can be inverted."""556 side = 73557 expected_size = (side, side)558 mask1 = pygame.mask.Mask(expected_size)559 mask2 = pygame.mask.Mask(expected_size, fill=True)560 expected_count1 = side * side561 expected_count2 = 0562 for i in range(side):563 expected_count1 -= 1564 expected_count2 += 1565 pos = (i, i)566 mask1.set_at(pos)567 mask2.set_at(pos, 0)568 mask1.invert()569 mask2.invert()570 self.assertEqual(mask1.count(), expected_count1)571 self.assertEqual(mask2.count(), expected_count2)572 self.assertEqual(mask1.get_size(), expected_size)573 self.assertEqual(mask2.get_size(), expected_size)574 for i in range(side):575 pos = (i, i)576 msg = 'pos={}'.format(pos)577 self.assertEqual(mask1.get_at(pos), 0, msg)578 self.assertEqual(mask2.get_at(pos), 1, msg)579 def test_invert__full(self):580 """Ensure a full mask can be inverted."""581 expected_count = 0582 expected_size = (43, 97)583 mask = pygame.mask.Mask(expected_size, fill=True)584 mask.invert()585 self.assertEqual(mask.count(), expected_count)586 self.assertEqual(mask.get_size(), expected_size)587 def test_invert__empty(self):588 """Ensure an empty mask can be inverted."""589 width, height = 43, 97590 expected_size = (width, height)591 expected_count = width * height592 mask = pygame.mask.Mask(expected_size)593 mask.invert()594 self.assertEqual(mask.count(), expected_count)595 self.assertEqual(mask.get_size(), expected_size)596 def test_scale(self):597 """Ensure a mask can be scaled."""598 width, height = 43, 61599 original_size = (width, height)600 for fill in (True, False):601 original_mask = pygame.mask.Mask(original_size, fill=fill)602 original_count = width * height if fill else 0603 # Test a range of sizes. Also tests scaling to 'same'604 # size when new_w, new_h = width, height605 for new_w in range(width - 10, width + 10):606 for new_h in range(height - 10, height + 10):607 expected_size = (new_w, new_h)608 expected_count = new_w * new_h if fill else 0609 msg = 'size={}'.format(expected_size)610 mask = original_mask.scale(expected_size)611 self.assertEqual(mask.count(), expected_count, msg)612 self.assertEqual(mask.get_size(), expected_size)613 # Ensure the original mask is unchanged.614 self.assertEqual(original_mask.count(), original_count,615 msg)616 self.assertEqual(original_mask.get_size(), original_size,617 msg)618 def test_scale__negative_size(self):619 """Ensure scale handles negative sizes correctly."""620 mask = pygame.Mask((100, 100))621 with self.assertRaises(ValueError):622 mask.scale((-1, -1))623 with self.assertRaises(ValueError):624 mask.scale((-1, 10))625 with self.assertRaises(ValueError):626 mask.scale((10, -1))627 def test_draw(self):628 """Ensure a mask can be drawn onto another mask.629 Testing the different combinations of full/empty masks:630 (mask1-filled) 1 draw 1 (mask2-filled)631 (mask1-empty) 0 draw 1 (mask2-filled)632 (mask1-filled) 1 draw 0 (mask2-empty)633 (mask1-empty) 0 draw 0 (mask2-empty)634 """635 expected_size = (4, 4)636 offset = (0, 0)637 expected_default = pygame.mask.Mask(expected_size, fill=True)638 expected_masks = {(False, False) : pygame.mask.Mask(expected_size)}639 for fill2 in (True, False):640 mask2 = pygame.mask.Mask(expected_size, fill=fill2)641 mask2_count = mask2.count()642 for fill1 in (True, False):643 key = (fill1, fill2)644 msg = 'key={}'.format(key)645 mask1 = pygame.mask.Mask(expected_size, fill=fill1)646 expected_mask = expected_masks.get(key, expected_default)647 mask1.draw(mask2, offset)648 self._assertMaskEqual(mask1, expected_mask, msg)649 # Ensure mask2 unchanged.650 self.assertEqual(mask2.count(), mask2_count, msg)651 self.assertEqual(mask2.get_size(), expected_size, msg)652 def test_draw__offset(self):653 """Ensure an offset mask can be drawn onto another mask."""654 mask1 = pygame.mask.Mask((65, 3))655 mask2 = pygame.mask.Mask((66, 4), fill=True)656 mask2_count = mask2.count()657 mask1_size = mask1.get_size()658 mask2_size = mask2.get_size()659 # Using rects to help determine the overlapping area.660 rect1 = pygame.Rect((0, 0), mask1_size)661 rect2 = pygame.Rect((0, 0), mask2_size)662 for offset in self.ORIGIN_OFFSETS:663 msg = 'offset={}'.format(offset)664 rect2.topleft = offset665 overlap_rect = rect1.clip(rect2)666 expected_count = overlap_rect.w * overlap_rect.h667 mask1.clear() # Ensure it's empty for testing each offset.668 mask1.draw(mask2, offset)669 self.assertEqual(mask1.count(), expected_count, msg)670 self.assertEqual(mask1.get_size(), mask1_size, msg)671 # Ensure mask2 unchanged.672 self.assertEqual(mask2.count(), mask2_count, msg)673 self.assertEqual(mask2.get_size(), mask2_size, msg)674 def test_draw__offset_boundary(self):675 """Ensures draw handles offsets and boundaries correctly."""676 mask1 = pygame.mask.Mask((13, 5))677 mask2 = pygame.mask.Mask((7, 3), fill=True)678 mask1_count = mask1.count()679 mask2_count = mask2.count()680 mask1_size = mask1.get_size()681 mask2_size = mask2.get_size()682 # Check the 4 boundaries.683 offsets = ((mask1_size[0], 0), # off right684 (0, mask1_size[1]), # off bottom685 (-mask2_size[0], 0), # off left686 (0, -mask2_size[1])) # off top687 for offset in offsets:688 msg = 'offset={}'.format(offset)689 mask1.draw(mask2, offset)690 # Ensure mask1/mask2 unchanged.691 self.assertEqual(mask1.count(), mask1_count, msg)692 self.assertEqual(mask2.count(), mask2_count, msg)693 self.assertEqual(mask1.get_size(), mask1_size, msg)694 self.assertEqual(mask2.get_size(), mask2_size, msg)695 def test_draw__invalid_mask_arg(self):696 """Ensure draw handles invalid mask arguments correctly."""697 size = (7, 3)698 offset = (0, 0)699 mask = pygame.mask.Mask(size)700 invalid_mask = pygame.Surface(size)701 with self.assertRaises(TypeError):702 mask.draw(invalid_mask, offset)703 def test_draw__invalid_offset_arg(self):704 """Ensure draw handles invalid offset arguments correctly."""705 size = (5, 7)706 offset = '(0, 0)'707 mask1 = pygame.mask.Mask(size)708 mask2 = pygame.mask.Mask(size)709 with self.assertRaises(TypeError):710 mask1.draw(mask2, offset)711 def test_erase(self):712 """Ensure a mask can erase another mask.713 Testing the different combinations of full/empty masks:714 (mask1-filled) 1 erase 1 (mask2-filled)715 (mask1-empty) 0 erase 1 (mask2-filled)716 (mask1-filled) 1 erase 0 (mask2-empty)717 (mask1-empty) 0 erase 0 (mask2-empty)718 """719 expected_size = (4, 4)720 offset = (0, 0)721 expected_default = pygame.mask.Mask(expected_size)722 expected_masks = {723 (True, False) : pygame.mask.Mask(expected_size, fill=True)}724 for fill2 in (True, False):725 mask2 = pygame.mask.Mask(expected_size, fill=fill2)726 mask2_count = mask2.count()727 for fill1 in (True, False):728 key = (fill1, fill2)729 msg = 'key={}'.format(key)730 mask1 = pygame.mask.Mask(expected_size, fill=fill1)731 expected_mask = expected_masks.get(key, expected_default)732 mask1.erase(mask2, offset)733 self._assertMaskEqual(mask1, expected_mask, msg)734 # Ensure mask2 unchanged.735 self.assertEqual(mask2.count(), mask2_count, msg)736 self.assertEqual(mask2.get_size(), expected_size, msg)737 def test_erase__offset(self):738 """Ensure an offset mask can erase another mask."""739 mask1 = pygame.mask.Mask((65, 3))740 mask2 = pygame.mask.Mask((66, 4), fill=True)741 mask2_count = mask2.count()742 mask1_size = mask1.get_size()743 mask2_size = mask2.get_size()744 # Using rects to help determine the overlapping area.745 rect1 = pygame.Rect((0, 0), mask1_size)746 rect2 = pygame.Rect((0, 0), mask2_size)747 rect1_area = rect1.w * rect1.h748 for offset in self.ORIGIN_OFFSETS:749 msg = 'offset={}'.format(offset)750 rect2.topleft = offset751 overlap_rect = rect1.clip(rect2)752 expected_count = rect1_area - (overlap_rect.w * overlap_rect.h)753 mask1.fill() # Ensure it's filled for testing each offset.754 mask1.erase(mask2, offset)755 self.assertEqual(mask1.count(), expected_count, msg)756 self.assertEqual(mask1.get_size(), mask1_size, msg)757 # Ensure mask2 unchanged.758 self.assertEqual(mask2.count(), mask2_count, msg)759 self.assertEqual(mask2.get_size(), mask2_size, msg)760 def test_erase__offset_boundary(self):761 """Ensures erase handles offsets and boundaries correctly."""762 mask1 = pygame.mask.Mask((7, 11), fill=True)763 mask2 = pygame.mask.Mask((3, 13), fill=True)764 mask1_count = mask1.count()765 mask2_count = mask2.count()766 mask1_size = mask1.get_size()767 mask2_size = mask2.get_size()768 # Check the 4 boundaries.769 offsets = ((mask1_size[0], 0), # off right770 (0, mask1_size[1]), # off bottom771 (-mask2_size[0], 0), # off left772 (0, -mask2_size[1])) # off top773 for offset in offsets:774 msg = 'offset={}'.format(offset)775 mask1.erase(mask2, offset)776 # Ensure mask1/mask2 unchanged.777 self.assertEqual(mask1.count(), mask1_count, msg)778 self.assertEqual(mask2.count(), mask2_count, msg)779 self.assertEqual(mask1.get_size(), mask1_size, msg)780 self.assertEqual(mask2.get_size(), mask2_size, msg)781 def test_erase__invalid_mask_arg(self):782 """Ensure erase handles invalid mask arguments correctly."""783 size = (3, 7)784 offset = (0, 0)785 mask = pygame.mask.Mask(size)786 invalid_mask = pygame.Surface(size)787 with self.assertRaises(TypeError):788 mask.erase(invalid_mask, offset)789 def test_erase__invalid_offset_arg(self):790 """Ensure erase handles invalid offset arguments correctly."""791 size = (7, 5)792 offset = '(0, 0)'793 mask1 = pygame.mask.Mask(size)794 mask2 = pygame.mask.Mask(size)795 with self.assertRaises(TypeError):796 mask1.erase(mask2, offset)797 def test_count(self):798 """Ensure a mask's set bits are correctly counted."""799 side = 67800 expected_size = (side, side)801 expected_count = 0802 mask = pygame.mask.Mask(expected_size)803 for i in range(side):804 expected_count += 1805 mask.set_at((i, i))806 count = mask.count()807 self.assertEqual(count, expected_count)808 self.assertEqual(mask.get_size(), expected_size)809 def test_count__full_mask(self):810 """Ensure a full mask's set bits are correctly counted."""811 width, height = 17, 97812 expected_size = (width, height)813 expected_count = width * height814 mask = pygame.mask.Mask(expected_size, fill=True)815 count = mask.count()816 self.assertEqual(count, expected_count)817 self.assertEqual(mask.get_size(), expected_size)818 def test_count__empty_mask(self):819 """Ensure an empty mask's set bits are correctly counted."""820 expected_count = 0821 expected_size = (13, 27)822 mask = pygame.mask.Mask(expected_size)823 count = mask.count()824 self.assertEqual(count, expected_count)825 self.assertEqual(mask.get_size(), expected_size)826 def todo_test_centroid(self):827 """Ensure a mask's centroid is correctly calculated."""828 self.fail()829 def test_centroid__empty_mask(self):830 """Ensure an empty mask's centroid is correctly calculated."""831 expected_centroid = (0, 0)832 expected_size = (101, 103)833 mask = pygame.mask.Mask(expected_size)834 centroid = mask.centroid()835 self.assertEqual(centroid, expected_centroid)836 self.assertEqual(mask.get_size(), expected_size)837 def todo_test_angle(self):838 """Ensure a mask's orientation angle is correctly calculated."""839 self.fail()840 def test_angle__empty_mask(self):841 """Ensure an empty mask's angle is correctly calculated."""842 expected_angle = 0.0843 expected_size = (107, 43)844 mask = pygame.mask.Mask(expected_size)845 angle = mask.angle()846 self.assertIsInstance(angle, float)847 self.assertAlmostEqual(angle, expected_angle)848 self.assertEqual(mask.get_size(), expected_size)849 def test_drawing(self):850 """ Test fill, clear, invert, draw, erase851 """852 m = pygame.Mask((100,100))853 self.assertEqual(m.count(), 0)854 m.fill()855 self.assertEqual(m.count(), 10000)856 m2 = pygame.Mask((10, 10), fill=True)857 m.erase(m2, (50,50))858 self.assertEqual(m.count(), 9900)859 m.invert()860 self.assertEqual(m.count(), 100)861 m.draw(m2, (0,0))862 self.assertEqual(m.count(), 200)863 m.clear()864 self.assertEqual(m.count(), 0)865 def test_outline(self):866 """867 """868 m = pygame.Mask((20,20))869 self.assertEqual(m.outline(), [])870 m.set_at((10,10), 1)871 self.assertEqual(m.outline(), [(10,10)])872 m.set_at((10,12), 1)873 self.assertEqual(m.outline(10), [(10,10)])874 m.set_at((11,11), 1)875 self.assertEqual(m.outline(), [(10,10), (11,11), (10,12), (11,11), (10,10)])876 self.assertEqual(m.outline(2), [(10,10), (10,12), (10,10)])877 #TODO: Test more corner case outlines.878 def test_convolve__size(self):879 sizes = [(1,1), (31,31), (32,32), (100,100)]880 for s1 in sizes:881 m1 = pygame.Mask(s1)882 for s2 in sizes:883 m2 = pygame.Mask(s2)884 o = m1.convolve(m2)885 for i in (0,1):886 self.assertEqual(o.get_size()[i],887 m1.get_size()[i] + m2.get_size()[i] - 1)888 def test_convolve__point_identities(self):889 """Convolving with a single point is the identity, while convolving a point with something flips it."""890 m = random_mask((100,100))891 k = pygame.Mask((1,1))892 k.set_at((0,0))893 self._assertMaskEqual(m, m.convolve(k))894 self._assertMaskEqual(m, k.convolve(k.convolve(m)))895 def test_convolve__with_output(self):896 """checks that convolution modifies only the correct portion of the output"""897 m = random_mask((10,10))898 k = pygame.Mask((2,2))899 k.set_at((0,0))900 o = pygame.Mask((50,50))901 test = pygame.Mask((50,50))902 m.convolve(k,o)903 test.draw(m,(1,1))904 self._assertMaskEqual(o, test)905 o.clear()906 test.clear()907 m.convolve(k,o, (10,10))908 test.draw(m,(11,11))909 self._assertMaskEqual(o, test)910 def test_convolve__out_of_range(self):911 full = pygame.Mask((2, 2), fill=True)912 self.assertEqual(full.convolve(full, None, ( 0, 3)).count(), 0)913 self.assertEqual(full.convolve(full, None, ( 0, 2)).count(), 3)914 self.assertEqual(full.convolve(full, None, (-2, -2)).count(), 1)915 self.assertEqual(full.convolve(full, None, (-3, -3)).count(), 0)916 def test_convolve(self):917 """Tests the definition of convolution"""918 m1 = random_mask((100,100))919 m2 = random_mask((100,100))920 conv = m1.convolve(m2)921 for i in range(conv.get_size()[0]):922 for j in range(conv.get_size()[1]):923 self.assertEqual(conv.get_at((i,j)) == 0,924 m1.overlap(m2, (i - 99, j - 99)) is None)925 def _draw_component_pattern_box(self, mask, size, pos, inverse=False):926 # Helper method to create/draw a 'box' pattern for testing.927 #928 # 111929 # 101 3x3 example pattern930 # 111931 pattern = pygame.mask.Mask((size, size), fill=True)932 pattern.set_at((size // 2, size // 2), 0)933 if inverse:934 mask.erase(pattern, pos)935 pattern.invert()936 else:937 mask.draw(pattern, pos)938 return pattern939 def _draw_component_pattern_x(self, mask, size, pos, inverse=False):940 # Helper method to create/draw an 'X' pattern for testing.941 #942 # 101943 # 010 3x3 example pattern944 # 101945 pattern = pygame.mask.Mask((size, size))946 ymax = size - 1947 for y in range(size):948 for x in range(size):949 if x == y or x == ymax - y:950 pattern.set_at((x, y))951 if inverse:952 mask.erase(pattern, pos)953 pattern.invert()954 else:955 mask.draw(pattern, pos)956 return pattern957 def _draw_component_pattern_plus(self, mask, size, pos, inverse=False):958 # Helper method to create/draw a '+' pattern for testing.959 #960 # 010961 # 111 3x3 example pattern962 # 010963 pattern = pygame.mask.Mask((size, size))964 xmid = ymid = size // 2965 for y in range(size):966 for x in range(size):967 if x == xmid or y == ymid:968 pattern.set_at((x, y))969 if inverse:970 mask.erase(pattern, pos)971 pattern.invert()972 else:973 mask.draw(pattern, pos)974 return pattern975 def test_connected_component(self):976 """Ensure a mask's connected component is correctly calculated."""977 width, height = 41, 27978 expected_size = (width, height)979 original_mask = pygame.mask.Mask(expected_size)980 patterns = [] # Patterns and offsets.981 # Draw some connected patterns on the original mask.982 offset = (0, 0)983 pattern = self._draw_component_pattern_x(original_mask, 3, offset)984 patterns.append((pattern, offset))985 size = 4986 offset = (width - size, 0)987 pattern = self._draw_component_pattern_plus(original_mask, size,988 offset)989 patterns.append((pattern, offset))990 # Make this one the largest connected component.991 offset = (width // 2, height // 2)992 pattern = self._draw_component_pattern_box(original_mask, 7, offset)993 patterns.append((pattern, offset))994 expected_pattern, expected_offset = patterns[-1]995 expected_count = expected_pattern.count()996 original_count = sum(p.count() for p, _ in patterns)997 mask = original_mask.connected_component()998 self.assertEqual(mask.count(), expected_count)999 self.assertEqual(mask.get_size(), expected_size)1000 self.assertEqual(mask.overlap_area(expected_pattern, expected_offset),1001 expected_count)1002 # Ensure the original mask is unchanged.1003 self.assertEqual(original_mask.count(), original_count)1004 self.assertEqual(original_mask.get_size(), expected_size)1005 for pattern, offset in patterns:1006 self.assertEqual(original_mask.overlap_area(pattern, offset),1007 pattern.count())1008 def test_connected_component__full_mask(self):1009 """Ensure a mask's connected component is correctly calculated1010 when the mask is full."""1011 expected_size = (23, 31)1012 original_mask = pygame.mask.Mask(expected_size, fill=True)1013 expected_count = original_mask.count()1014 mask = original_mask.connected_component()1015 self.assertEqual(mask.count(), expected_count)1016 self.assertEqual(mask.get_size(), expected_size)1017 # Ensure the original mask is unchanged.1018 self.assertEqual(original_mask.count(), expected_count)1019 self.assertEqual(original_mask.get_size(), expected_size)1020 def test_connected_component__empty_mask(self):1021 """Ensure a mask's connected component is correctly calculated1022 when the mask is empty."""1023 expected_size = (37, 43)1024 original_mask = pygame.mask.Mask(expected_size)1025 original_count = original_mask.count()1026 expected_count = 01027 mask = original_mask.connected_component()1028 self.assertEqual(mask.count(), expected_count)1029 self.assertEqual(mask.get_size(), expected_size)1030 # Ensure the original mask is unchanged.1031 self.assertEqual(original_mask.count(), original_count)1032 self.assertEqual(original_mask.get_size(), expected_size)1033 def test_connected_component__one_set_bit(self):1034 """Ensure a mask's connected component is correctly calculated1035 when the coordinate's bit is set with a connected component of 1 bit.1036 """1037 width, height = 71, 671038 expected_size = (width, height)1039 original_mask = pygame.mask.Mask(expected_size, fill=True)1040 xset, yset = width // 2, height // 21041 set_pos = (xset, yset)1042 expected_offset = (xset - 1, yset - 1)1043 # This isolates the bit at set_pos from all the other bits.1044 expected_pattern = self._draw_component_pattern_box(original_mask, 3,1045 expected_offset, inverse=True)1046 expected_count = 11047 original_count = original_mask.count()1048 mask = original_mask.connected_component(set_pos)1049 self.assertEqual(mask.count(), expected_count)1050 self.assertEqual(mask.get_size(), expected_size)1051 self.assertEqual(mask.overlap_area(expected_pattern, expected_offset),1052 expected_count)1053 # Ensure the original mask is unchanged.1054 self.assertEqual(original_mask.count(), original_count)1055 self.assertEqual(original_mask.get_size(), expected_size)1056 self.assertEqual(original_mask.overlap_area(1057 expected_pattern, expected_offset), expected_count)1058 def test_connected_component__multi_set_bits(self):1059 """Ensure a mask's connected component is correctly calculated1060 when the coordinate's bit is set with a connected component of > 1 bit.1061 """1062 expected_size = (113, 67)1063 original_mask = pygame.mask.Mask(expected_size)1064 p_width, p_height = 11, 131065 set_pos = xset, yset = 11, 211066 expected_offset = (xset - 1, yset - 1)1067 expected_pattern = pygame.mask.Mask((p_width, p_height), fill=True)1068 # Make an unsymmetrical pattern. All the set bits need to be connected1069 # in the resulting pattern for this to work properly.1070 for y in range(3, p_height):1071 for x in range(1, p_width):1072 if x == y or x == y - 3 or x == p_width - 4:1073 expected_pattern.set_at((x, y), 0)1074 expected_count = expected_pattern.count()1075 original_mask.draw(expected_pattern, expected_offset)1076 mask = original_mask.connected_component(set_pos)1077 self.assertEqual(mask.count(), expected_count)1078 self.assertEqual(mask.get_size(), expected_size)1079 self.assertEqual(mask.overlap_area(expected_pattern, expected_offset),1080 expected_count)1081 # Ensure the original mask is unchanged.1082 self.assertEqual(original_mask.count(), expected_count)1083 self.assertEqual(original_mask.get_size(), expected_size)1084 self.assertEqual(original_mask.overlap_area(1085 expected_pattern, expected_offset), expected_count)1086 def test_connected_component__unset_bit(self):1087 """Ensure a mask's connected component is correctly calculated1088 when the coordinate's bit is unset.1089 """1090 width, height = 109, 1011091 expected_size = (width, height)1092 original_mask = pygame.mask.Mask(expected_size, fill=True)1093 unset_pos = (width // 2, height // 2)1094 original_mask.set_at(unset_pos, 0)1095 original_count = original_mask.count()1096 expected_count = 01097 mask = original_mask.connected_component(unset_pos)1098 self.assertEqual(mask.count(), expected_count)1099 self.assertEqual(mask.get_size(), expected_size)1100 # Ensure the original mask is unchanged.1101 self.assertEqual(original_mask.count(), original_count)1102 self.assertEqual(original_mask.get_size(), expected_size)1103 self.assertEqual(original_mask.get_at(unset_pos), 0)1104 def test_connected_component__out_of_bounds(self):1105 """Ensure connected_component() checks bounds."""1106 width, height = 19, 111107 original_size = (width, height)1108 original_mask = pygame.mask.Mask(original_size, fill=True)1109 original_count = original_mask.count()1110 for pos in ((0, -1), (-1, 0), (0, height + 1), (width + 1, 0)):1111 with self.assertRaises(IndexError):1112 mask = original_mask.connected_component(pos)1113 # Ensure the original mask is unchanged.1114 self.assertEqual(original_mask.count(), original_count)1115 self.assertEqual(original_mask.get_size(), original_size)1116 def test_connected_components(self):1117 """1118 """1119 m = pygame.Mask((10,10))1120 self.assertEqual(repr(m.connected_components()), "[]")1121 comp = m.connected_component()1122 self.assertEqual(m.count(), comp.count())1123 m.set_at((0,0), 1)1124 m.set_at((1,1), 1)1125 comp = m.connected_component()1126 comps = m.connected_components()1127 comps1 = m.connected_components(1)1128 comps2 = m.connected_components(2)1129 comps3 = m.connected_components(3)1130 self.assertEqual(comp.count(), comps[0].count())1131 self.assertEqual(comps1[0].count(), 2)1132 self.assertEqual(comps2[0].count(), 2)1133 self.assertEqual(repr(comps3), "[]")1134 m.set_at((9, 9), 1)1135 comp = m.connected_component()1136 comp1 = m.connected_component((1, 1))1137 comp2 = m.connected_component((2, 2))1138 comps = m.connected_components()1139 comps1 = m.connected_components(1)1140 comps2 = m.connected_components(2)1141 comps3 = m.connected_components(3)1142 self.assertEqual(comp.count(), 2)1143 self.assertEqual(comp1.count(), 2)1144 self.assertEqual(comp2.count(), 0)1145 self.assertEqual(len(comps), 2)1146 self.assertEqual(len(comps1), 2)1147 self.assertEqual(len(comps2), 1)1148 self.assertEqual(len(comps3), 0)1149 def test_get_bounding_rects(self):1150 """1151 """1152 m = pygame.Mask((10,10))1153 m.set_at((0,0), 1)1154 m.set_at((1,0), 1)1155 m.set_at((0,1), 1)1156 m.set_at((0,3), 1)1157 m.set_at((3,3), 1)1158 r = m.get_bounding_rects()1159 self.assertEqual(1160 repr(r),1161 "[<rect(0, 0, 2, 2)>, <rect(0, 3, 1, 1)>, <rect(3, 3, 1, 1)>]")1162 #11001163 #11111164 m = pygame.Mask((4,2))1165 m.set_at((0,0), 1)1166 m.set_at((1,0), 1)1167 m.set_at((2,0), 0)1168 m.set_at((3,0), 0)1169 m.set_at((0,1), 1)1170 m.set_at((1,1), 1)1171 m.set_at((2,1), 1)1172 m.set_at((3,1), 1)1173 r = m.get_bounding_rects()1174 self.assertEqual(repr(r), "[<rect(0, 0, 4, 2)>]")1175 #001001176 #011101177 #001001178 m = pygame.Mask((5,3))1179 m.set_at((0,0), 0)1180 m.set_at((1,0), 0)1181 m.set_at((2,0), 1)1182 m.set_at((3,0), 0)1183 m.set_at((4,0), 0)1184 m.set_at((0,1), 0)1185 m.set_at((1,1), 1)1186 m.set_at((2,1), 1)1187 m.set_at((3,1), 1)1188 m.set_at((4,1), 0)1189 m.set_at((0,2), 0)1190 m.set_at((1,2), 0)1191 m.set_at((2,2), 1)1192 m.set_at((3,2), 0)1193 m.set_at((4,2), 0)1194 r = m.get_bounding_rects()1195 self.assertEqual(repr(r), "[<rect(1, 0, 3, 3)>]")1196 #000101197 #001001198 #010001199 m = pygame.Mask((5,3))1200 m.set_at((0,0), 0)1201 m.set_at((1,0), 0)1202 m.set_at((2,0), 0)1203 m.set_at((3,0), 1)1204 m.set_at((4,0), 0)1205 m.set_at((0,1), 0)1206 m.set_at((1,1), 0)1207 m.set_at((2,1), 1)1208 m.set_at((3,1), 0)1209 m.set_at((4,1), 0)1210 m.set_at((0,2), 0)1211 m.set_at((1,2), 1)1212 m.set_at((2,2), 0)1213 m.set_at((3,2), 0)1214 m.set_at((4,2), 0)1215 r = m.get_bounding_rects()1216 self.assertEqual(repr(r), "[<rect(1, 0, 3, 3)>]")1217 #000111218 #111111219 m = pygame.Mask((5,2))1220 m.set_at((0,0), 0)1221 m.set_at((1,0), 0)1222 m.set_at((2,0), 0)1223 m.set_at((3,0), 1)1224 m.set_at((4,0), 1)1225 m.set_at((0,1), 1)1226 m.set_at((1,1), 1)1227 m.set_at((2,1), 1)1228 m.set_at((3,1), 1)1229 m.set_at((3,1), 1)1230 r = m.get_bounding_rects()1231 #TODO: this should really make one bounding rect.1232 #self.assertEqual(repr(r), "[<rect(0, 0, 5, 2)>]")1233 def test_zero_mask(self):1234 mask = pygame.mask.Mask((0, 0))1235 self.assertEqual(mask.get_size(), (0, 0))1236 mask = pygame.mask.Mask((100, 0))1237 self.assertEqual(mask.get_size(), (100, 0))1238 mask = pygame.mask.Mask((0, 100))1239 self.assertEqual(mask.get_size(), (0, 100))1240 def test_zero_mask_get_size(self):1241 """Ensures get_size correctly handles zero sized masks."""1242 for expected_size in ((41, 0), (0, 40), (0, 0)):1243 mask = pygame.mask.Mask(expected_size)1244 size = mask.get_size()1245 self.assertEqual(size, expected_size)1246 def test_zero_mask_get_at(self):1247 """Ensures get_at correctly handles zero sized masks."""1248 for size in ((51, 0), (0, 50), (0, 0)):1249 mask = pygame.mask.Mask(size)1250 with self.assertRaises(IndexError):1251 value = mask.get_at((0, 0))1252 def test_zero_mask_set_at(self):1253 """Ensures set_at correctly handles zero sized masks."""1254 for size in ((31, 0), (0, 30), (0, 0)):1255 mask = pygame.mask.Mask(size)1256 with self.assertRaises(IndexError):1257 mask.set_at((0, 0))1258 def test_zero_mask_overlap(self):1259 sizes = ((100, 0), (0, 100), (0, 0))1260 for size in sizes:1261 mask = pygame.mask.Mask(size)1262 mask2 = pygame.mask.Mask((100, 100))1263 self.assertEqual(mask.overlap(mask2, (0, 0)), None)1264 self.assertEqual(mask2.overlap(mask, (0, 0)), None)1265 def test_zero_mask_overlap_area(self):1266 sizes = ((100, 0), (0, 100), (0, 0))1267 for size in sizes:1268 mask = pygame.mask.Mask(size)1269 mask2 = pygame.mask.Mask((100, 100))1270 self.assertEqual(mask.overlap_area(mask2, (0, 0)), 0)1271 self.assertEqual(mask2.overlap_area(mask, (0, 0)), 0)1272 def test_zero_mask_overlap_mask(self):1273 sizes = ((100, 0), (0, 100), (0, 0))1274 for size in sizes:1275 mask = pygame.mask.Mask(size)1276 mask2 = pygame.mask.Mask((100, 100))1277 overlap_mask = mask.overlap_mask(mask2, (0, 0))1278 overlap_mask2 = mask2.overlap_mask(mask, (0, 0))1279 self.assertEqual(mask.get_size(), overlap_mask.get_size())1280 self.assertEqual(mask2.get_size(), overlap_mask2.get_size())1281 def test_zero_mask_fill(self):1282 sizes = ((100, 0), (0, 100), (0, 0))1283 for size in sizes:1284 mask = pygame.mask.Mask(size, fill=True)1285 self.assertEqual(mask.count(), 0)1286 def test_zero_mask_clear(self):1287 sizes = ((100, 0), (0, 100), (0, 0))1288 for size in sizes:1289 mask = pygame.mask.Mask(size)1290 mask.clear()1291 self.assertEqual(mask.count(), 0)1292 def test_zero_mask_flip(self):1293 sizes = ((100, 0), (0, 100), (0, 0))1294 for size in sizes:1295 mask = pygame.mask.Mask(size)1296 mask.invert()1297 self.assertEqual(mask.count(), 0)1298 def test_zero_mask_scale(self):1299 sizes = ((100, 0), (0, 100), (0, 0))1300 for size in sizes:1301 mask = pygame.mask.Mask(size)1302 mask2 = mask.scale((2, 3))1303 self.assertEqual(mask2.get_size(), (2, 3))1304 def test_zero_mask_draw(self):1305 sizes = ((100, 0), (0, 100), (0, 0))1306 for size in sizes:1307 mask = pygame.mask.Mask(size)1308 mask2 = pygame.mask.Mask((100, 100), fill=True)1309 before = [mask2.get_at((x, y)) for x in range(100) for y in range(100)]1310 mask.draw(mask2, (0, 0))1311 after = [mask2.get_at((x, y)) for x in range(100) for y in range(100)]1312 self.assertEqual(before, after)1313 def test_zero_mask_erase(self):1314 sizes = ((100, 0), (0, 100), (0, 0))1315 for size in sizes:1316 mask = pygame.mask.Mask(size)1317 mask2 = pygame.mask.Mask((100, 100), fill=True)1318 before = [mask2.get_at((x, y)) for x in range(100) for y in range(100)]1319 mask.erase(mask2, (0, 0))1320 after = [mask2.get_at((x, y)) for x in range(100) for y in range(100)]1321 self.assertEqual(before, after)1322 def test_zero_mask_count(self):1323 sizes = ((100, 0), (0, 100), (0, 0))1324 for size in sizes:1325 mask = pygame.mask.Mask(size, fill=True)1326 self.assertEqual(mask.count(), 0)1327 def test_zero_mask_centroid(self):1328 sizes = ((100, 0), (0, 100), (0, 0))1329 for size in sizes:1330 mask = pygame.mask.Mask(size)1331 self.assertEqual(mask.centroid(), (0, 0))1332 def test_zero_mask_angle(self):1333 sizes = ((100, 0), (0, 100), (0, 0))1334 for size in sizes:1335 mask = pygame.mask.Mask(size)1336 self.assertEqual(mask.angle(), 0.0)1337 def test_zero_mask_outline(self):1338 """Ensures outline correctly handles zero sized masks."""1339 expected_points = []1340 for size in ((61, 0), (0, 60), (0, 0)):1341 mask = pygame.mask.Mask(size)1342 points = mask.outline()1343 self.assertListEqual(points, expected_points,1344 'size={}'.format(size))1345 def test_zero_mask_outline__with_arg(self):1346 """Ensures outline correctly handles zero sized masks1347 when using the skip pixels argument."""1348 expected_points = []1349 for size in ((66, 0), (0, 65), (0, 0)):1350 mask = pygame.mask.Mask(size)1351 points = mask.outline(10)1352 self.assertListEqual(points, expected_points,1353 'size={}'.format(size))1354 def test_zero_mask_convolve(self):1355 """Ensures convolve correctly handles zero sized masks.1356 Tests the different combinations of sized and zero sized masks.1357 """1358 for size1 in ((17, 13), (71, 0), (0, 70), (0, 0)):1359 mask1 = pygame.mask.Mask(size1, fill=True)1360 for size2 in ((11, 7), (81, 0), (0, 60), (0, 0)):1361 msg = 'sizes={}, {}'.format(size1, size2)1362 mask2 = pygame.mask.Mask(size2, fill=True)1363 expected_size = (max(0, size1[0] + size2[0] - 1),1364 max(0, size1[1] + size2[1] - 1))1365 mask = mask1.convolve(mask2)1366 self.assertIsNot(mask, mask2, msg)1367 self.assertEqual(mask.get_size(), expected_size, msg)1368 def test_zero_mask_convolve__with_output_mask(self):1369 """Ensures convolve correctly handles zero sized masks1370 when using an output mask argument.1371 Tests the different combinations of sized and zero sized masks.1372 """1373 for size1 in ((11, 17), (91, 0), (0, 90), (0, 0)):1374 mask1 = pygame.mask.Mask(size1, fill=True)1375 for size2 in ((13, 11), (83, 0), (0, 62), (0, 0)):1376 mask2 = pygame.mask.Mask(size2, fill=True)1377 for output_size in ((7, 5), (71, 0), (0, 70), (0, 0)):1378 msg = 'sizes={}, {}, {}'.format(size1, size2, output_size)1379 output_mask = pygame.mask.Mask(output_size)1380 mask = mask1.convolve(mask2, output_mask)1381 self.assertIs(mask, output_mask, msg)1382 self.assertEqual(mask.get_size(), output_size, msg)...

Full Screen

Full Screen

phone-nl.js

Source:phone-nl.js Github

copy

Full Screen

1[2 {"mask": "+31-10-###-####", "cc": "NL", "cd": "Netherlands", "city": "Rotterdam"},3 {"mask": "+31-111-###-###", "cc": "NL", "cd": "Netherlands", "city": "Zierikzee"},4 {"mask": "+31-113-###-###", "cc": "NL", "cd": "Netherlands", "city": "Goes"},5 {"mask": "+31-114-###-###", "cc": "NL", "cd": "Netherlands", "city": "Hulst"},6 {"mask": "+31-115-###-###", "cc": "NL", "cd": "Netherlands", "city": "Terneuzen"},7 {"mask": "+31-117-###-###", "cc": "NL", "cd": "Netherlands", "city": "Oostburg"},8 {"mask": "+31-118-###-###", "cc": "NL", "cd": "Netherlands", "city": "Middelburg"},9 {"mask": "+31-13-###-####", "cc": "NL", "cd": "Netherlands", "city": "Tilburg"},10 {"mask": "+31-14-###-####", "cc": "NL", "cd": "Netherlands", "city": "Intern gebruik door KPN"},11 {"mask": "+31-15-###-####", "cc": "NL", "cd": "Netherlands", "city": "Delft"},12 {"mask": "+31-161-###-###", "cc": "NL", "cd": "Netherlands", "city": "Rijen"},13 {"mask": "+31-162-###-###", "cc": "NL", "cd": "Netherlands", "city": "Oosterhout"},14 {"mask": "+31-164-###-###", "cc": "NL", "cd": "Netherlands", "city": "Bergen op Zoom"},15 {"mask": "+31-165-###-###", "cc": "NL", "cd": "Netherlands", "city": "Roosendaal"},16 {"mask": "+31-166-###-###", "cc": "NL", "cd": "Netherlands", "city": "Tholen"},17 {"mask": "+31-167-###-###", "cc": "NL", "cd": "Netherlands", "city": "Steenbergen"},18 {"mask": "+31-168-###-###", "cc": "NL", "cd": "Netherlands", "city": "Zevenbergen"},19 {"mask": "+31-172-###-###", "cc": "NL", "cd": "Netherlands", "city": "Alphen aan den Rijn"},20 {"mask": "+31-174-###-###", "cc": "NL", "cd": "Netherlands", "city": "Naaldwijk"},21 {"mask": "+31-180-###-###", "cc": "NL", "cd": "Netherlands", "city": "Krimpen aan den IJsel"},22 {"mask": "+31-181-###-###", "cc": "NL", "cd": "Netherlands", "city": "Spijkenisse"},23 {"mask": "+31-182-###-###", "cc": "NL", "cd": "Netherlands", "city": "Gouda"},24 {"mask": "+31-183-###-###", "cc": "NL", "cd": "Netherlands", "city": "Gorinchem"},25 {"mask": "+31-184-###-###", "cc": "NL", "cd": "Netherlands", "city": "Sliedrecht"},26 {"mask": "+31-186-###-###", "cc": "NL", "cd": "Netherlands", "city": "Oud-Beijerland"},27 {"mask": "+31-187-###-###", "cc": "NL", "cd": "Netherlands", "city": "Middelharnis"},28 {"mask": "+31-20-###-####", "cc": "NL", "cd": "Netherlands", "city": "Amsterdam"},29 {"mask": "+31-222-###-###", "cc": "NL", "cd": "Netherlands", "city": "Den Burg"},30 {"mask": "+31-223-###-###", "cc": "NL", "cd": "Netherlands", "city": "Den Helder"},31 {"mask": "+31-224-###-###", "cc": "NL", "cd": "Netherlands", "city": "Schagen"},32 {"mask": "+31-226-###-###", "cc": "NL", "cd": "Netherlands", "city": "Noord-Scharwoude"},33 {"mask": "+31-227-###-###", "cc": "NL", "cd": "Netherlands", "city": "Middenmeer"},34 {"mask": "+31-228-###-###", "cc": "NL", "cd": "Netherlands", "city": "Enkhuizen"},35 {"mask": "+31-229-###-###", "cc": "NL", "cd": "Netherlands", "city": "Hoorn"},36 {"mask": "+31-23-###-####", "cc": "NL", "cd": "Netherlands", "city": "Haarlem"},37 {"mask": "+31-24-###-####", "cc": "NL", "cd": "Netherlands", "city": "Nijmegen"},38 {"mask": "+31-251-###-###", "cc": "NL", "cd": "Netherlands", "city": "Beverwijk"},39 {"mask": "+31-252-###-###", "cc": "NL", "cd": "Netherlands", "city": "Hillegom"},40 {"mask": "+31-255-###-###", "cc": "NL", "cd": "Netherlands", "city": "IJmuiden"},41 {"mask": "+31-26-###-####", "cc": "NL", "cd": "Netherlands", "city": "Arnhem"},42 {"mask": "+31-294-###-###", "cc": "NL", "cd": "Netherlands", "city": "Weesp"},43 {"mask": "+31-297-###-###", "cc": "NL", "cd": "Netherlands", "city": "Uithoorn"},44 {"mask": "+31-299-###-###", "cc": "NL", "cd": "Netherlands", "city": "Purmerend"},45 {"mask": "+31-30-###-####", "cc": "NL", "cd": "Netherlands", "city": "Utrecht"},46 {"mask": "+31-313-###-###", "cc": "NL", "cd": "Netherlands", "city": "Dieren"},47 {"mask": "+31-314-###-###", "cc": "NL", "cd": "Netherlands", "city": "Doetinchem"},48 {"mask": "+31-315-###-###", "cc": "NL", "cd": "Netherlands", "city": "Terborg"},49 {"mask": "+31-316-###-###", "cc": "NL", "cd": "Netherlands", "city": "Zevenaar"},50 {"mask": "+31-317-###-###", "cc": "NL", "cd": "Netherlands", "city": "Wageningen"},51 {"mask": "+31-318-###-###", "cc": "NL", "cd": "Netherlands", "city": "Ede"},52 {"mask": "+31-320-###-###", "cc": "NL", "cd": "Netherlands", "city": "Lelystad"},53 {"mask": "+31-321-###-###", "cc": "NL", "cd": "Netherlands", "city": "Dronten"},54 {"mask": "+31-33-###-####", "cc": "NL", "cd": "Netherlands", "city": "Amersfoort"},55 {"mask": "+31-341-###-###", "cc": "NL", "cd": "Netherlands", "city": "Harderwijk"},56 {"mask": "+31-342-###-###", "cc": "NL", "cd": "Netherlands", "city": "Barneveld"},57 {"mask": "+31-343-###-###", "cc": "NL", "cd": "Netherlands", "city": "Doorn"},58 {"mask": "+31-344-###-###", "cc": "NL", "cd": "Netherlands", "city": "Tiel"},59 {"mask": "+31-294-###-###", "cc": "NL", "cd": "Netherlands", "city": "Weesp"},60 {"mask": "+31-297-###-###", "cc": "NL", "cd": "Netherlands", "city": "Uithoorn"},61 {"mask": "+31-299-###-###", "cc": "NL", "cd": "Netherlands", "city": "Purmerend"},62 {"mask": "+31-30-###-####", "cc": "NL", "cd": "Netherlands", "city": "Utrecht"},63 {"mask": "+31-313-###-###", "cc": "NL", "cd": "Netherlands", "city": "Dieren"},64 {"mask": "+31-314-###-###", "cc": "NL", "cd": "Netherlands", "city": "Doetinchem"},65 {"mask": "+31-315-###-###", "cc": "NL", "cd": "Netherlands", "city": "Terborg"},66 {"mask": "+31-316-###-###", "cc": "NL", "cd": "Netherlands", "city": "Zevenaar"},67 {"mask": "+31-317-###-###", "cc": "NL", "cd": "Netherlands", "city": "Wageningen"},68 {"mask": "+31-318-###-###", "cc": "NL", "cd": "Netherlands", "city": "Ede"},69 {"mask": "+31-320-###-###", "cc": "NL", "cd": "Netherlands", "city": "Lelystad"},70 {"mask": "+31-321-###-###", "cc": "NL", "cd": "Netherlands", "city": "Dronten"},71 {"mask": "+31-33-###-####", "cc": "NL", "cd": "Netherlands", "city": "Amersfoort"},72 {"mask": "+31-341-###-###", "cc": "NL", "cd": "Netherlands", "city": "Harderwijk"},73 {"mask": "+31-342-###-###", "cc": "NL", "cd": "Netherlands", "city": "Barneveld"},74 {"mask": "+31-343-###-###", "cc": "NL", "cd": "Netherlands", "city": "Doorn"},75 {"mask": "+31-344-###-###", "cc": "NL", "cd": "Netherlands", "city": "Tiel"},76 {"mask": "+31-345-###-###", "cc": "NL", "cd": "Netherlands", "city": "Culemborg"},77 {"mask": "+31-346-###-###", "cc": "NL", "cd": "Netherlands", "city": "Maarssen"},78 {"mask": "+31-347-###-###", "cc": "NL", "cd": "Netherlands", "city": "Vianen"},79 {"mask": "+31-348-###-###", "cc": "NL", "cd": "Netherlands", "city": "Woerden"},80 {"mask": "+31-35-###-####", "cc": "NL", "cd": "Netherlands", "city": "Hilversum"},81 {"mask": "+31-36-###-####", "cc": "NL", "cd": "Netherlands", "city": "Almere"},82 {"mask": "+31-38-###-####", "cc": "NL", "cd": "Netherlands", "city": "Zwolle"},83 {"mask": "+31-40-###-####", "cc": "NL", "cd": "Netherlands", "city": "Eindhoven"},84 {"mask": "+31-411-###-###", "cc": "NL", "cd": "Netherlands", "city": "Boxtel"},85 {"mask": "+31-412-###-###", "cc": "NL", "cd": "Netherlands", "city": "Oss"},86 {"mask": "+31-413-###-###", "cc": "NL", "cd": "Netherlands", "city": "Veghel"},87 {"mask": "+31-416-###-###", "cc": "NL", "cd": "Netherlands", "city": "Waalwijk"},88 {"mask": "+31-418-###-###", "cc": "NL", "cd": "Netherlands", "city": "Zaltbommel"},89 {"mask": "+31-43-###-####", "cc": "NL", "cd": "Netherlands", "city": "Maastricht"},90 {"mask": "+31-45-###-####", "cc": "NL", "cd": "Netherlands", "city": "Heerlen"},91 {"mask": "+31-46-###-####", "cc": "NL", "cd": "Netherlands", "city": "Sittard"},92 {"mask": "+31-475-###-###", "cc": "NL", "cd": "Netherlands", "city": "Roermond"},93 {"mask": "+31-478-###-###", "cc": "NL", "cd": "Netherlands", "city": "Venray"},94 {"mask": "+31-481-###-###", "cc": "NL", "cd": "Netherlands", "city": "Bemmel"},95 {"mask": "+31-485-###-###", "cc": "NL", "cd": "Netherlands", "city": "Cuijk"},96 {"mask": "+31-486-###-###", "cc": "NL", "cd": "Netherlands", "city": "Grave"},97 {"mask": "+31-487-###-###", "cc": "NL", "cd": "Netherlands", "city": "Druten"},98 {"mask": "+31-488-###-###", "cc": "NL", "cd": "Netherlands", "city": "Zetten"},99 {"mask": "+31-492-###-###", "cc": "NL", "cd": "Netherlands", "city": "Helmond"},100 {"mask": "+31-493-###-###", "cc": "NL", "cd": "Netherlands", "city": "Deurne"},101 {"mask": "+31-495-###-###", "cc": "NL", "cd": "Netherlands", "city": "Weert"},102 {"mask": "+31-497-###-###", "cc": "NL", "cd": "Netherlands", "city": "Eersel"},103 {"mask": "+31-499-###-###", "cc": "NL", "cd": "Netherlands", "city": "Best"},104 {"mask": "+31-50-###-####", "cc": "NL", "cd": "Netherlands", "city": "Groningen"},105 {"mask": "+31-511-###-###", "cc": "NL", "cd": "Netherlands", "city": "Feanw�lden"},106 {"mask": "+31-512-###-###", "cc": "NL", "cd": "Netherlands", "city": "Drachten"},107 {"mask": "+31-513-###-###", "cc": "NL", "cd": "Netherlands", "city": "Heerenveen"},108 {"mask": "+31-514-###-###", "cc": "NL", "cd": "Netherlands", "city": "Balk"},109 {"mask": "+31-515-###-###", "cc": "NL", "cd": "Netherlands", "city": "Sneek"},110 {"mask": "+31-516-###-###", "cc": "NL", "cd": "Netherlands", "city": "Oosterwolde"},111 {"mask": "+31-517-###-###", "cc": "NL", "cd": "Netherlands", "city": "Franeker"},112 {"mask": "+31-518-###-###", "cc": "NL", "cd": "Netherlands", "city": "St Annaparochie"},113 {"mask": "+31-519-###-###", "cc": "NL", "cd": "Netherlands", "city": "Dokkum"},114 {"mask": "+31-521-###-###", "cc": "NL", "cd": "Netherlands", "city": "Steenwijk"},115 {"mask": "+31-522-###-###", "cc": "NL", "cd": "Netherlands", "city": "Meppel"},116 {"mask": "+31-523-###-###", "cc": "NL", "cd": "Netherlands", "city": "Dedemsvaart"},117 {"mask": "+31-524-###-###", "cc": "NL", "cd": "Netherlands", "city": "Coevorden"},118 {"mask": "+31-525-###-###", "cc": "NL", "cd": "Netherlands", "city": "Elburg"},119 {"mask": "+31-527-###-###", "cc": "NL", "cd": "Netherlands", "city": "Emmeloord"},120 {"mask": "+31-528-###-###", "cc": "NL", "cd": "Netherlands", "city": "Hoogeveen"},121 {"mask": "+31-529-###-###", "cc": "NL", "cd": "Netherlands", "city": "Ommen"},122 {"mask": "+31-53-###-####", "cc": "NL", "cd": "Netherlands", "city": "Enschede"},123 {"mask": "+31-541-###-###", "cc": "NL", "cd": "Netherlands", "city": "Oldenzaal"},124 {"mask": "+31-543-###-###", "cc": "NL", "cd": "Netherlands", "city": "Winterswijk"},125 {"mask": "+31-544-###-###", "cc": "NL", "cd": "Netherlands", "city": "Groenlo"},126 {"mask": "+31-545-###-###", "cc": "NL", "cd": "Netherlands", "city": "Neede"},127 {"mask": "+31-546-###-###", "cc": "NL", "cd": "Netherlands", "city": "Almelo"},128 {"mask": "+31-547-###-###", "cc": "NL", "cd": "Netherlands", "city": "Goor"},129 {"mask": "+31-548-###-###", "cc": "NL", "cd": "Netherlands", "city": "Rijssen"},130 {"mask": "+31-55-###-####", "cc": "NL", "cd": "Netherlands", "city": "Apeldoorn"},131 {"mask": "+31-561-###-###", "cc": "NL", "cd": "Netherlands", "city": "Wolvega"},132 {"mask": "+31-562-###-###", "cc": "NL", "cd": "Netherlands", "city": "West-Terschelling"},133 {"mask": "+31-566-###-###", "cc": "NL", "cd": "Netherlands", "city": "Jirnsum"},134 {"mask": "+31-570-###-###", "cc": "NL", "cd": "Netherlands", "city": "Deventer"},135 {"mask": "+31-571-###-###", "cc": "NL", "cd": "Netherlands", "city": "Twello"},136 {"mask": "+31-572-###-###", "cc": "NL", "cd": "Netherlands", "city": "Raalte"},137 {"mask": "+31-573-###-###", "cc": "NL", "cd": "Netherlands", "city": "Lochem"},138 {"mask": "+31-575-###-###", "cc": "NL", "cd": "Netherlands", "city": "Zutphen"},139 {"mask": "+31-577-###-###", "cc": "NL", "cd": "Netherlands", "city": "Uddel"},140 {"mask": "+31-578-###-###", "cc": "NL", "cd": "Netherlands", "city": "Epe"},141 {"mask": "+31-58-###-####", "cc": "NL", "cd": "Netherlands", "city": "Leeuwarden"},142 {"mask": "+31-591-###-###", "cc": "NL", "cd": "Netherlands", "city": "Emmen"},143 {"mask": "+31-592-###-###", "cc": "NL", "cd": "Netherlands", "city": "Assen"},144 {"mask": "+31-593-###-###", "cc": "NL", "cd": "Netherlands", "city": "Beilen"},145 {"mask": "+31-594-###-###", "cc": "NL", "cd": "Netherlands", "city": "Zuidhorn"},146 {"mask": "+31-595-###-###", "cc": "NL", "cd": "Netherlands", "city": "Warffum"},147 {"mask": "+31-596-###-###", "cc": "NL", "cd": "Netherlands", "city": "Appingedam"},148 {"mask": "+31-597-###-###", "cc": "NL", "cd": "Netherlands", "city": "Winschoten"},149 {"mask": "+31-598-###-###", "cc": "NL", "cd": "Netherlands", "city": "Hoogezand"},150 {"mask": "+31-599-###-###", "cc": "NL", "cd": "Netherlands", "city": "Stadskanaal"},151 {"mask": "+31-70-###-####", "cc": "NL", "cd": "Netherlands", "city": "Den Haag"},152 {"mask": "+31-71-###-####", "cc": "NL", "cd": "Netherlands", "city": "Leiden"},153 {"mask": "+31-72-###-####", "cc": "NL", "cd": "Netherlands", "city": "Alkmaar"},154 {"mask": "+31-73-###-####", "cc": "NL", "cd": "Netherlands", "city": "'s-Hertogenbosch"},155 {"mask": "+31-74-###-####", "cc": "NL", "cd": "Netherlands", "city": "Hengelo"},156 {"mask": "+31-75-###-####", "cc": "NL", "cd": "Netherlands", "city": "Zaandam"},157 {"mask": "+31-76-###-####", "cc": "NL", "cd": "Netherlands", "city": "Breda"},158 {"mask": "+31-77-###-####", "cc": "NL", "cd": "Netherlands", "city": "Venlo"},159 {"mask": "+31-78-###-####", "cc": "NL", "cd": "Netherlands", "city": "Dordrecht"},160 {"mask": "+31-79-###-####", "cc": "NL", "cd": "Netherlands", "city": "Zoetermeer"},161 {"mask": "+31-61-###-####", "cc": "NL", "cd": "Netherlands", "city": "Mobiele nummers"},162 {"mask": "+31-62-###-####", "cc": "NL", "cd": "Netherlands", "city": "Mobiele nummers"},163 {"mask": "+31-63-###-####", "cc": "NL", "cd": "Netherlands", "city": "Mobiele nummers"},164 {"mask": "+31-64-###-####", "cc": "NL", "cd": "Netherlands", "city": "Mobiele nummers"},165 {"mask": "+31-65-###-####", "cc": "NL", "cd": "Netherlands", "city": "Mobiele nummers"},166 {"mask": "+31-68-###-####", "cc": "NL", "cd": "Netherlands", "city": "Mobiele nummers"},167 {"mask": "+31-69-###-####", "cc": "NL", "cd": "Netherlands", "city": "Mobiele nummers"},168 {"mask": "+31-66-###-####", "cc": "NL", "cd": "Netherlands", "city": "Semafonie"},169 {"mask": "+31-670-###-###", "cc": "NL", "cd": "Netherlands", "city": "Videotex"},170 {"mask": "+31-671-###-###", "cc": "NL", "cd": "Netherlands", "city": "Videotex"},171 {"mask": "+31-672-###-###", "cc": "NL", "cd": "Netherlands", "city": "Videotex"},172 {"mask": "+31-673-###-###", "cc": "NL", "cd": "Netherlands", "city": "Videotex"},173 {"mask": "+31-674-###-###", "cc": "NL", "cd": "Netherlands", "city": "Videotex"},174 {"mask": "+31-675-###-###", "cc": "NL", "cd": "Netherlands", "city": "Videotex"},175 {"mask": "+31-676-###-###", "cc": "NL", "cd": "Netherlands", "city": "Inbelnummers van internetproviders"},176 {"mask": "+31-800-###-###", "cc": "NL", "cd": "Netherlands", "city": "Gratis informatienummers"},177 {"mask": "+31-82-###-####", "cc": "NL", "cd": "Netherlands", "city": "Virtual Private Network"},178 {"mask": "+31-88-###-####", "cc": "NL", "cd": "Netherlands", "city": "Bedrijfsnummers"},179 {"mask": "+31-900-###-###", "cc": "NL", "cd": "Netherlands", "city": "Betaalde informatienummers"},180 {"mask": "+31-906-###-###", "cc": "NL", "cd": "Netherlands", "city": "Betaalde informatienummers"},181 {"mask": "+31-909-###-###", "cc": "NL", "cd": "Netherlands", "city": "Betaalde informatienummers"},182 {183 "mask": "+31-91-###-####",184 "cc": "NL",185 "cd": "Netherlands",186 "city": "Plaatsonafhankelijk netnummer, geschikt voor beeldtelefonie of lijnen met verhoogde kwaliteit"187 }...

Full Screen

Full Screen

metrics.py

Source:metrics.py Github

copy

Full Screen

1import cv22import numpy as np3from scipy.spatial.distance import directed_hausdorff4import matplotlib.pyplot as plt5from skimage.io import imread6import imageio7class IOUMetric:8 """9 Class to calculate mean-iou using fast_hist method10 """11 def __init__(self, num_classes):12 self.num_classes = num_classes13 self.hist = np.zeros((num_classes, num_classes))14 def _fast_hist(self, label_pred, label_true):15 mask = (label_true >= 0) & (label_true < self.num_classes)16 hist = np.bincount(17 self.num_classes * label_true[mask].astype(int) +18 label_pred[mask], minlength=self.num_classes ** 2).reshape(self.num_classes, self.num_classes)19 return hist20 def add_batch(self, predictions, gts):21 for lp, lt in zip(predictions, gts):22 self.hist += self._fast_hist(lp.flatten(), lt.flatten())23 def evaluate(self):24 acc = np.diag(self.hist).sum() / self.hist.sum()25 acc_cls = np.diag(self.hist) / self.hist.sum(axis=1)26 acc_cls = np.nanmean(acc_cls)27 iu = np.diag(self.hist) / (self.hist.sum(axis=1) + self.hist.sum(axis=0) - np.diag(self.hist))28 mean_iu = np.nanmean(iu)29 freq = self.hist.sum(axis=1) / self.hist.sum()30 fwavacc = (freq[freq > 0] * iu[freq > 0]).sum()31 return acc, acc_cls, iu, mean_iu, fwavacc32def get_iou(mask_name,predict):33 image_mask = cv2.imread(mask_name,0)34 if np.all(image_mask == None):35 image_mask = imageio.mimread(mask_name)36 image_mask = np.array(image_mask)[0]37 image_mask = cv2.resize(image_mask,(576,576))38 #image_mask = mask39 # print(image.shape)40 height = predict.shape[0]41 weight = predict.shape[1]42 # print(height*weight)43 o = 044 for row in range(height):45 for col in range(weight):46 if predict[row, col] < 0.5: #由于输出的predit是0~1范围的,其中值越靠近1越被网络认为是肝脏目标,所以取0.5为阈值47 predict[row, col] = 048 else:49 predict[row, col] = 150 if predict[row, col] == 0 or predict[row, col] == 1:51 o += 152 height_mask = image_mask.shape[0]53 weight_mask = image_mask.shape[1]54 for row in range(height_mask):55 for col in range(weight_mask):56 if image_mask[row, col] < 125: #由于mask图是黑白的灰度图,所以少于125的可以看作是黑色57 image_mask[row, col] = 058 else:59 image_mask[row, col] = 160 if image_mask[row, col] == 0 or image_mask[row, col] == 1:61 o += 162 predict = predict.astype(np.int16)63 interArea = np.multiply(predict, image_mask)64 tem = predict + image_mask65 unionArea = tem - interArea66 inter = np.sum(interArea)67 union = np.sum(unionArea)68 iou_tem = inter / union69 # Iou = IOUMetric(2) #2表示类别,肝脏类+背景类70 # Iou.add_batch(predict, image_mask)71 # a, b, c, d, e= Iou.evaluate()72 print('%s:iou=%f' % (mask_name,iou_tem))73 return iou_tem74def get_dice(mask_name,predict):75 image_mask = cv2.imread(mask_name, 0)76 if np.all(image_mask == None):77 image_mask = imageio.mimread(mask_name)78 image_mask = np.array(image_mask)[0]79 image_mask = cv2.resize(image_mask,(576,576))80 height = predict.shape[0]81 weight = predict.shape[1]82 o = 083 for row in range(height):84 for col in range(weight):85 if predict[row, col] < 0.5: # 由于输出的predit是0~1范围的,其中值越靠近1越被网络认为是肝脏目标,所以取0.5为阈值86 predict[row, col] = 087 else:88 predict[row, col] = 189 if predict[row, col] == 0 or predict[row, col] == 1:90 o += 191 height_mask = image_mask.shape[0]92 weight_mask = image_mask.shape[1]93 for row in range(height_mask):94 for col in range(weight_mask):95 if image_mask[row, col] < 125: # 由于mask图是黑白的灰度图,所以少于125的可以看作是黑色96 image_mask[row, col] = 097 else:98 image_mask[row, col] = 199 if image_mask[row, col] == 0 or image_mask[row, col] == 1:100 o += 1101 predict = predict.astype(np.int16)102 intersection = (predict*image_mask).sum()103 dice = (2. *intersection) /(predict.sum()+image_mask.sum())104 return dice105def get_hd(mask_name,predict):106 image_mask = cv2.imread(mask_name, 0)107 # print(mask_name)108 # print(image_mask)109 if np.all(image_mask == None):110 image_mask = imageio.mimread(mask_name)111 image_mask = np.array(image_mask)[0]112 image_mask = cv2.resize(image_mask,(576,576))113 #image_mask = mask114 height = predict.shape[0]115 weight = predict.shape[1]116 o = 0117 for row in range(height):118 for col in range(weight):119 if predict[row, col] < 0.5: # 由于输出的predit是0~1范围的,其中值越靠近1越被网络认为是肝脏目标,所以取0.5为阈值120 predict[row, col] = 0121 else:122 predict[row, col] = 1123 if predict[row, col] == 0 or predict[row, col] == 1:124 o += 1125 height_mask = image_mask.shape[0]126 weight_mask = image_mask.shape[1]127 for row in range(height_mask):128 for col in range(weight_mask):129 if image_mask[row, col] < 125: # 由于mask图是黑白的灰度图,所以少于125的可以看作是黑色130 image_mask[row, col] = 0131 else:132 image_mask[row, col] = 1133 if image_mask[row, col] == 0 or image_mask[row, col] == 1:134 o += 1135 hd1 = directed_hausdorff(image_mask, predict)[0]136 hd2 = directed_hausdorff(predict, image_mask)[0]137 res = None138 if hd1>hd2 or hd1 == hd2:139 res=hd1140 return res141 else:142 res=hd2143 return res144def show(predict):145 height = predict.shape[0]146 weight = predict.shape[1]147 for row in range(height):148 for col in range(weight):149 predict[row, col] *= 255150 plt.imshow(predict)...

Full Screen

Full Screen

docking-data.py

Source:docking-data.py Github

copy

Full Screen

...14 with fileinput.input(files=(filename)) as f:15 for line in f:16 instructions.append(line.strip())17 return instructions18def set_mask(s):19 global value_mask_020 global value_mask_121 global memory_mask_022 global memory_mask_123 global memory_mask_x24 value_mask_0 = 0xFFFFFFFFFF # Set 36 bits to 125 value_mask_1 = 026 memory_mask_0 = 0xFFFFFFFFFF # Set 36 bits to 127 memory_mask_1 = 0 28 memory_mask_x = 029 for i, c in enumerate(s[::-1]):30 if c == 'X':31 memory_mask_x |= (1 << i)32 pass33 elif c == '1':34 value_mask_1 |= (1 << i)35 memory_mask_1 |= (1 << i)36 elif c == '0':37 value_mask_0 &= ~(1 << i)38 memory_mask_0 &= ~(1 << i)39 #print(format(value_mask_0,'b'))40 #print(s, value_mask_0, value_mask_1)41 print("New memory mask x is ", format(memory_mask_x,'b'))42def apply_value_mask(value):43 global value_mask_044 global value_mask_145 #print("Value before mask ", value_mask_0, value_mask_1, value)46 value &= value_mask_0 # Overwrite 0s47 value |= value_mask_1 # Overwrite 1s48 return value49def apply_memory_mask(address):50 global memory_mask_051 global memory_mask_152 global memory_mask_x53 addresses = list()54 print("Mask x = ", format(memory_mask_x,'b'), "to address", address)55 address |= memory_mask_1 # Only mask 1 applies for part two. Overwrite 1s56 addresses.append(address)57 mask_x = 158 tmp = list()59 for i in range(36):60 if memory_mask_x & mask_x:61 print("Bit set")62 for a in addresses:63 tmp.append(a | mask_x)64 tmp.append(a & ~ mask_x)65 addresses = tmp.copy()66 mask_x = mask_x << 167 print (" addresses are ", addresses)68 #for address in addresses:69 #print(format(address,'b'), address)70 return addresses71def main():72 global mask73 global part_one_memory74 global part_two_memory75 instructions = read_input(sys.argv[1])76 for instr in instructions:77 print("Instruction is", instr)78 s = instr.split(" = ")79 if s[0] == "mask":80 # Set mask81 set_mask(s[1])82 elif s[0].startswith("mem"):83 value = int(s[1])84 # Part one85 mem_loc = int(s[0][4:s[0].index(']')])86 print("Memory location is ", mem_loc)87 masked_value = apply_value_mask(value)88 #print(value)89 part_one_memory[mem_loc] = masked_value90 # Part two91 addresses = apply_memory_mask(mem_loc)92 for address in addresses:93 part_two_memory[address] = value94 #print(part_one_memory)95 part_one_total = sum(part_one_memory.values())96 part_two_total = sum(part_two_memory.values())97 print("Part one total = ", part_one_total)98 print("Part two total = ", part_two_total)99if __name__ == '__main__':...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var page = require('webpage').create();2var system = require('system');3var fs = require('fs');4var url = system.args[1];5var mask = system.args[2];6var output = system.args[3];7page.viewportSize = { width: 1024, height: 768 };8page.open(url, function(status) {9 if (status !== 'success') {10 console.log('Unable to access network');11 } else {12 page.clipRect = {13 };14 page.mask(mask, function() {15 page.render(output);16 phantom.exit();17 });18 }19});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.runTest(url, function(err, data) {4 if (err) return console.error(err);5 var testId = data.data.testId;6 wpt.getTestResults(testId, function(err, data) {7 if (err) return console.error(err);8 console.log(data);9 });10});11var wpt = require('webpagetest');12var wpt = new WebPageTest('www.webpagetest.org');13wpt.runTest(url, function(err, data) {14 if (err) return console.error(err);15 var testId = data.data.testId;16 wpt.getTestResults(testId, function(err, data) {17 if (err) return console.error(err);18 console.log(data);19 });20});21var wpt = require('webpagetest');22var wpt = new WebPageTest('www.webpagetest.org');23wpt.runTest(url, function(err, data) {24 if (err) return console.error(err);25 var testId = data.data.testId;26 wpt.getTestResults(testId, function(err, data) {27 if (err) return console.error(err);28 console.log(data);29 });30});31var wpt = require('webpagetest');32var wpt = new WebPageTest('www.webpagetest.org');33wpt.runTest(url, function(err, data) {

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var wp = wptools();3var options = {4};5wp.setOptions(options);6wp.page('Albert Einstein').then(function(page) {7 return page.get();8}).then(function(page) {9 console.log(page.data);10});11var wptools = require('wptools');12var wp = wptools();13var options = {14};15wp.setOptions(options);16wp.page('Albert Einstein').then(function(page) {17 return page.get();18}).then(function(page) {19 console.log(page.data);20});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2wptools.page('Albert_Einstein').then(function(page) {3 return page.get(function(err, page) {4 console.log(page.imageinfo[0].url);5 });6});

Full Screen

Using AI Code Generation

copy

Full Screen

1var text = "The quick brown fox jumped over the lazy dog's back.";2var masked = wptexturize(text);3console.log(masked);4var text = "The quick brown fox jumped over the lazy dog&#8217;s back.";5var unmasked = wptexturize(text);6console.log(unmasked);7var text = "The quick brown fox jumped over the lazy dog's back.";8var masked = wptexturize(text);9console.log(masked);10var text = "The quick brown fox jumped over the lazy dog&#8217;s back.";11var unmasked = wptexturize(text);12console.log(unmasked);13var text = "The quick brown fox jumped over the lazy dog's back.";14var masked = wptexturize(text);15console.log(masked);16var text = "The quick brown fox jumped over the lazy dog&#8217;s back.";17var unmasked = wptexturize(text);18console.log(unmasked);19var text = "The quick brown fox jumped over the lazy dog's back.";20var masked = wptexturize(text);21console.log(masked);22var text = "The quick brown fox jumped over the lazy dog&#8217;s back.";23var unmasked = wptexturize(text);24console.log(unmasked);25var text = "The quick brown fox jumped over the lazy dog's back.";26var masked = wptexturize(text);27console.log(masked);28var text = "The quick brown fox jumped over the lazy dog&#8217;s back.";

Full Screen

Using AI Code Generation

copy

Full Screen

1$(document).ready(function(){2 $('#myinput').mask('0000-0000-0000-0000');3});4$(document).ready(function(){5 $('#myinput').mask('0000-0000-0000-0000');6});7$(document).ready(function(){8 $('#myinput').mask('0000-0000-0000-0000');9});10$(document).ready(function(){11 $('#myinput').mask('0000-0000-0000-0000');12});13$(document).ready(function(){14 $('#myinput').mask('0000-0000-0000-0000');15});

Full Screen

Using AI Code Generation

copy

Full Screen

1var text = "Hello World";2var text = wptexturize(text);3console.log(text);4var text = "Hello World";5var text = wptexturize.mask(text);6console.log(text);7var text = "Hello World";8var text = wptexturize.mask(text, true);9console.log(text);10var text = "Hello World";11var text = wptexturize.mask(text, false);12console.log(text);13var text = "Hello World";14var text = wptexturize.mask(text, true, true);15console.log(text);16var text = "Hello World";17var text = wptexturize.mask(text, true, false);18console.log(text);19var text = "Hello World";20var text = wptexturize.mask(text, false, true);21console.log(text);22var text = "Hello World";23var text = wptexturize.mask(text, false, false);24console.log(text);25var text = "Hello World";26var text = wptexturize.unmask(text);27console.log(text);28var text = "Hello World";29var text = wptexturize.unmask(text, true);30console.log(text);31var text = "Hello World";32var text = wptexturize.unmask(text, false);33console.log(text);34var text = "Hello World";35var text = wptexturize.unmask(text, true, true);36console.log(text);37var text = "Hello World";38var text = wptexturize.unmask(text, true, false);39console.log(text);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var wp = wptools.page('Narendra Modi');3wp.get(function(err,resp){4 console.log(resp);5});6{ title: 'Narendra Modi',7 { name: 'Narendra Modi',

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