@@ -10,38 +10,23 @@ public class LowestSetBitTest {
10
10
@ Test
11
11
public void testIsolateLowestSetBit () {
12
12
// Test with regular positive numbers
13
- assertEquals (1 , lowestSetBit .isolateLowestSetBit (5 )); // 5 in binary is 101, the lowest set bit is 1
14
- assertEquals (2 , lowestSetBit .isolateLowestSetBit (6 )); // 6 in binary is 110, the lowest set bit is 2
15
- assertEquals (4 , lowestSetBit .isolateLowestSetBit (12 )); // 12 in binary is 1100, the lowest set bit is 4
13
+ assertEquals (1 , lowestSetBit .isolateLowestSetBit (5 ));
14
+ assertEquals (2 , lowestSetBit .isolateLowestSetBit (6 ));
15
+ assertEquals (4 , lowestSetBit .isolateLowestSetBit (12 ));
16
16
17
17
// Test with powers of two
18
- assertEquals (1 , lowestSetBit .isolateLowestSetBit (1 )); // 1 in binary is 1, the lowest set bit is 1
19
- assertEquals (2 , lowestSetBit .isolateLowestSetBit (2 )); // 2 in binary is 10, the lowest set bit is 2
20
- assertEquals (4 , lowestSetBit .isolateLowestSetBit (4 )); // 4 in binary is 100, the lowest set bit is 4
18
+ assertEquals (1 , lowestSetBit .isolateLowestSetBit (1 ));
19
+ assertEquals (2 , lowestSetBit .isolateLowestSetBit (2 ));
20
+ assertEquals (4 , lowestSetBit .isolateLowestSetBit (4 ));
21
21
22
22
// Test with negative numbers
23
- assertEquals (1 , lowestSetBit .isolateLowestSetBit (-5 )); // -5 in binary (two's complement) still has 1 as the lowest set bit
24
- assertEquals (2 , lowestSetBit .isolateLowestSetBit (-6 )); // -6 in binary has 2 as the lowest set bit
23
+ assertEquals (1 , lowestSetBit .isolateLowestSetBit (-5 ));
24
+ assertEquals (2 , lowestSetBit .isolateLowestSetBit (-6 ));
25
25
26
26
// Test with zero
27
- assertEquals (0 , lowestSetBit .isolateLowestSetBit (0 )); // Edge case: 0 should return 0
27
+ assertEquals (0 , lowestSetBit .isolateLowestSetBit (0 ));
28
28
29
29
// Test with number having all bits set
30
- assertEquals (1 , lowestSetBit .isolateLowestSetBit (-1 )); // -1 in two's complement has all bits set, lowest set bit is 1
31
- }
32
-
33
- @ Test
34
- public void testClearLowestSetBit () {
35
- // Test with positive numbers
36
- assertEquals (4 , lowestSetBit .clearLowestSetBit (5 )); // 5 in binary is 101, clearing lowest set bit gives 100 (which is 4)
37
- assertEquals (4 , lowestSetBit .clearLowestSetBit (6 )); // 6 in binary is 110, clearing lowest set bit gives 100 (which is 4)
38
- assertEquals (8 , lowestSetBit .clearLowestSetBit (12 )); // 12 in binary is 1100, clearing lowest set bit gives 1000 (which is 8)
39
-
40
- // Test with negative numbers
41
- assertEquals (-6 , lowestSetBit .clearLowestSetBit (-5 )); // -5 in binary, clearing lowest set bit should give -6
42
- assertEquals (-8 , lowestSetBit .clearLowestSetBit (-6 )); // -6 in binary, clearing lowest set bit should give -8
43
-
44
- // Test with zero
45
- assertEquals (0 , lowestSetBit .clearLowestSetBit (0 )); // Edge case: 0 should return 0
30
+ assertEquals (1 , lowestSetBit .isolateLowestSetBit (-1 ));
46
31
}
47
32
}
0 commit comments