generated from freudenreichan/info2Praktikum-NeuronalesNetz
Pflichtaufgaben fertig: Matrix-Fixes, Bilder einlesen, NN-Testdatei
- matrix.c: multiply summiert in MatrixType statt int (Nachkommastellen gingen verloren), clearMatrix gibt Speicher frei, Indexpruefung pro Zeile/Spalte, NULL-Pruefungen in add/multiply - imageInput.c: fseek-Spruenge entfernt, Dateikopf pruefen, Lesefehler behandeln, clearSeries implementiert - neuralNetworkTests.c: prepareNeuralNetworkFile implementiert - neuralNetwork.c: clearModel gibt das Layer-Array frei (Speicherleck) - Zusaetzliche Unittests fuer Matrix und Bildeinlesen - Testartefakte und Testprogramme in .gitignore, testFile.info2 entfernt Alle 33 Tests gruen, keine Warnungen, 87.37 % Genauigkeit (wie Referenz). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
570e3fa930
commit
4d6a86f293
8 files changed
+326
-87
No files matched your search
@@ -119,6 +119,97 @@ void test_readImagesFailsOnWrongFileTag(void)
|
||||
remove(path);
|
||||
}
|
||||
|
||||
static void writeRawFile(const char *path, const void *data, size_t size)
|
||||
{
|
||||
FILE *file = fopen(path, "wb");
|
||||
|
||||
if(file != NULL)
|
||||
{
|
||||
fwrite(data, 1, size, file);
|
||||
fclose(file);
|
||||
}
|
||||
}
|
||||
|
||||
void test_readImagesReturnsCorrectPixelValues(void)
|
||||
{
|
||||
const char *path = "testFile.info2";
|
||||
const char *fileTag = "__info2_image_file_format__";
|
||||
const unsigned short header[] = {2, 2, 2};
|
||||
const GrayScalePixelType expectedPixels1[] = {0, 64, 128, 255};
|
||||
const GrayScalePixelType expectedPixels2[] = {1, 2, 3, 4};
|
||||
const unsigned char expectedLabels[] = {7, 3};
|
||||
GrayScaleImageSeries *series = NULL;
|
||||
FILE *file = fopen(path, "wb");
|
||||
|
||||
TEST_ASSERT_NOT_NULL(file);
|
||||
fwrite(fileTag, sizeof(char), strlen(fileTag), file);
|
||||
fwrite(header, sizeof(header[0]), 3, file);
|
||||
fwrite(expectedPixels1, sizeof(GrayScalePixelType), 4, file);
|
||||
fwrite(&expectedLabels[0], sizeof(unsigned char), 1, file);
|
||||
fwrite(expectedPixels2, sizeof(GrayScalePixelType), 4, file);
|
||||
fwrite(&expectedLabels[1], sizeof(unsigned char), 1, file);
|
||||
fclose(file);
|
||||
|
||||
series = readImages(path);
|
||||
remove(path);
|
||||
|
||||
TEST_ASSERT_NOT_NULL(series);
|
||||
TEST_ASSERT_EQUAL_UINT8_ARRAY(expectedPixels1, series->images[0].buffer, 4);
|
||||
TEST_ASSERT_EQUAL_UINT8_ARRAY(expectedPixels2, series->images[1].buffer, 4);
|
||||
TEST_ASSERT_EQUAL_UINT8_ARRAY(expectedLabels, series->labels, 2);
|
||||
clearSeries(series);
|
||||
}
|
||||
|
||||
void test_readImagesFailsOnTruncatedImageData(void)
|
||||
{
|
||||
const char *path = "testFile.info2";
|
||||
long fullSize = 0;
|
||||
char *content = NULL;
|
||||
FILE *file = NULL;
|
||||
|
||||
prepareImageFile(path, 8, 8, 3, 1);
|
||||
|
||||
// Datei einlesen und ohne das letzte Byte (Label des letzten Bildes) neu schreiben
|
||||
file = fopen(path, "rb");
|
||||
TEST_ASSERT_NOT_NULL(file);
|
||||
fseek(file, 0, SEEK_END);
|
||||
fullSize = ftell(file);
|
||||
rewind(file);
|
||||
content = (char *)malloc(fullSize);
|
||||
TEST_ASSERT_NOT_NULL(content);
|
||||
TEST_ASSERT_EQUAL_INT(fullSize, fread(content, 1, fullSize, file));
|
||||
fclose(file);
|
||||
writeRawFile(path, content, fullSize - 1);
|
||||
free(content);
|
||||
|
||||
TEST_ASSERT_NULL(readImages(path));
|
||||
remove(path);
|
||||
}
|
||||
|
||||
void test_readImagesFailsOnIncompleteHeader(void)
|
||||
{
|
||||
const char *path = "testFile.info2";
|
||||
const char content[] = "__info2_image_file_format__\x02\x00\x08";
|
||||
|
||||
writeRawFile(path, content, sizeof(content) - 1);
|
||||
TEST_ASSERT_NULL(readImages(path));
|
||||
remove(path);
|
||||
}
|
||||
|
||||
void test_readImagesFailsOnZeroImages(void)
|
||||
{
|
||||
const char *path = "testFile.info2";
|
||||
prepareImageFile(path, 8, 8, 0, 1);
|
||||
TEST_ASSERT_NULL(readImages(path));
|
||||
remove(path);
|
||||
}
|
||||
|
||||
void test_clearSeriesAcceptsNull(void)
|
||||
{
|
||||
clearSeries(NULL);
|
||||
TEST_PASS();
|
||||
}
|
||||
|
||||
void setUp(void) {
|
||||
// Falls notwendig, kann hier Vorbereitungsarbeit gemacht werden
|
||||
}
|
||||
@@ -138,6 +229,11 @@ int main()
|
||||
RUN_TEST(test_readImagesReturnsCorrectLabels);
|
||||
RUN_TEST(test_readImagesReturnsNullOnNotExistingPath);
|
||||
RUN_TEST(test_readImagesFailsOnWrongFileTag);
|
||||
RUN_TEST(test_readImagesReturnsCorrectPixelValues);
|
||||
RUN_TEST(test_readImagesFailsOnTruncatedImageData);
|
||||
RUN_TEST(test_readImagesFailsOnIncompleteHeader);
|
||||
RUN_TEST(test_readImagesFailsOnZeroImages);
|
||||
RUN_TEST(test_clearSeriesAcceptsNull);
|
||||
|
||||
return UNITY_END();
|
||||
}
|
||||
Reference in new issue
Block a user