generated from freudenreichan/info2Praktikum-DobleSpiel
added first function in numbers.c
This commit is contained in:
parent
6dc857cc63
commit
b75411fd99
2
makefile
2
makefile
@ -35,7 +35,7 @@ $(program_obj_filesobj_files): %.o: %.c
|
|||||||
# --------------------------
|
# --------------------------
|
||||||
# Unit Tests
|
# Unit Tests
|
||||||
# --------------------------
|
# --------------------------
|
||||||
tets_sources = test_stack.c stack.c
|
test_sources = test_stack.c stack.c
|
||||||
test_objects = $(test_sources:.c=.o)
|
test_objects = $(test_sources:.c=.o)
|
||||||
|
|
||||||
test_runner: $(test_objects)
|
test_runner: $(test_objects)
|
||||||
|
|||||||
25
numbers.c
25
numbers.c
@ -6,8 +6,7 @@
|
|||||||
#include "bintree.h"
|
#include "bintree.h"
|
||||||
|
|
||||||
//TODO: getDuplicate und createNumbers implementieren
|
//TODO: getDuplicate und createNumbers implementieren
|
||||||
/* * * Erzeugen eines Arrays mit der vom Nutzer eingegebenen Anzahl an Zufallszahlen.
|
/* Sicherstellen, dass beim Befüllen keine Duplikate entstehen.
|
||||||
* Sicherstellen, dass beim Befüllen keine Duplikate entstehen.
|
|
||||||
* Duplizieren eines zufälligen Eintrags im Array.
|
* Duplizieren eines zufälligen Eintrags im Array.
|
||||||
* in `getDuplicate()`: Sortieren des Arrays und Erkennen der doppelten Zahl durch Vergleich benachbarter Elemente. */
|
* in `getDuplicate()`: Sortieren des Arrays und Erkennen der doppelten Zahl durch Vergleich benachbarter Elemente. */
|
||||||
|
|
||||||
@ -16,7 +15,29 @@
|
|||||||
// creating random numbers.
|
// creating random numbers.
|
||||||
unsigned int *createNumbers(unsigned int len)
|
unsigned int *createNumbers(unsigned int len)
|
||||||
{
|
{
|
||||||
|
unsigned int *array[len -1];
|
||||||
|
unsigned int position;
|
||||||
|
unsigned int duplicate;
|
||||||
|
unsigned int pos_dup;
|
||||||
|
|
||||||
|
srand(time(NULL));
|
||||||
|
|
||||||
|
for (unsigned int i = 1; i <= len; i++)
|
||||||
|
{
|
||||||
|
array[i-1] = rand() % (2*len) - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO: sicherstellen, dass im Array keine doppelten Zahlen vorhanden sind (Max)
|
||||||
|
|
||||||
|
position = rand() % len - 1;
|
||||||
|
duplicate = array[position];
|
||||||
|
pos_dup = rand() % len - 1;
|
||||||
|
|
||||||
|
if (pos_dup != position)
|
||||||
|
array[pos_dup] = array[position];
|
||||||
|
|
||||||
|
return array;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns only the only number in numbers which is present twice. Returns zero on errors.
|
// Returns only the only number in numbers which is present twice. Returns zero on errors.
|
||||||
|
|||||||
3
stack.c
3
stack.c
@ -77,4 +77,5 @@ void clearStack(StackNode *stack)
|
|||||||
|
|
||||||
current = next;
|
current = next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
13
test_stack.c
13
test_stack.c
@ -31,7 +31,7 @@ void test_on_empty_stack(void)
|
|||||||
|
|
||||||
void test_push(void)
|
void test_push(void)
|
||||||
{
|
{
|
||||||
int a[3] = 0;
|
int a[3] = {0};
|
||||||
StackNode *stack = NULL;
|
StackNode *stack = NULL;
|
||||||
|
|
||||||
for (int i = 1; i < 4; i++)
|
for (int i = 1; i < 4; i++)
|
||||||
@ -62,7 +62,7 @@ void test_push(void)
|
|||||||
|
|
||||||
else printf("Test pus: FAILED - Expected: all 1, Was: %d, %d, %d\n", a[0], a[1], a[2]);
|
else printf("Test pus: FAILED - Expected: all 1, Was: %d, %d, %d\n", a[0], a[1], a[2]);
|
||||||
|
|
||||||
stack = clearStack(stack);
|
clearStack(stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_pop(void)
|
void test_pop(void)
|
||||||
@ -84,7 +84,7 @@ void test_pop(void)
|
|||||||
|
|
||||||
else printf("Test pop: FAIL! - Stack is not empty! Head: %p\n", (void*)stack);
|
else printf("Test pop: FAIL! - Stack is not empty! Head: %p\n", (void*)stack);
|
||||||
|
|
||||||
stack = clearStack(stack);
|
clearStack(stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_top(void)
|
void test_top(void)
|
||||||
@ -99,7 +99,7 @@ void test_top(void)
|
|||||||
|
|
||||||
else printf("Test top: FAIL! - Expected 1, was %p\n", b);
|
else printf("Test top: FAIL! - Expected 1, was %p\n", b);
|
||||||
|
|
||||||
stack = clearStack(stack);
|
clearStack(stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_clearStack(void)
|
void test_clearStack(void)
|
||||||
@ -120,11 +120,12 @@ void test_clearStack(void)
|
|||||||
stack = push(stack, var_push);
|
stack = push(stack, var_push);
|
||||||
}
|
}
|
||||||
|
|
||||||
stack = clearStack(stack);
|
clearStack(stack);
|
||||||
|
|
||||||
void *a = top(stack);
|
void *a = top(stack);
|
||||||
if (a == NULL) printf("Test clear: SUCESS!\n");
|
if (a == NULL) printf("Test clear: SUCESS!\n");
|
||||||
|
|
||||||
else printf("Test clear: FAILED! - Expected: NULL, Was:%p\n", a);
|
else printf("Test clear: FAILED! - Expected: NULL, Was: %p\n", a);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user