Skip to content

Commit fc477ee

Browse files
testing: improving test coverage CountingInversionsTest (TheAlgorithms#6393)
testing: improving test coverage CountingInversionsTest Co-authored-by: Deniz Altunkapan <93663085+DenizAltunkapan@users.noreply.github.com>
1 parent 44c572b commit fc477ee

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/test/java/com/thealgorithms/divideandconquer/CountingInversionsTest.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,35 @@ public void testAllInversions() {
2929
int[] arr = {5, 4, 3, 2, 1};
3030
assertEquals(10, CountingInversions.countInversions(arr));
3131
}
32+
33+
@Test
34+
public void testEmptyArray() {
35+
int[] arr = {};
36+
assertEquals(0, CountingInversions.countInversions(arr));
37+
}
38+
39+
@Test
40+
public void testArrayWithDuplicates() {
41+
int[] arr = {1, 3, 2, 3, 1};
42+
// Inversions: (3,2), (3,1), (3,1), (2,1)
43+
assertEquals(4, CountingInversions.countInversions(arr));
44+
}
45+
46+
@Test
47+
public void testLargeArray() {
48+
int n = 1000;
49+
int[] arr = new int[n];
50+
for (int i = 0; i < n; i++) {
51+
arr[i] = n - i; // descending order -> max inversions = n*(n-1)/2
52+
}
53+
int expected = n * (n - 1) / 2;
54+
assertEquals(expected, CountingInversions.countInversions(arr));
55+
}
56+
57+
@Test
58+
public void testArrayWithAllSameElements() {
59+
int[] arr = {7, 7, 7, 7};
60+
// No inversions since all elements are equal
61+
assertEquals(0, CountingInversions.countInversions(arr));
62+
}
3263
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy