add GreyScaleTest
This commit is contained in:
parent
e67fb83d8f
commit
dafd526828
@ -6,7 +6,7 @@
|
|||||||
#include "imageInput.h"
|
#include "imageInput.h"
|
||||||
|
|
||||||
|
|
||||||
static void prepareImageFile(const char *path, unsigned short int width, unsigned short int height, unsigned int short numberOfImages, unsigned char label)
|
static void prepareImageFile(const char *path, unsigned short int width, unsigned short int height, unsigned int short numberOfImages, unsigned char label, unsigned short greyScaleTest)
|
||||||
{
|
{
|
||||||
FILE *file = fopen(path, "wb");
|
FILE *file = fopen(path, "wb");
|
||||||
|
|
||||||
@ -17,6 +17,14 @@ static void prepareImageFile(const char *path, unsigned short int width, unsigne
|
|||||||
|
|
||||||
if(zeroBuffer != NULL)
|
if(zeroBuffer != NULL)
|
||||||
{
|
{
|
||||||
|
if(greyScaleTest)
|
||||||
|
{
|
||||||
|
for(unsigned int i = 0; i < (numberOfImages * width * height); i++)
|
||||||
|
{
|
||||||
|
zeroBuffer[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);
|
||||||
@ -41,7 +49,7 @@ void test_readImagesReturnsCorrectNumberOfImages(void)
|
|||||||
GrayScaleImageSeries *series = NULL;
|
GrayScaleImageSeries *series = NULL;
|
||||||
const unsigned short expectedNumberOfImages = 2;
|
const unsigned short expectedNumberOfImages = 2;
|
||||||
const char *path = "testFile.info2";
|
const char *path = "testFile.info2";
|
||||||
prepareImageFile(path, 8, 8, expectedNumberOfImages, 1);
|
prepareImageFile(path, 8, 8, expectedNumberOfImages, 1, 0);
|
||||||
series = readImages(path);
|
series = readImages(path);
|
||||||
TEST_ASSERT_NOT_NULL(series);
|
TEST_ASSERT_NOT_NULL(series);
|
||||||
TEST_ASSERT_EQUAL_UINT16(expectedNumberOfImages, series->count);
|
TEST_ASSERT_EQUAL_UINT16(expectedNumberOfImages, series->count);
|
||||||
@ -54,7 +62,7 @@ void test_readImagesReturnsCorrectImageWidth(void)
|
|||||||
GrayScaleImageSeries *series = NULL;
|
GrayScaleImageSeries *series = NULL;
|
||||||
const unsigned short expectedWidth = 10;
|
const unsigned short expectedWidth = 10;
|
||||||
const char *path = "testFile.info2";
|
const char *path = "testFile.info2";
|
||||||
prepareImageFile(path, expectedWidth, 8, 2, 1);
|
prepareImageFile(path, expectedWidth, 8, 2, 1, 0);
|
||||||
series = readImages(path);
|
series = readImages(path);
|
||||||
TEST_ASSERT_NOT_NULL(series);
|
TEST_ASSERT_NOT_NULL(series);
|
||||||
TEST_ASSERT_NOT_NULL(series->images);
|
TEST_ASSERT_NOT_NULL(series->images);
|
||||||
@ -70,7 +78,7 @@ void test_readImagesReturnsCorrectImageHeight(void)
|
|||||||
GrayScaleImageSeries *series = NULL;
|
GrayScaleImageSeries *series = NULL;
|
||||||
const unsigned short expectedHeight = 10;
|
const unsigned short expectedHeight = 10;
|
||||||
const char *path = "testFile.info2";
|
const char *path = "testFile.info2";
|
||||||
prepareImageFile(path, 8, expectedHeight, 2, 1);
|
prepareImageFile(path, 8, expectedHeight, 2, 1, 0);
|
||||||
series = readImages(path);
|
series = readImages(path);
|
||||||
TEST_ASSERT_NOT_NULL(series);
|
TEST_ASSERT_NOT_NULL(series);
|
||||||
TEST_ASSERT_NOT_NULL(series->images);
|
TEST_ASSERT_NOT_NULL(series->images);
|
||||||
@ -87,7 +95,7 @@ void test_readImagesReturnsCorrectLabels(void)
|
|||||||
|
|
||||||
GrayScaleImageSeries *series = NULL;
|
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, 0);
|
||||||
series = readImages(path);
|
series = readImages(path);
|
||||||
TEST_ASSERT_NOT_NULL(series);
|
TEST_ASSERT_NOT_NULL(series);
|
||||||
TEST_ASSERT_NOT_NULL(series->labels);
|
TEST_ASSERT_NOT_NULL(series->labels);
|
||||||
@ -119,6 +127,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, 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 +167,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();
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user