From d863cb62af53934f097895934a002ada9c30fe45 Mon Sep 17 00:00:00 2001 From: alxkm Date: Wed, 16 Jul 2025 21:37:44 +0200 Subject: [PATCH] testing: improving test coverage CountingInversionsTest --- .../CountingInversionsTest.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/test/java/com/thealgorithms/divideandconquer/CountingInversionsTest.java b/src/test/java/com/thealgorithms/divideandconquer/CountingInversionsTest.java index d12614d6fd06..f8356a87eb31 100644 --- a/src/test/java/com/thealgorithms/divideandconquer/CountingInversionsTest.java +++ b/src/test/java/com/thealgorithms/divideandconquer/CountingInversionsTest.java @@ -29,4 +29,35 @@ public void testAllInversions() { int[] arr = {5, 4, 3, 2, 1}; assertEquals(10, CountingInversions.countInversions(arr)); } + + @Test + public void testEmptyArray() { + int[] arr = {}; + assertEquals(0, CountingInversions.countInversions(arr)); + } + + @Test + public void testArrayWithDuplicates() { + int[] arr = {1, 3, 2, 3, 1}; + // Inversions: (3,2), (3,1), (3,1), (2,1) + assertEquals(4, CountingInversions.countInversions(arr)); + } + + @Test + public void testLargeArray() { + int n = 1000; + int[] arr = new int[n]; + for (int i = 0; i < n; i++) { + arr[i] = n - i; // descending order -> max inversions = n*(n-1)/2 + } + int expected = n * (n - 1) / 2; + assertEquals(expected, CountingInversions.countInversions(arr)); + } + + @Test + public void testArrayWithAllSameElements() { + int[] arr = {7, 7, 7, 7}; + // No inversions since all elements are equal + assertEquals(0, CountingInversions.countInversions(arr)); + } } 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