[FEATURE] #200

Open
opened 2026-01-29 15:08:40 +00:00 by claunia · 0 comments
Owner

Originally created by @Ujwal200707 on GitHub (Nov 2, 2025).

Detailed description

in your bubble sort.c
Your test() function generates random numbers. If an assertion fails, it’s hard to debug because the array changes every run.

Context

The test function generates a new random array each time it runs, so if a bug occurs, the failing input changes on every run. This makes debugging and reproducing failures difficult because the array is nondeterministic.

Possible implementation

Solution:

Add a deterministic test array with known numbers.

Optionally, print the array before and after sorting to debug.

int test_arr[] = {5, 1, 4, 2, 8};
bubbleSort(test_arr, 5);
for (int i = 0; i < 4; i++)
assert(test_arr[i] <= test_arr[i + 1]);

Additional information

Relying solely on random data can hide edge cases, such as already sorted arrays, reverse-sorted arrays, or arrays with duplicate values, which may not be generated by rand().

Random tests do not guarantee full coverage of possible scenarios that could break the algorithm.

Without printing the array, it’s impossible to know what input caused a failure, making debugging harder.

Using a deterministic array alongside random tests ensures reproducibility and better verification of the sorting logic.

Originally created by @Ujwal200707 on GitHub (Nov 2, 2025). ### Detailed description in your bubble sort.c Your test() function generates random numbers. If an assertion fails, it’s hard to debug because the array changes every run. ### Context The test function generates a new random array each time it runs, so if a bug occurs, the failing input changes on every run. This makes debugging and reproducing failures difficult because the array is nondeterministic. ### Possible implementation Solution: Add a deterministic test array with known numbers. Optionally, print the array before and after sorting to debug. int test_arr[] = {5, 1, 4, 2, 8}; bubbleSort(test_arr, 5); for (int i = 0; i < 4; i++) assert(test_arr[i] <= test_arr[i + 1]); ### Additional information Relying solely on random data can hide edge cases, such as already sorted arrays, reverse-sorted arrays, or arrays with duplicate values, which may not be generated by rand(). Random tests do not guarantee full coverage of possible scenarios that could break the algorithm. Without printing the array, it’s impossible to know what input caused a failure, making debugging harder. Using a deterministic array alongside random tests ensures reproducibility and better verification of the sorting logic.
claunia added the Staleenhancement labels 2026-01-29 15:08:41 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/C#200