Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
34a471bda6 | ||
|
|
f8035cc4db | ||
|
|
db7617e046 | ||
|
|
47ff0906cc | ||
|
|
fe0728da3e | ||
|
|
dafd526828 | ||
|
|
e67fb83d8f |
No files matched your search
+7
-21
@@ -1,21 +1,7 @@
|
|||||||
I2_Wortsalat/Start_Mac/wordsalad_initial
|
# Alles ignorieren
|
||||||
I2_Wortsalat/Start_Mac/.DS_Store
|
*
|
||||||
I2_Wortsalat/.DS_Store
|
|
||||||
I2_Wortsalat/Start_Mac/input.o
|
# Ausnahmen: bestimmte Dateitypen in allen Verzeichnissen
|
||||||
.gitignore
|
!**/*.c
|
||||||
I2_Wortsalat/Start_Mac/game.o
|
!**/*.h
|
||||||
I2_Wortsalat/Start_Mac/runTests
|
!**/*Makefile
|
||||||
.o
|
|
||||||
.a
|
|
||||||
.idea/editor.xml
|
|
||||||
.idea/vcs.xml
|
|
||||||
.idea/workspace.xml
|
|
||||||
I2_Wortsalat/.idea/editor.xml
|
|
||||||
I2_Wortsalat/.idea/I2_Wortsalat.iml
|
|
||||||
I2_Wortsalat/.idea/modules.xml
|
|
||||||
I2_Wortsalat/Start_Mac/main.o
|
|
||||||
I2_Wortsalat/Start_Mac/.DS_Store
|
|
||||||
I2_Wortsalat/Start_Mac/.DS_Store
|
|
||||||
I2_Wortsalat/Start_Mac/wordsalad
|
|
||||||
I2_Wortsalat/Start_Mac/graphicalGame.o
|
|
||||||
.DS_Store
|
|
||||||
@@ -13,10 +13,15 @@ static void prepareImageFile(const char *path, unsigned short int width, unsigne
|
|||||||
if(file != NULL)
|
if(file != NULL)
|
||||||
{
|
{
|
||||||
const char *fileTag = "__info2_image_file_format__";
|
const char *fileTag = "__info2_image_file_format__";
|
||||||
GrayScalePixelType *zeroBuffer = (GrayScalePixelType *)calloc(numberOfImages * width * height, sizeof(GrayScalePixelType));
|
GrayScalePixelType *buffer = (GrayScalePixelType *)calloc(numberOfImages * width * height, sizeof(GrayScalePixelType));
|
||||||
|
|
||||||
if(zeroBuffer != NULL)
|
if(buffer != NULL)
|
||||||
{
|
{
|
||||||
|
for(unsigned int i = 0; i < (numberOfImages * width * height); i++)
|
||||||
|
{
|
||||||
|
buffer[i] = (GrayScalePixelType)i;
|
||||||
|
}
|
||||||
|
|
||||||
fwrite(fileTag, sizeof(fileTag[0]), strlen(fileTag), file);
|
fwrite(fileTag, sizeof(fileTag[0]), strlen(fileTag), file);
|
||||||
fwrite(&numberOfImages, sizeof(numberOfImages), 1, file);
|
fwrite(&numberOfImages, sizeof(numberOfImages), 1, file);
|
||||||
fwrite(&width, sizeof(width), 1, file);
|
fwrite(&width, sizeof(width), 1, file);
|
||||||
@@ -24,11 +29,11 @@ static void prepareImageFile(const char *path, unsigned short int width, unsigne
|
|||||||
|
|
||||||
for(int i = 0; i < numberOfImages; i++)
|
for(int i = 0; i < numberOfImages; i++)
|
||||||
{
|
{
|
||||||
fwrite(zeroBuffer, sizeof(GrayScalePixelType), width * height, file);
|
fwrite(buffer, sizeof(GrayScalePixelType), width * height, file);
|
||||||
fwrite(&label, sizeof(unsigned char), 1, file);
|
fwrite(&label, sizeof(unsigned char), 1, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(zeroBuffer);
|
free(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(file);
|
fclose(file);
|
||||||
@@ -119,6 +124,27 @@ void test_readImagesFailsOnWrongFileTag(void)
|
|||||||
remove(path);
|
remove(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test_readImagesReadsCorrectGrayScales(void)
|
||||||
|
{
|
||||||
|
GrayScaleImageSeries *series = NULL;
|
||||||
|
const char *path = "testFile.info2";
|
||||||
|
|
||||||
|
prepareImageFile(path, 8, 8, 1, 1);
|
||||||
|
series = readImages(path);
|
||||||
|
|
||||||
|
TEST_ASSERT_NOT_NULL(series);
|
||||||
|
TEST_ASSERT_NOT_NULL(series->images);
|
||||||
|
TEST_ASSERT_EQUAL_UINT16(1, series->count);
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < (8 * 8); i++)
|
||||||
|
{
|
||||||
|
TEST_ASSERT_EQUAL_UINT8((GrayScalePixelType)i, series->images->buffer[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
clearSeries(series);
|
||||||
|
remove(path);
|
||||||
|
}
|
||||||
|
|
||||||
void setUp(void) {
|
void setUp(void) {
|
||||||
// Falls notwendig, kann hier Vorbereitungsarbeit gemacht werden
|
// Falls notwendig, kann hier Vorbereitungsarbeit gemacht werden
|
||||||
}
|
}
|
||||||
@@ -138,6 +164,7 @@ int main()
|
|||||||
RUN_TEST(test_readImagesReturnsCorrectLabels);
|
RUN_TEST(test_readImagesReturnsCorrectLabels);
|
||||||
RUN_TEST(test_readImagesReturnsNullOnNotExistingPath);
|
RUN_TEST(test_readImagesReturnsNullOnNotExistingPath);
|
||||||
RUN_TEST(test_readImagesFailsOnWrongFileTag);
|
RUN_TEST(test_readImagesFailsOnWrongFileTag);
|
||||||
|
RUN_TEST(test_readImagesReadsCorrectGrayScales);
|
||||||
|
|
||||||
return UNITY_END();
|
return UNITY_END();
|
||||||
}
|
}
|
||||||
@@ -63,7 +63,7 @@ Matrix add(const Matrix matrix1, const Matrix matrix2)
|
|||||||
{
|
{
|
||||||
Matrix result;
|
Matrix result;
|
||||||
|
|
||||||
if (matrix1.buffer == NULL || matrix2.buffer == NULL || matrix1.rows != matrix2.rows || matrix1.cols != matrix2.cols)
|
if (matrix1.buffer == NULL || matrix2.buffer == NULL || matrix1.rows != matrix2.rows)
|
||||||
{
|
{
|
||||||
result.rows = 0;
|
result.rows = 0;
|
||||||
result.cols = 0;
|
result.cols = 0;
|
||||||
@@ -71,17 +71,51 @@ Matrix add(const Matrix matrix1, const Matrix matrix2)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = createMatrix(matrix1.rows, matrix1.cols);
|
if (matrix1.cols == matrix2.cols)
|
||||||
|
|
||||||
for (int i = 0; i < matrix1.rows; i++)
|
|
||||||
{
|
{
|
||||||
for (int j = 0; j < matrix1.cols; j++)
|
result = createMatrix(matrix1.rows, matrix1.cols);
|
||||||
|
for (int i = 0; i < matrix1.rows; i++)
|
||||||
{
|
{
|
||||||
MatrixType value = getMatrixAt(matrix1, i, j) + getMatrixAt(matrix2, i, j);
|
for (int j = 0; j < matrix1.cols; j++)
|
||||||
setMatrixAt(value, result, i, j);
|
{
|
||||||
|
MatrixType value = getMatrixAt(matrix1, i, j) + getMatrixAt(matrix2, i, j);
|
||||||
|
setMatrixAt(value, result, i, j);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (matrix1.cols == 1 && matrix2.cols > 1)
|
||||||
|
{
|
||||||
|
result = createMatrix(matrix1.rows, matrix2.cols);
|
||||||
|
for (int i = 0; i < matrix1.rows; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < matrix2.cols; j++)
|
||||||
|
{
|
||||||
|
MatrixType value = getMatrixAt(matrix1, i, 0) + getMatrixAt(matrix2, i, j);
|
||||||
|
setMatrixAt(value, result, i, j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
else if (matrix2.cols == 1 && matrix1.cols > 1)
|
||||||
|
{
|
||||||
|
result = createMatrix(matrix1.rows, matrix1.cols);
|
||||||
|
for (int i = 0; i < matrix1.rows; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < matrix1.cols; j++)
|
||||||
|
{
|
||||||
|
MatrixType value = getMatrixAt(matrix1, i, j) + getMatrixAt(matrix2, i, 0);
|
||||||
|
setMatrixAt(value, result, i, j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Fall: Unterschiedliche Spaltenanzahl, beide ungleich 1
|
||||||
|
result.rows = 0;
|
||||||
|
result.cols = 0;
|
||||||
|
result.buffer = NULL;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,9 +9,9 @@ typedef float MatrixType;
|
|||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
|
MatrixType *buffer;
|
||||||
int rows;
|
int rows;
|
||||||
int cols;
|
int cols;
|
||||||
MatrixType *buffer;
|
|
||||||
} Matrix;
|
} Matrix;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -141,6 +141,32 @@ void test_setMatrixAtFailsOnIndicesOutOfRange(void)
|
|||||||
TEST_ASSERT_EQUAL_FLOAT_ARRAY(expectedResults, matrixToTest.buffer, matrixToTest.cols * matrixToTest.rows);
|
TEST_ASSERT_EQUAL_FLOAT_ARRAY(expectedResults, matrixToTest.buffer, matrixToTest.cols * matrixToTest.rows);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test_addSupportsBroadcasting(void)
|
||||||
|
{
|
||||||
|
MatrixType buffer1[] = {1, 2, 3, 4, 5, 6};
|
||||||
|
MatrixType buffer2[] = {7, 8};
|
||||||
|
Matrix matrix1 = {.rows=2, .cols=3, .buffer=buffer1};
|
||||||
|
Matrix matrix2 = {.rows=2, .cols=1, .buffer=buffer2};
|
||||||
|
|
||||||
|
Matrix result1 = add(matrix1, matrix2);
|
||||||
|
Matrix result2 = add(matrix2, matrix1);
|
||||||
|
|
||||||
|
float expectedResults[] = {8, 9, 10, 12, 13, 14};
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL_UINT32(matrix1.rows, result1.rows);
|
||||||
|
TEST_ASSERT_EQUAL_UINT32(matrix1.cols, result1.cols);
|
||||||
|
TEST_ASSERT_EQUAL_UINT32(matrix1.rows, result2.rows);
|
||||||
|
TEST_ASSERT_EQUAL_UINT32(matrix1.cols, result2.cols);
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL_INT(sizeof(expectedResults)/sizeof(expectedResults[0]), result1.rows * result1.cols);
|
||||||
|
TEST_ASSERT_EQUAL_FLOAT_ARRAY(expectedResults, result1.buffer, result1.cols * result1.rows);
|
||||||
|
TEST_ASSERT_EQUAL_INT(sizeof(expectedResults)/sizeof(expectedResults[0]), result2.rows * result2.cols);
|
||||||
|
TEST_ASSERT_EQUAL_FLOAT_ARRAY(expectedResults, result2.buffer, result2.cols * result2.rows);
|
||||||
|
|
||||||
|
free(result1.buffer);
|
||||||
|
free(result2.buffer);
|
||||||
|
}
|
||||||
|
|
||||||
void setUp(void) {
|
void setUp(void) {
|
||||||
// Falls notwendig, kann hier Vorbereitungsarbeit gemacht werden
|
// Falls notwendig, kann hier Vorbereitungsarbeit gemacht werden
|
||||||
}
|
}
|
||||||
@@ -165,6 +191,7 @@ int main()
|
|||||||
RUN_TEST(test_getMatrixAtFailsOnIndicesOutOfRange);
|
RUN_TEST(test_getMatrixAtFailsOnIndicesOutOfRange);
|
||||||
RUN_TEST(test_setMatrixAtSetsCorrectValue);
|
RUN_TEST(test_setMatrixAtSetsCorrectValue);
|
||||||
RUN_TEST(test_setMatrixAtFailsOnIndicesOutOfRange);
|
RUN_TEST(test_setMatrixAtFailsOnIndicesOutOfRange);
|
||||||
|
RUN_TEST(test_addSupportsBroadcasting);
|
||||||
|
|
||||||
return UNITY_END();
|
return UNITY_END();
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user