Template
initial implementation for numbers.c with some testing in test_numbers.c
numbers.c currently uses the qsort() function from stdlib
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
#include "unity.h"
|
||||
// #include "bintree.h"
|
||||
// #include "string.h"
|
||||
#include "numbers.h"
|
||||
#include "stdlib.h"
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
// set stuff up here
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
// set stuff up here
|
||||
}
|
||||
|
||||
// getDuplicate on array without duplicats
|
||||
// expects 0/error
|
||||
void test_get_duplicate_error(void)
|
||||
{
|
||||
unsigned int input[] = {1, 5, 9, 2, 4};
|
||||
unsigned int len = sizeof(input) / sizeof(input[0]);
|
||||
|
||||
TEST_ASSERT_EQUAL_UINT(0, getDuplicate(input, len));
|
||||
}
|
||||
|
||||
// this tries to brute force a triple
|
||||
void test_for_triple(void)
|
||||
{
|
||||
// this test is less effective if srand is called inside createNumbers()
|
||||
for (int i = 0; i < 100000; i++)
|
||||
{
|
||||
unsigned int *numbers = createNumbers(3);
|
||||
if (numbers[0] == numbers[1] && numbers[1] == numbers[2])
|
||||
{
|
||||
// fail the test
|
||||
TEST_ASSERT(0);
|
||||
}
|
||||
free(numbers);
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
printf("============================\nNumbers tests\n============================\n");
|
||||
UNITY_BEGIN();
|
||||
RUN_TEST(test_get_duplicate_error);
|
||||
RUN_TEST(test_for_triple);
|
||||
return UNITY_END();
|
||||
}
|
||||
Reference in New Issue
Block a user