Class CheckerTree<T>
- Type Parameters:
T
- the type of elements stored in the tree
- All Implemented Interfaces:
InterfaceChecker<AbstractChecker<Tree<T>,
CheckerTree<T>>, Tree<T>>
A specialized checker for
Tree
data structures, providing a fluent API to assert various properties
and invariants about a tree. This class extends AbstractChecker
and allows for custom or default
naming of the checker instance.
CheckerTree provides static factory methods for convenient construction from a Tree
instance,
a root value, or a root value with a map of children. It supports checks for emptiness, binary structure,
symmetry, fullness, depth, number of leaves, and diameter, among others.
Usage Example:
Tree<Integer> tree = new Tree<>(1);
CheckerTree<Integer> checker = CheckerTree.check(tree);
checker.isBinaryTree().minDepth(1);
- See Also:
-
Field Summary
Fields inherited from class util.AbstractChecker
backObject, exceptionTracker, name, object, saveErrors, stop
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
CheckerTree
(Tree<T> tree, String name) Constructs a newCheckerTree
with the specified tree and name. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> CheckerTree
<T> check
(T rootValue) Creates a CheckerTree from a root value with a default name.static <T> CheckerTree
<T> Creates a CheckerTree from a root value and assigns a custom name.static <T> CheckerTree
<T> Creates a CheckerTree from a root value and a map of children, with a default name.static <T> CheckerTree
<T> Creates a CheckerTree from a root value and a map of children, and assigns a custom name.static <T> CheckerTree
<T> Creates a CheckerTree for the given tree with a default name.static <T> CheckerTree
<T> Creates a CheckerTree for the given tree and assigns a custom name.inRangeDepth
(int min, int max) Checks if the tree's depth is within the specified range (inclusive).inRangeDiamenter
(int min, int max) Checks if the tree's diameter is within the specified range (inclusive).inRangeLeaves
(int min, int max) Checks if the number of leaves in the tree is within the specified range (inclusive).Checks if the tree is a binary tree (each node has at most two children).isEmpty()
Checks if the tree is empty.isFull()
Checks if the tree is full (every node has 0 or 2 children).Checks if the tree is symmetric (mirror image around its center).maxDepth
(int max) Checks if the tree's depth is at most the specified maximum.maxDiamenter
(int max) Checks if the tree's diameter is at most the specified maximum.maxLeaves
(int max) Checks if the number of leaves in the tree is at most the specified maximum.minDepth
(int min) Checks if the tree's depth is at least the specified minimum.minDiamenter
(int min) Checks if the tree's diameter is at least the specified minimum.minLeaves
(int min) Checks if the number of leaves in the tree is at least the specified minimum.protected CheckerTree
<T> self()
Returns this instance (for fluent API).Methods inherited from class util.AbstractChecker
checkProperty, checkProperty, checkProperty, end, getMethod, getObject, getProperty, hasErrors, hasNotErrors, is, is, isEqual, isNonNull, isNot, isNot, isNull, notSaveErrors, saveErrors, show, showNotThrownException, showThrownException, stop
-
Constructor Details
-
CheckerTree
-
-
Method Details
-
check
Creates a CheckerTree for the given tree and assigns a custom name.- Type Parameters:
T
- theTree
's element type- Parameters:
tree
- the tree to checkname
- the name to assign to this checker- Returns:
- a CheckerTree instance for the given tree
-
check
Creates a CheckerTree from a root value and a map of children, and assigns a custom name.- Type Parameters:
T
- theTree
's element type- Parameters:
rootValue
- the value of the root nodechildrenMap
- a map where each key is a node and the value is a list of its childrenname
- the name to assign to this checker- Returns:
- a CheckerTree instance for the constructed tree
-
check
Creates a CheckerTree from a root value and assigns a custom name.- Type Parameters:
T
- theTree
's element type- Parameters:
rootValue
- the value of the root nodename
- the name to assign to this checker- Returns:
- a CheckerTree instance for the constructed tree
-
check
Creates a CheckerTree for the given tree with a default name.- Type Parameters:
T
- theTree
's element type- Parameters:
tree
- the tree to check- Returns:
- a CheckerTree instance for the given tree
-
check
Creates a CheckerTree from a root value and a map of children, with a default name.- Type Parameters:
T
- theTree
's element type- Parameters:
rootValue
- the value of the root nodechildrenMap
- a map where each key is a node and the value is a list of its children- Returns:
- a CheckerTree instance for the constructed tree
-
check
Creates a CheckerTree from a root value with a default name.- Type Parameters:
T
- theTree
's element type- Parameters:
rootValue
- the value of the root node- Returns:
- a CheckerTree instance for the constructed tree
-
self
Returns this instance (for fluent API).- Specified by:
self
in classAbstractChecker<Tree<T>,
CheckerTree<T>> - Returns:
- this CheckerTree instance
-
isEmpty
-
isBinaryTree
Checks if the tree is a binary tree (each node has at most two children).- Returns:
- this CheckerTree instance
-
isSymmetric
Checks if the tree is symmetric (mirror image around its center).- Returns:
- this CheckerTree instance
-
isFull
Checks if the tree is full (every node has 0 or 2 children).- Returns:
- this CheckerTree instance
-
minDepth
Checks if the tree's depth is at least the specified minimum.- Parameters:
min
- the minimum depth- Returns:
- this CheckerTree instance
-
maxDepth
Checks if the tree's depth is at most the specified maximum.- Parameters:
max
- the maximum depth- Returns:
- this CheckerTree instance
-
inRangeDepth
Checks if the tree's depth is within the specified range (inclusive).- Parameters:
min
- the minimum depthmax
- the maximum depth- Returns:
- this CheckerTree instance
-
minLeaves
Checks if the number of leaves in the tree is at least the specified minimum.- Parameters:
min
- the minimum number of leaves- Returns:
- this CheckerTree instance
-
maxLeaves
Checks if the number of leaves in the tree is at most the specified maximum.- Parameters:
max
- the maximum number of leaves- Returns:
- this CheckerTree instance
-
inRangeLeaves
Checks if the number of leaves in the tree is within the specified range (inclusive).- Parameters:
min
- the minimum number of leavesmax
- the maximum number of leaves- Returns:
- this CheckerTree instance
-
minDiamenter
Checks if the tree's diameter is at least the specified minimum.- Parameters:
min
- the minimum diameter- Returns:
- this CheckerTree instance
-
maxDiamenter
Checks if the tree's diameter is at most the specified maximum.- Parameters:
max
- the maximum diameter- Returns:
- this CheckerTree instance
-
inRangeDiamenter
Checks if the tree's diameter is within the specified range (inclusive).- Parameters:
min
- the minimum diametermax
- the maximum diameter- Returns:
- this CheckerTree instance
-