forked from freudenreichan/info2Praktikum-NeuronalesNetz
custom test works
This commit is contained in:
1 parent
cdc4a68824
commit
4bb015fb56
1 file changed
+23
-32
+23
-32
@@ -35,33 +35,6 @@ static void prepareImageFile(const char *path, unsigned short int width, unsigne
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int writeImagesToFile(const char *path, GrayScaleImageSeries *series)
|
|
||||||
{
|
|
||||||
FILE *file = fopen(path, "wb");
|
|
||||||
|
|
||||||
if (file != NULL)
|
|
||||||
{
|
|
||||||
const char *fileTag = "__info2_image_file_format__";
|
|
||||||
const short count = (short)series->count;
|
|
||||||
const short width = (short)(series->images[0].width);
|
|
||||||
const short height = (short)(series->images[0].height);
|
|
||||||
fwrite(fileTag, sizeof(fileTag[0]), strlen(fileTag), file);
|
|
||||||
fwrite(&count, sizeof(short), 1, file);
|
|
||||||
fwrite(&width, sizeof(short), 1, file);
|
|
||||||
fwrite(&height, sizeof(short), 1, file);
|
|
||||||
|
|
||||||
for (int i = 0; i < series->count; i++)
|
|
||||||
{
|
|
||||||
fwrite(series->images[i].buffer, sizeof(GrayScalePixelType), width * height, file);
|
|
||||||
fwrite(&(series->labels[i]), sizeof(unsigned char), 1, file);
|
|
||||||
}
|
|
||||||
|
|
||||||
fclose(file);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void test_readImagesReturnsCorrectNumberOfImages(void)
|
void test_readImagesReturnsCorrectNumberOfImages(void)
|
||||||
{
|
{
|
||||||
GrayScaleImageSeries *series = NULL;
|
GrayScaleImageSeries *series = NULL;
|
||||||
@@ -145,19 +118,37 @@ void test_readImagesFailsOnWrongFileTag(void)
|
|||||||
remove(path);
|
remove(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int editSize(const char* path, const unsigned short w, const unsigned short h) {
|
||||||
|
FILE *fd = fopen(path, "rb+");
|
||||||
|
if (fd == NULL) return 1;
|
||||||
|
|
||||||
|
long x = 0;
|
||||||
|
|
||||||
|
// skip over header and image number
|
||||||
|
x += strlen("__info2_image_file_format__");
|
||||||
|
x += sizeof(unsigned short);
|
||||||
|
|
||||||
|
fseek(fd, x, SEEK_SET);
|
||||||
|
|
||||||
|
// set width & height
|
||||||
|
|
||||||
|
if (!fwrite(&w, sizeof(w), 1, fd)) return 1;
|
||||||
|
if (!fwrite(&h, sizeof(h), 1, fd)) return 1;
|
||||||
|
|
||||||
|
if (fclose(fd)) return 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// Test if the sizes specify buffers which are larger than can be read from the file
|
// Test if the sizes specify buffers which are larger than can be read from the file
|
||||||
// Errors as it runs into the end of the file
|
// Errors as it runs into the end of the file
|
||||||
void test_sizes_wrong(void)
|
void test_sizes_wrong(void)
|
||||||
{
|
{
|
||||||
const unsigned char expectedLabel = 15;
|
const unsigned char expectedLabel = 15;
|
||||||
|
|
||||||
GrayScaleImageSeries *series = NULL;
|
|
||||||
const char *path = "testFile.info2";
|
const char *path = "testFile.info2";
|
||||||
prepareImageFile(path, 8, 8, 2, expectedLabel);
|
prepareImageFile(path, 8, 8, 2, expectedLabel);
|
||||||
series = readImages(path);
|
TEST_ASSERT_EQUAL_INT(0, editSize(path, 8, 9));
|
||||||
series->images[0].width = series->images[0].width + 1;
|
|
||||||
writeImagesToFile(path, series);
|
|
||||||
|
|
||||||
|
|
||||||
TEST_ASSERT_NULL(readImages(path));
|
TEST_ASSERT_NULL(readImages(path));
|
||||||
remove(path);
|
remove(path);
|
||||||
|
|||||||
Reference in new issue
Block a user