Merge branch 'main' into temp
This commit is contained in:
commit
5b576589e3
4
.gitignore
vendored
4
.gitignore
vendored
@ -2,3 +2,7 @@ doble_initial.exe
|
|||||||
highscores.txt
|
highscores.txt
|
||||||
runStackTest.exe
|
runStackTest.exe
|
||||||
stack.o
|
stack.o
|
||||||
|
runNumbersTest.exe
|
||||||
|
numbers.o
|
||||||
|
.vscode/launch.json
|
||||||
|
.vscode/settings.json
|
||||||
|
|||||||
20
numbers.c
20
numbers.c
@ -32,19 +32,33 @@ unsigned int checkArray(unsigned int *array, unsigned int len, unsigned int numb
|
|||||||
unsigned int *createNumbers(unsigned int len)
|
unsigned int *createNumbers(unsigned int len)
|
||||||
{
|
{
|
||||||
srand(time(NULL));
|
srand(time(NULL));
|
||||||
unsigned int array[len];
|
unsigned int *array = (unsigned int*)malloc(len * sizeof(unsigned int));
|
||||||
unsigned int randomNr;
|
int randomNr, counter;
|
||||||
|
|
||||||
|
if(array == NULL)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < len; i++)
|
for (int i = 0; i < len; i++)
|
||||||
{
|
{
|
||||||
|
counter = 0;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
randomNr = rand() % 2 * len + 1;
|
if (counter == 9)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
randomNr = rand() % (2 * len + 1);
|
||||||
|
counter++;
|
||||||
} while (!checkArray(array, i, randomNr));
|
} while (!checkArray(array, i, randomNr));
|
||||||
|
|
||||||
array[i] = randomNr;
|
array[i] = randomNr;
|
||||||
|
printf("%u ", array[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
printf("\n");
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -3,6 +3,20 @@
|
|||||||
#include "numbers.h"
|
#include "numbers.h"
|
||||||
#include "unity.h"
|
#include "unity.h"
|
||||||
|
|
||||||
|
void createNumbersTest()
|
||||||
|
{
|
||||||
|
unsigned int *array;
|
||||||
|
unsigned int len = 6;
|
||||||
|
|
||||||
|
array = createNumbers(len);
|
||||||
|
for (int i = 0; i < len; i++)
|
||||||
|
{
|
||||||
|
printf("%u ", array[i]);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
TEST_ASSERT_NOT_NULL(array);
|
||||||
|
}
|
||||||
|
|
||||||
void duplicateTest()
|
void duplicateTest()
|
||||||
{
|
{
|
||||||
unsigned int array[6] = {1, 4, 5, 2, 3, 1};
|
unsigned int array[6] = {1, 4, 5, 2, 3, 1};
|
||||||
@ -26,7 +40,7 @@ int main()
|
|||||||
UNITY_BEGIN();
|
UNITY_BEGIN();
|
||||||
|
|
||||||
printf("============================\nNumbers tests\n============================\n");
|
printf("============================\nNumbers tests\n============================\n");
|
||||||
|
RUN_TEST(createNumbersTest);
|
||||||
RUN_TEST(duplicateTest);
|
RUN_TEST(duplicateTest);
|
||||||
|
|
||||||
return UNITY_END();
|
return UNITY_END();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user