generated from freudenreichan/info2Praktikum-DobleSpiel
getDuplicate + Test + FERTIG
This commit is contained in:
parent
e7358b2c6f
commit
11798f162d
BIN
Start_Windows/doble.exe
Normal file
BIN
Start_Windows/doble.exe
Normal file
Binary file not shown.
BIN
Start_Windows/highscore.o
Normal file
BIN
Start_Windows/highscore.o
Normal file
Binary file not shown.
@ -1 +1,2 @@
|
||||
Thomas;9976
|
||||
player1;3999
|
||||
|
||||
BIN
Start_Windows/main.o
Normal file
BIN
Start_Windows/main.o
Normal file
Binary file not shown.
@ -33,7 +33,7 @@ unsigned int *createNumbers(unsigned int len)
|
||||
|
||||
srand(time(NULL));
|
||||
while(gespeichert <len-1){
|
||||
arrayNoDup[gespeichert] = rand()%(2*len);
|
||||
arrayNoDup[gespeichert] = 1 + rand()%(2*len);
|
||||
tree = addToTree(tree,&arrayNoDup[gespeichert],sizeof(int),compareInt,&isDuplicate);
|
||||
if(!isDuplicate){
|
||||
gespeichert++;
|
||||
@ -58,5 +58,13 @@ unsigned int *createNumbers(unsigned int len)
|
||||
// Returns only the only number in numbers which is present twice. Returns zero on errors.
|
||||
unsigned int getDuplicate(const unsigned int numbers[], unsigned int len)
|
||||
{
|
||||
|
||||
TreeNode *tree = NULL;
|
||||
int isduplicate=0;
|
||||
for(int i=0;i<len;i++){
|
||||
tree = addToTree(tree,&numbers[i],sizeof(numbers[0]),compareInt,&isduplicate);
|
||||
if(isduplicate){
|
||||
return numbers[i];
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Binary file not shown.
@ -31,7 +31,7 @@ static void testCreateNumbersLength() {
|
||||
unsigned int *nums = createNumbers(len);
|
||||
TEST_ASSERT_NOT_NULL(nums);
|
||||
for (unsigned int i = 0; i < len; i++) {
|
||||
TEST_ASSERT_INT_WITHIN(len * 2, 0, nums[i]); // Überprüft, ob werte zwischen 0 und len*2 liegen
|
||||
TEST_ASSERT_UINT_WITHIN(len * 2, 0, nums[i]); // Überprüft, ob werte zwischen 0 und len*2 liegen
|
||||
}
|
||||
free(nums);
|
||||
}
|
||||
@ -49,10 +49,27 @@ static void testCreateNumbersContainsDuplicate() {
|
||||
}
|
||||
}
|
||||
}
|
||||
TEST_ASSERT_EQUAL_INT(1,duplicate);
|
||||
TEST_ASSERT_EQUAL_UINT(1,duplicate);
|
||||
free(nums);
|
||||
}
|
||||
|
||||
static void testGetDuplicateNoDuplicates() {
|
||||
unsigned int values[] = {1, 2, 3, 4, 5};
|
||||
unsigned int dup = getDuplicate(values, 5);
|
||||
TEST_ASSERT_EQUAL_UINT(0, dup);
|
||||
}
|
||||
|
||||
static void testGetDuplicateWithDuplicate() {
|
||||
unsigned int values[] = {1, 2, 3, 4, 2, 5};
|
||||
unsigned int dup = getDuplicate(values, 6);
|
||||
TEST_ASSERT_EQUAL_UINT(2, dup);
|
||||
}
|
||||
|
||||
static void testGetDuplicateMultipleDuplicates() {
|
||||
unsigned int values[] = {10, 20, 30, 10, 20, 40};
|
||||
unsigned int dup = getDuplicate(values, 6);
|
||||
TEST_ASSERT_EQUAL_UINT(10, dup);
|
||||
}
|
||||
|
||||
|
||||
void setUp(void){
|
||||
@ -71,7 +88,9 @@ int main(){
|
||||
RUN_TEST(testCreateNumbersNotNull);
|
||||
RUN_TEST(testCreateNumbersLength);
|
||||
RUN_TEST(testCreateNumbersContainsDuplicate);
|
||||
|
||||
RUN_TEST(testGetDuplicateNoDuplicates);
|
||||
RUN_TEST(testGetDuplicateWithDuplicate);
|
||||
RUN_TEST(testGetDuplicateMultipleDuplicates);
|
||||
|
||||
return UNITY_END();
|
||||
}
|
||||
Binary file not shown.
BIN
Start_Windows/timer.o
Normal file
BIN
Start_Windows/timer.o
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user