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

Function test_tree_generation

tests/test_tree.py:1225–1259  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1223
1224
1225def test_tree_generation() -> None:
1226 for invalid_height in ["foo", -1, None]:
1227 with pytest.raises(TreeHeightError) as err:
1228 tree(height=invalid_height) # type: ignore
1229 assert str(err.value) == "height must be an int between 0 - 9"
1230
1231 root = tree(height=0)
1232 assert root is not None
1233
1234 root.validate()
1235 assert root.height == 0
1236 assert root.left is None
1237 assert root.right is None
1238 assert isinstance(root.val, int)
1239
1240 for _ in range(REPETITIONS):
1241 random_height = random.randint(1, 9)
1242
1243 root = tree(random_height)
1244 assert root is not None
1245
1246 root.validate()
1247 assert root.height == random_height
1248
1249 for _ in range(REPETITIONS):
1250 random_height = random.randint(1, 9)
1251
1252 root = tree(random_height, is_perfect=True)
1253 assert root is not None
1254
1255 root.validate()
1256 assert root.height == random_height
1257 assert root.is_perfect is True
1258 assert root.is_balanced is True
1259 assert root.is_strict is True
1260
1261
1262def test_bst_generation() -> None:

Callers

nothing calls this directly

Calls 2

treeFunction · 0.90
validateMethod · 0.80

Tested by

no test coverage detected