Skip to content

Commit bae00e4

Browse files
style: Apply clang-format to match repository style guide
- Format code according to .clang-format configuration - Use single-line lambdas as allowed by AllowShortLambdasOnASingleLine: All - Apply 4-space indentation - Ensure proper line endings
1 parent 1ad5545 commit bae00e4

File tree

2 files changed

+12
-28
lines changed

2 files changed

+12
-28
lines changed

src/main/java/com/thealgorithms/datastructures/trees/CentroidDecomposition.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ private CentroidDecomposition() {
3131
/**
3232
* Represents the centroid tree structure.
3333
*/
34-
public static class CentroidTree {
34+
public static final class CentroidTree {
3535
private final int n;
3636
private final List<List<Integer>> adj;
3737
private final int[] parent;
@@ -104,7 +104,7 @@ private int getSubtreeSize(int u, int p) {
104104

105105
/**
106106
* Finds the centroid of a subtree.
107-
* A centroid is a node whose removal creates components with size totalSize/2.
107+
* A centroid is a node whose removal creates components with size &lt;= totalSize/2.
108108
*
109109
* @param u current node
110110
* @param p parent node
@@ -153,7 +153,7 @@ public int size() {
153153

154154
/**
155155
* Returns the centroid tree structure as a string.
156-
* Format: node -> parent (or ROOT for root node)
156+
* Format: node -&gt; parent (or ROOT for root node)
157157
*
158158
* @return string representation
159159
*/
@@ -179,7 +179,7 @@ public String toString() {
179179
* @param n number of nodes (0-indexed: 0 to n-1)
180180
* @param edges list of edges where each edge is [u, v]
181181
* @return CentroidTree object
182-
* @throws IllegalArgumentException if n <= 0 or edges is invalid
182+
* @throws IllegalArgumentException if n &lt;= 0 or edges is invalid
183183
*/
184184
public static CentroidTree buildFromEdges(int n, int[][] edges) {
185185
if (n <= 0) {

src/test/java/com/thealgorithms/datastructures/trees/CentroidDecompositionTest.java

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -154,62 +154,46 @@ void testPathGraph() {
154154

155155
@Test
156156
void testInvalidEmptyTree() {
157-
assertThrows(IllegalArgumentException.class, () -> {
158-
CentroidDecomposition.buildFromEdges(0, new int[][] {});
159-
});
157+
assertThrows(IllegalArgumentException.class, () -> { CentroidDecomposition.buildFromEdges(0, new int[][] {}); });
160158
}
161159

162160
@Test
163161
void testInvalidNegativeNodes() {
164-
assertThrows(IllegalArgumentException.class, () -> {
165-
CentroidDecomposition.buildFromEdges(-1, new int[][] {});
166-
});
162+
assertThrows(IllegalArgumentException.class, () -> { CentroidDecomposition.buildFromEdges(-1, new int[][] {}); });
167163
}
168164

169165
@Test
170166
void testInvalidNullEdges() {
171-
assertThrows(IllegalArgumentException.class, () -> {
172-
CentroidDecomposition.buildFromEdges(5, null);
173-
});
167+
assertThrows(IllegalArgumentException.class, () -> { CentroidDecomposition.buildFromEdges(5, null); });
174168
}
175169

176170
@Test
177171
void testInvalidEdgeCount() {
178172
// Tree with n nodes must have n-1 edges
179173
int[][] edges = {{0, 1}, {1, 2}}; // 2 edges for 5 nodes (should be 4)
180-
assertThrows(IllegalArgumentException.class, () -> {
181-
CentroidDecomposition.buildFromEdges(5, edges);
182-
});
174+
assertThrows(IllegalArgumentException.class, () -> { CentroidDecomposition.buildFromEdges(5, edges); });
183175
}
184176

185177
@Test
186178
void testInvalidEdgeFormat() {
187179
int[][] edges = {{0, 1, 2}}; // Edge with 3 elements instead of 2
188-
assertThrows(IllegalArgumentException.class, () -> {
189-
CentroidDecomposition.buildFromEdges(3, edges);
190-
});
180+
assertThrows(IllegalArgumentException.class, () -> { CentroidDecomposition.buildFromEdges(3, edges); });
191181
}
192182

193183
@Test
194184
void testInvalidNodeInEdge() {
195185
int[][] edges = {{0, 5}}; // Node 5 doesn't exist in tree of size 3
196-
assertThrows(IllegalArgumentException.class, () -> {
197-
CentroidDecomposition.buildFromEdges(3, edges);
198-
});
186+
assertThrows(IllegalArgumentException.class, () -> { CentroidDecomposition.buildFromEdges(3, edges); });
199187
}
200188

201189
@Test
202190
void testInvalidNodeQuery() {
203191
int[][] edges = {{0, 1}, {1, 2}};
204192
CentroidDecomposition.CentroidTree tree = CentroidDecomposition.buildFromEdges(3, edges);
205193

206-
assertThrows(IllegalArgumentException.class, () -> {
207-
tree.getParent(-1);
208-
});
194+
assertThrows(IllegalArgumentException.class, () -> { tree.getParent(-1); });
209195

210-
assertThrows(IllegalArgumentException.class, () -> {
211-
tree.getParent(5);
212-
});
196+
assertThrows(IllegalArgumentException.class, () -> { tree.getParent(5); });
213197
}
214198

215199
@Test

0 commit comments

Comments
 (0)