| 219 | |
| 220 | |
| 221 | def test_node_init_and_setattr_error_cases() -> None: |
| 222 | root, left_child, right_child = Node(1), Node(2), Node(3) |
| 223 | root.left = left_child |
| 224 | root.right = right_child |
| 225 | |
| 226 | with pytest.raises(NodeValueError) as err1: |
| 227 | Node(EMPTY_LIST) |
| 228 | assert str(err1.value) == "node value must be a float/int/str" |
| 229 | |
| 230 | with pytest.raises(NodeValueError) as err2: |
| 231 | Node(1).val = EMPTY_LIST |
| 232 | assert str(err2.value) == "node value must be a float/int/str" |
| 233 | |
| 234 | with pytest.raises(NodeTypeError) as err3: |
| 235 | Node(1, "this_is_not_a_node") # type: ignore |
| 236 | assert str(err3.value) == "left child must be a Node instance" |
| 237 | |
| 238 | with pytest.raises(NodeTypeError) as err4: |
| 239 | Node(1, Node(1), "this_is_not_a_node") # type: ignore |
| 240 | assert str(err4.value) == "right child must be a Node instance" |
| 241 | |
| 242 | with pytest.raises(NodeTypeError) as err5: |
| 243 | root.left = "this_is_not_a_node" # type: ignore |
| 244 | assert root.left is left_child |
| 245 | assert str(err5.value) == "left child must be a Node instance" |
| 246 | |
| 247 | with pytest.raises(NodeTypeError) as err6: |
| 248 | root.right = "this_is_not_a_node" # type: ignore |
| 249 | assert root.right is right_child |
| 250 | assert str(err6.value) == "right child must be a Node instance" |
| 251 | |
| 252 | |
| 253 | def test_tree_equals_with_integers() -> None: |