MCPcopy
hub / github.com/joowani/binarytree / test_heap_generation

Function test_heap_generation

tests/test_tree.py:1323–1395  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1321
1322
1323def test_heap_generation() -> None:
1324 for invalid_height in ["foo", -1, None]:
1325 with pytest.raises(TreeHeightError) as err:
1326 heap(height=invalid_height) # type: ignore
1327 assert str(err.value) == "height must be an int between 0 - 9"
1328
1329 root = heap(height=0)
1330 assert root is not None
1331 root.validate()
1332 assert root.height == 0
1333 assert root.left is None
1334 assert root.right is None
1335 assert isinstance(root.val, int)
1336
1337 for _ in range(REPETITIONS):
1338 random_height = random.randint(1, 9)
1339 root = heap(random_height, is_max=True)
1340 assert root is not None
1341 root.validate()
1342 assert root.is_max_heap is True
1343 assert root.is_min_heap is False
1344 assert root.height == random_height
1345
1346 for _ in range(REPETITIONS):
1347 random_height = random.randint(1, 9)
1348 root = heap(random_height, letters=True, is_max=True)
1349 assert root is not None
1350 root.validate()
1351 assert root.is_max_heap is True
1352 assert root.is_min_heap is False
1353 assert root.height == random_height
1354
1355 for _ in range(REPETITIONS):
1356 random_height = random.randint(1, 9)
1357 root = heap(random_height, is_max=False)
1358 assert root is not None
1359 root.validate()
1360 assert root.is_max_heap is False
1361 assert root.is_min_heap is True
1362 assert root.height == random_height
1363
1364 for _ in range(REPETITIONS):
1365 random_height = random.randint(1, 9)
1366 root = heap(random_height, letters=True, is_max=False)
1367 assert root is not None
1368 root.validate()
1369 assert root.is_max_heap is False
1370 assert root.is_min_heap is True
1371 assert root.height == random_height
1372
1373 for _ in range(REPETITIONS):
1374 random_height = random.randint(1, 9)
1375 root = heap(random_height, is_perfect=True)
1376 assert root is not None
1377 root.validate()
1378 assert root.is_max_heap is True
1379 assert root.is_min_heap is False
1380 assert root.is_perfect is True

Callers

nothing calls this directly

Calls 2

heapFunction · 0.90
validateMethod · 0.80

Tested by

no test coverage detected