1- """
2- psf/black : true
3- ruff : passed
4- """
5-
61from __future__ import annotations
72
83from collections .abc import Iterator
@@ -321,9 +316,7 @@ def check_coloring(self) -> bool:
321316 return False
322317 if self .left and not self .left .check_coloring ():
323318 return False
324- if self .right and not self .right .check_coloring ():
325- return False
326- return True
319+ return not (self .right and not self .right .check_coloring ())
327320
328321 def black_height (self ) -> int | None :
329322 """Returns the number of black nodes from this node to the
@@ -561,9 +554,7 @@ def test_rotations() -> bool:
561554 right_rot .right .right = RedBlackTree (10 , parent = right_rot .right )
562555 right_rot .right .right .left = RedBlackTree (5 , parent = right_rot .right .right )
563556 right_rot .right .right .right = RedBlackTree (20 , parent = right_rot .right .right )
564- if tree != right_rot :
565- return False
566- return True
557+ return tree == right_rot
567558
568559
569560def test_insertion_speed () -> bool :
@@ -606,13 +597,11 @@ def test_insert_and_search() -> bool:
606597 tree .insert (12 )
607598 tree .insert (10 )
608599 tree .insert (11 )
609- if 5 in tree or - 6 in tree or - 10 in tree or 13 in tree :
600+ if any ( i in tree for i in ( 5 , - 6 , - 10 , 13 )) :
610601 # Found something not in there
611602 return False
612- if not (11 in tree and 12 in tree and - 8 in tree and 0 in tree ):
613- # Didn't find something in there
614- return False
615- return True
603+ # Find all these things in there
604+ return all (i in tree for i in (11 , 12 , - 8 , 0 ))
616605
617606
618607def test_insert_delete () -> bool :
@@ -634,9 +623,7 @@ def test_insert_delete() -> bool:
634623 tree = tree .remove (9 )
635624 if not tree .check_color_properties ():
636625 return False
637- if list (tree .inorder_traverse ()) != [- 8 , 0 , 4 , 8 , 10 , 11 , 12 ]:
638- return False
639- return True
626+ return list (tree .inorder_traverse ()) == [- 8 , 0 , 4 , 8 , 10 , 11 , 12 ]
640627
641628
642629def test_floor_ceil () -> bool :
@@ -664,9 +651,7 @@ def test_min_max() -> bool:
664651 tree .insert (24 )
665652 tree .insert (20 )
666653 tree .insert (22 )
667- if tree .get_max () != 22 or tree .get_min () != - 16 :
668- return False
669- return True
654+ return not (tree .get_max () != 22 or tree .get_min () != - 16 )
670655
671656
672657def test_tree_traversal () -> bool :
@@ -682,9 +667,7 @@ def test_tree_traversal() -> bool:
682667 return False
683668 if list (tree .preorder_traverse ()) != [0 , - 16 , 16 , 8 , 22 , 20 , 24 ]:
684669 return False
685- if list (tree .postorder_traverse ()) != [- 16 , 8 , 20 , 24 , 22 , 16 , 0 ]:
686- return False
687- return True
670+ return list (tree .postorder_traverse ()) == [- 16 , 8 , 20 , 24 , 22 , 16 , 0 ]
688671
689672
690673def test_tree_chaining () -> bool :
@@ -695,9 +678,7 @@ def test_tree_chaining() -> bool:
695678 return False
696679 if list (tree .preorder_traverse ()) != [0 , - 16 , 16 , 8 , 22 , 20 , 24 ]:
697680 return False
698- if list (tree .postorder_traverse ()) != [- 16 , 8 , 20 , 24 , 22 , 16 , 0 ]:
699- return False
700- return True
681+ return list (tree .postorder_traverse ()) == [- 16 , 8 , 20 , 24 , 22 , 16 , 0 ]
701682
702683
703684def print_results (msg : str , passes : bool ) -> None :
0 commit comments