UNitytests bestanden, falsche Varibale inkrementiert und zurueckgegeben

This commit is contained in:
silvana884
2025-11-05 10:50:52 +01:00
parent 69844ee853
commit b1730511c6
7 changed files with 630 additions and 26 deletions
+18 -24
View File
@@ -17,7 +17,7 @@
// Creates the word salad by placing words randomly and filling empty spaces
int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount)
{
int placedChar = 0;
int placedWords = 0;
srand(time(NULL));
int usedWords[MAX_NUMBER_OF_WORDS];
@@ -25,19 +25,11 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
usedWords[i] = -1;
}
fillSalad(salad, searchFieldLen, words, wordCount, usedWords);
showWordSalad(salad, searchFieldLen);
for(int i= 0; i < MAX_SEARCH_FIELD_LEN; i++)
{
for(int j=0; j < MAX_SEARCH_FIELD_LEN; j++)
{
if(salad[i][j] != '\0')
{
placedChar++;
}
}
}
return placedChar;
placedWords = fillSalad(salad, searchFieldLen, words, wordCount, usedWords);
//showWordSalad(salad, searchFieldLen);
printf("\nPlacedWords: %d\n", placedWords);
return placedWords;
}
// Prints the word salad to console
@@ -74,8 +66,9 @@ int emptyPlaces(unsigned int wordCount)
// fills salad array with max. words from word array either horizontally or vertically
void fillSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount, int usedWords[MAX_NUMBER_OF_WORDS])
int fillSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount, int usedWords[MAX_NUMBER_OF_WORDS])
{
int addedWords = 0;
// empties salad
for(int i = 0; i < searchFieldLen; i++) {
for(int j = 0; j < searchFieldLen; j++) {
@@ -104,17 +97,18 @@ void fillSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned
if(wordLen <= searchFieldLen) {
int startCol = rand() % (searchFieldLen - wordLen + 1);
int canPlace = 1;
for(int i = 0; i < wordLen; i++) {
for(int i = 0; i < wordLen; i++) { //checks if word fits
if(salad[row][startCol + i] != '\0') {
canPlace = 0;
break;
}
}
if(canPlace) {
if(canPlace) { //word fits and is inserted
for(int i = 0; i < wordLen; i++) {
salad[row][startCol + i] = words[numWord][i];
}
placed = 1;
addedWords++;
}
}
} else {
@@ -135,6 +129,7 @@ void fillSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned
salad[startRow + i][col] = words[numWord][i];
}
placed = 1;
addedWords++;
}
}
}
@@ -142,7 +137,8 @@ void fillSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned
tries++;
}
}
fillRandom(salad, searchFieldLen, words, wordCount, 1);
fillRandom(salad);
return addedWords;
}
@@ -210,7 +206,8 @@ void fillWordinRow(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN],unsign
//Fills word in salad and deletes row of words of the used word, vertical from top to bottom
void fillWordinColumn(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount, int numWord, int column)
{int wordLen = strlen(words[numWord]);
{
int wordLen = strlen(words[numWord]);
if (wordLen > searchFieldLen || wordLen == 0)
return;
@@ -233,10 +230,8 @@ void fillWordinColumn(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], un
// if emptyPlaces, fill these with random letters
void fillRandom(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount, int empty)
void fillRandom(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN])
{
if(empty)
{
for(int j=0; j < MAX_SEARCH_FIELD_LEN; j++)
{
for(int h= 0; h < MAX_SEARCH_FIELD_LEN; h++)
@@ -249,5 +244,4 @@ void fillRandom(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned
}
}
}
}
}
}
+2 -2
View File
@@ -10,11 +10,11 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
void showWordSalad(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen);
int printHorizontal(unsigned int wordCount);
int emptyPlaces(unsigned int wordCount);
void fillSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount, int usedWords[MAX_NUMBER_OF_WORDS]);
int fillSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount, int usedWords[MAX_NUMBER_OF_WORDS]);
int whichWord(const char words[][MAX_WORD_LEN], unsigned int wordCount, int usedWords[MAX_NUMBER_OF_WORDS]);
void fillWordinRow(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount, int numWord, int row);
void fillWordinColumn(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount, int numWord, int column);
void fillRandom(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount, int empty);
void fillRandom(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN]);