Skip to content

[FEATURE] #1525

@Ujwal200707

Description

@Ujwal200707

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions