add separate test function

This commit is contained in:
northernSage 2021-02-17 07:14:34 -03:00
parent 3b647a617a
commit 9ba58f4571

View File

@ -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;