mirror of
https://github.com/TheAlgorithms/C
synced 2024-11-24 22:39:52 +03:00
add separate test function
This commit is contained in:
parent
3b647a617a
commit
9ba58f4571
@ -3,6 +3,7 @@
|
||||
#define MAX 20
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <assert.h>
|
||||
|
||||
/**
|
||||
* Bubble sort implementation
|
||||
@ -38,6 +39,31 @@ void bubblesort(int* array_sort)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test function
|
||||
* @returns void
|
||||
*/
|
||||
static void test() {
|
||||
/* simple int array for testing */
|
||||
int array_sort[MAX] = {0};
|
||||
|
||||
/* populate our test array with
|
||||
* random integer numbers */
|
||||
for (int i = 0; i < MAX; i++)
|
||||
{
|
||||
array_sort[i] = rand() % 101;
|
||||
}
|
||||
|
||||
/* sort array */
|
||||
bubblesort(array_sort);
|
||||
|
||||
/* check if array ir correctly ordered */
|
||||
for (int i = 0; i < MAX - 1; i++)
|
||||
{
|
||||
assert(array_sort[i] <= array_sort[i+1]);
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int i, array_sort[MAX] = {0}, is_sorted = false, change_place;
|
||||
|
Loading…
Reference in New Issue
Block a user