forked from freudenreichan/info2Praktikum-DobleSpiel
75 lines
2.0 KiB
C
75 lines
2.0 KiB
C
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
#include "unity.h"
|
|
#include "numbers.h"
|
|
|
|
void setUp(void) {}
|
|
void tearDown(void) {}
|
|
|
|
|
|
static void test_arrayGetsNumbers() {
|
|
unsigned int returnValue = 0;
|
|
unsigned int* array = createNumbers(5);
|
|
for (int i = 0; i < 5; i++) {
|
|
returnValue += array[i];
|
|
}
|
|
int expectedValue = 10;// minimal Value when len is 5 => 11
|
|
TEST_ASSERT_GREATER_THAN_INT(expectedValue,returnValue);
|
|
free (array);
|
|
}
|
|
|
|
static void test_arrayOnlyHasOneDulicate() {
|
|
unsigned int len = 5;
|
|
unsigned int *array = createNumbers(len);
|
|
int duplicateTrue = getDuplicate(array, len);
|
|
int expectedValue = 0;
|
|
free(array);
|
|
TEST_ASSERT_NOT_EQUAL_INT(expectedValue,duplicateTrue);
|
|
}
|
|
static void test_returnNullWhenLenIs0() {
|
|
unsigned int len = 0;
|
|
unsigned int *array = createNumbers(len);
|
|
free(array);
|
|
TEST_ASSERT_NULL(array);
|
|
}
|
|
|
|
static void test_findsDuplicate() {
|
|
unsigned int array[] = {5, 10, 9, 3, 3};
|
|
unsigned int len = 5;
|
|
unsigned int returnValue = getDuplicate(array, len);
|
|
unsigned int expectedValue= 3;
|
|
TEST_ASSERT_EQUAL_INT(expectedValue,returnValue);
|
|
}
|
|
static void test_return0WhenNoDuplicate() {
|
|
unsigned int array[] = {5, 10, 9, 3, 2};
|
|
unsigned int len = 5;
|
|
unsigned int returnValue = getDuplicate(array, len);
|
|
unsigned int expectedValue = 0;
|
|
TEST_ASSERT_EQUAL_INT(expectedValue, returnValue);
|
|
}
|
|
static void test_return0WhenMultipleDuplicates() {
|
|
unsigned int array[] = {5, 5, 9, 3, 3};
|
|
unsigned int len = 5;
|
|
unsigned int returnValue = getDuplicate(array, len);
|
|
unsigned int expectedValue = 0;
|
|
TEST_ASSERT_EQUAL_INT(expectedValue, returnValue);
|
|
}
|
|
|
|
int main()
|
|
{
|
|
UNITY_BEGIN();
|
|
|
|
printf("\n============================\nnumber tests\n============================\n");
|
|
RUN_TEST(test_arrayGetsNumbers);
|
|
RUN_TEST(test_arrayOnlyHasOneDulicate);
|
|
RUN_TEST(test_returnNullWhenLenIs0);
|
|
RUN_TEST(test_findsDuplicate);
|
|
RUN_TEST(test_return0WhenNoDuplicate);
|
|
RUN_TEST(test_return0WhenMultipleDuplicates);
|
|
|
|
return UNITY_END();
|
|
}
|
|
|