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

Function test_list_representation_1

tests/test_tree.py:377–457  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

375
376
377def test_list_representation_1() -> None:
378 root = build(EMPTY_LIST)
379 assert root is None
380
381 root = build([1])
382 assert root is not None
383 assert root.val == 1
384 assert root.left is None
385 assert root.right is None
386
387 root = build([1, 2])
388 assert root is not None
389 assert root.val == 1
390 assert root.left is not None
391 assert root.left.val == 2
392 assert root.right is None
393
394 root = build([1, 2, 3])
395 assert root is not None
396 assert root.val == 1
397 assert root.left is not None
398 assert root.left.val == 2
399 assert root.right is not None
400 assert root.right.val == 3
401 assert root.left.left is None
402 assert root.left.right is None
403 assert root.right.left is None
404 assert root.right.right is None
405
406 root = build([1, 2, 3, None, 4])
407 assert root is not None
408 assert root.val == 1
409 assert root.left is not None
410 assert root.left.val == 2
411 assert root.right is not None
412 assert root.right.val == 3
413 assert root.left.left is None
414 assert root.left.right is not None
415 assert root.left.right.val == 4
416 assert root.right.left is None
417 assert root.right.right is None
418 assert root.left.right.left is None
419 assert root.left.right.right is None
420
421 with pytest.raises(NodeNotFoundError) as err:
422 build([None, 1, 2])
423 assert str(err.value) == "parent node missing at index 0"
424
425 with pytest.raises(NodeNotFoundError) as err:
426 build([1, None, 2, 3, 4])
427 assert str(err.value) == "parent node missing at index 1"
428
429 root = Node(1)
430 assert root.values == [1]
431
432 root.right = Node(3)
433 assert root.values == [1, None, 3]
434

Callers

nothing calls this directly

Calls 3

buildFunction · 0.90
NodeClass · 0.90
treeFunction · 0.90

Tested by

no test coverage detected