diff --git a/Image/ImageUtils.h b/Image/ImageUtils.h index 9d0ed53..d32c210 100644 --- a/Image/ImageUtils.h +++ b/Image/ImageUtils.h @@ -1,8 +1,6 @@ /** * Karaka * - * PHP Version 8.0 - * * @package Image * @copyright Dennis Eichhorn * @license OMS License 1.0 diff --git a/Image/Skew.h b/Image/Skew.h index 4030e8e..d293670 100644 --- a/Image/Skew.h +++ b/Image/Skew.h @@ -1,8 +1,6 @@ /** * Karaka * - * PHP Version 8.0 - * * @package Image * @copyright Dennis Eichhorn * @license OMS License 1.0 diff --git a/Image/Thresholding.h b/Image/Thresholding.h index 1ad9ced..ae704c7 100644 --- a/Image/Thresholding.h +++ b/Image/Thresholding.h @@ -1,8 +1,6 @@ /** * Karaka * - * PHP Version 8.0 - * * @package Image * @copyright Dennis Eichhorn * @license OMS License 1.0 diff --git a/Tools/InvoicePreprocessing/main.cpp b/Tools/InvoicePreprocessing/main.cpp index 5e7f501..ec5ff37 100644 --- a/Tools/InvoicePreprocessing/main.cpp +++ b/Tools/InvoicePreprocessing/main.cpp @@ -1,8 +1,6 @@ /** * Karaka * - * PHP Version 8.0 - * * @package App * @copyright Dennis Eichhorn * @license OMS License 1.0 @@ -15,7 +13,7 @@ #include "../../Image/Skew.h" #include "../../Image/Thresholding.h" -int main(int argc, char** argv ) +int main(int argc, char** argv) { if (argc != 3) { printf("A input image and a output image is required\n"); diff --git a/Utils/TestUtils.h b/Utils/TestUtils.h new file mode 100644 index 0000000..7739b29 --- /dev/null +++ b/Utils/TestUtils.h @@ -0,0 +1,28 @@ +/** + * Karaka + * + * @package Utils + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link https://karaka.app + */ +#ifndef UTILS_TEST_UTILS_H +#define UTILS_TEST_UTILS_H + +#include +#include + +#define ASSERT_EQUALS(a, b, t1, t2) \ + ({ __typeof__ (a) _a = (a); \ + __typeof__ (b) _b = (b); \ + if (_a == _b) { printf("."); } else { printf("F"); printf("\n\n%s - %i: ", __FILE__, __LINE__); printf(t1, a); printf(" != "); printf(t2, b); return 0; } \ + }) + +#define ASSERT_EQUALS__DELTA(a, b, delta, t1, t2) \ + ({ __typeof__ (a) _a = (a); \ + __typeof__ (b) _b = (b); \ + if (abs(_a - _b) <= delta) { printf("."); } else { printf("F"); printf("\n\n%s - %i: ", __FILE__, __LINE__); printf(t1, a); printf(" != "); printf(t2, b); printf("\n"); return 0; } \ + }) + +#endif \ No newline at end of file diff --git a/tests/Image/ImageUtilsTest.cpp b/tests/Image/ImageUtilsTest.cpp new file mode 100644 index 0000000..09dcf56 --- /dev/null +++ b/tests/Image/ImageUtilsTest.cpp @@ -0,0 +1,33 @@ +/** + * Karaka + * + * @package Test + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link https://karaka.app + */ +#include + +#include "../../Utils/TestUtils.h" +#include "../../Image/ImageUtils.h" + +int main(int argc, char** argv) +{ + printf("ImageUtils:\n\n"); + + printf("lightnessFromRgb:\n"); + + float white = Image::ImageUtils::lightnessFromRgb(255, 255, 255); + ASSERT_EQUALS(white, 1.0, "%f", "%f"); + + float black = Image::ImageUtils::lightnessFromRgb(0, 0, 0); + ASSERT_EQUALS(black, 0.0, "%f", "%f"); + + float other = Image::ImageUtils::lightnessFromRgb(125, 125, 125); + ASSERT_EQUALS__DELTA(other, 0.524, 0.00001, "%f", "%f"); + + printf("\n"); + + return 0; +} \ No newline at end of file diff --git a/tests/test.sh b/tests/test.sh new file mode 100755 index 0000000..974ca29 --- /dev/null +++ b/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +g++ Image/ImageUtilsTest.cpp -o Image/ImageUtilsTest && ./Image/ImageUtilsTest && rm Image/ImageUtilsTest \ No newline at end of file