Skip to content

Commit 4df8542

Browse files
committed
Format Update
1 parent c7bc224 commit 4df8542

File tree

1 file changed

+6
-27
lines changed

1 file changed

+6
-27
lines changed

src/test/java/com/thealgorithms/tree/HeavyLightDecompositionTest.java

+6-27
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,14 @@
11
package com.thealgorithms.tree;
22

3-
/**
4-
* Testcases for Heavy-Light Decomposition (HLD) implementation in Java.
5-
*
6-
* The test cases check tree initialization, path maximum queries, node value updates,
7-
* and skewed tree handling to ensure correct functionality. They verify edge addition,
8-
* segment tree updates, and path-based max queries for correctness.
9-
*
10-
* Author: Nithin U.
11-
* Github: https://github.com/NithinU2802
12-
*
13-
*/
14-
153
import org.junit.jupiter.api.BeforeEach;
164
import org.junit.jupiter.api.Test;
17-
import static org.junit.jupiter.api.Assertions.*;
5+
import static org.junit.jupiter.api.Assertions.assertEquals;
6+
import static org.junit.jupiter.api.Assertions.assertTrue;
187

198
public class HeavyLightDecompositionTest {
209

2110
private HeavyLightDecomposition hld;
22-
private int[] values;
11+
private int[] values = new int[]{0, 10, 20, 30, 40, 50}; ;
2312

2413
/**
2514
* Initializes the test environment with a predefined tree structure and values.
@@ -31,9 +20,6 @@ void setUp() {
3120
hld.addEdge(1, 3);
3221
hld.addEdge(2, 4);
3322
hld.addEdge(2, 5);
34-
35-
// Single array initialization for all test cases
36-
values = new int[]{0, 10, 20, 30, 40, 50};
3723
hld.initialize(1, values);
3824
}
3925

@@ -69,18 +55,11 @@ void testUpdateNodeValue() {
6955

7056
/**
7157
* Tests a skewed tree structure to ensure max path queries work correctly.
72-
* Expected: The max value in the path (1,4) should be 35.
58+
* Expected: The max value in the path (1,4) should be 40.
7359
*/
7460
@Test
75-
void testSkewedTreeMaxQuery() {
76-
hld = new HeavyLightDecomposition(4);
77-
hld.addEdge(1, 2);
78-
hld.addEdge(2, 3);
79-
hld.addEdge(3, 4);
80-
values = new int[]{0, 5, 15, 25, 35}; // Adjusted values for the skewed tree
81-
hld.initialize(1, values);
82-
83-
assertEquals(35, hld.queryMaxInPath(1, 4), "Max value in skewed tree should be 35");
61+
void testSkewedTreeMaxQuery() {
62+
assertEquals(40, hld.queryMaxInPath(1, 4), "Max value in skewed tree should be 40");
8463
}
8564

8665
/**

0 commit comments

Comments
 (0)