Added first tests.
the build was successful
Details
the build was successful
Details
This commit is contained in:
parent
b518d5ed12
commit
903de5f906
|
@ -19,10 +19,11 @@ pipeline:
|
|||
- apt-get update -q
|
||||
- apt-get install -qy -t xenial g++-5
|
||||
- apt-get install -qy cmake pkg-config
|
||||
- apt-get install -qy libmagick++-dev
|
||||
- apt-get install -qy libmagick++-dev catch
|
||||
- rm -rf build && mkdir -p build && cd build
|
||||
- cmake -DCMAKE_INSTALL_PREFIX=/usr ..
|
||||
- make VERBOSE=1
|
||||
- ctest ..
|
||||
volumes:
|
||||
- /var/cache/debian-package-cache:/var/cache/apt/archives
|
||||
|
||||
|
|
|
@ -41,3 +41,4 @@ install(FILES src/${CMAKE_PROJECT_NAME}.hpp DESTINATION ${CMAKE_INSTALL_INCLUDED
|
|||
install(FILES README.md DESTINATION ${CMAKE_INSTALL_DOCDIR})
|
||||
|
||||
include(packages.CMakeLists.txt)
|
||||
include(tests.CMakeLists.txt)
|
||||
|
|
|
@ -79,6 +79,8 @@ They are generated on Debian Stretch 64 bit and signed with my
|
|||
[clang](https://llvm.org/) 5/6)
|
||||
* [cmake](https://cmake.org/) (at least 3.2)
|
||||
* [imagemagick](https://www.imagemagick.org/) (tested: 7.0 / 6.7)
|
||||
* Optional:
|
||||
* [Catch](https://github.com/catchorg/Catch2) (tested: 2.3.0)
|
||||
|
||||
On a Debian system, install the packages:
|
||||
`build-essential cmake libmagick++-dev`.
|
||||
|
@ -96,6 +98,7 @@ make install
|
|||
##### cmake options
|
||||
|
||||
* `-DCMAKE_BUILD_TYPE=Debug` for a debug build
|
||||
* `-DWITH_TESTS=Debug` to build tests
|
||||
* One of:
|
||||
* `-DWITH_DEB=YES` to generate a deb-package
|
||||
* `-DWITH_RPM=YES` to generate an rpm-package
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
#define CATCH_CONFIG_MAIN
|
||||
#include <catch2/catch.hpp>
|
|
@ -0,0 +1,88 @@
|
|||
#include <catch2/catch.hpp>
|
||||
#include <string>
|
||||
#include <Magick++/Image.h>
|
||||
#include "identiconpp.hpp"
|
||||
|
||||
using std::string;
|
||||
#include <iostream>
|
||||
|
||||
SCENARIO("ltr_asymmetric")
|
||||
{
|
||||
GIVEN("An identicon instance with 2x2 dots")
|
||||
{
|
||||
Identiconpp identicon(2, 2, Identiconpp::algorithm::ltr_asymmetric);
|
||||
Magick::Image img;
|
||||
Magick::Color black("#000000ff");
|
||||
Magick::Color white("#ffffffff");
|
||||
|
||||
WHEN("Digest is \"00\"")
|
||||
{
|
||||
img = identicon.generate("00", 2);
|
||||
THEN("Is completely white")
|
||||
{
|
||||
REQUIRE(img.pixelColor(0, 0) == white);
|
||||
REQUIRE(img.pixelColor(0, 1) == white);
|
||||
REQUIRE(img.pixelColor(1, 0) == white);
|
||||
REQUIRE(img.pixelColor(1, 1) == white);
|
||||
}
|
||||
}
|
||||
|
||||
WHEN("Digest is \"ff\"")
|
||||
{
|
||||
img = identicon.generate("ff", 2);
|
||||
THEN("Is completely black")
|
||||
{
|
||||
REQUIRE(img.pixelColor(0, 0) == black);
|
||||
REQUIRE(img.pixelColor(0, 1) == black);
|
||||
REQUIRE(img.pixelColor(1, 0) == black);
|
||||
REQUIRE(img.pixelColor(1, 1) == black);
|
||||
}
|
||||
}
|
||||
|
||||
WHEN("Digest is \"70\"")
|
||||
{
|
||||
// 0111 0000 = 01
|
||||
// 11
|
||||
img = identicon.generate("70", 2);
|
||||
THEN("Produces white pixel at 0x0")
|
||||
{
|
||||
REQUIRE(img.pixelColor(0, 0) == white);
|
||||
}
|
||||
THEN("Produces black pixel at 1x0")
|
||||
{
|
||||
REQUIRE(img.pixelColor(1, 0) == black);
|
||||
}
|
||||
THEN("Produces black pixel at 1x0")
|
||||
{
|
||||
REQUIRE(img.pixelColor(0, 1) == black);
|
||||
}
|
||||
THEN("Produces black pixel at 1x1")
|
||||
{
|
||||
REQUIRE(img.pixelColor(1, 1) == black);
|
||||
}
|
||||
}
|
||||
|
||||
WHEN("Digest is \"80\"")
|
||||
{
|
||||
// 1000 0000 = 10
|
||||
// 00
|
||||
img = identicon.generate("80", 2);
|
||||
THEN("Produces black pixel at 0x0")
|
||||
{
|
||||
REQUIRE(img.pixelColor(0, 0) == black);
|
||||
}
|
||||
THEN("Produces white pixel at 1x0")
|
||||
{
|
||||
REQUIRE(img.pixelColor(1, 0) == white);
|
||||
}
|
||||
THEN("Produces white pixel at 1x0")
|
||||
{
|
||||
REQUIRE(img.pixelColor(0, 1) == white);
|
||||
}
|
||||
THEN("Produces white pixel at 1x1")
|
||||
{
|
||||
REQUIRE(img.pixelColor(1, 1) == white);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,88 @@
|
|||
#include <catch2/catch.hpp>
|
||||
#include <string>
|
||||
#include <Magick++/Image.h>
|
||||
#include "identiconpp.hpp"
|
||||
|
||||
using std::string;
|
||||
#include <iostream>
|
||||
|
||||
SCENARIO("ltr_symmetric")
|
||||
{
|
||||
GIVEN("An identicon instance with 2x2 dots")
|
||||
{
|
||||
Identiconpp identicon(2, 2, Identiconpp::algorithm::ltr_symmetric);
|
||||
Magick::Image img;
|
||||
Magick::Color black("#000000ff");
|
||||
Magick::Color white("#ffffffff");
|
||||
|
||||
WHEN("Digest is \"0\"")
|
||||
{
|
||||
img = identicon.generate("0", 2);
|
||||
THEN("Is completely white")
|
||||
{
|
||||
REQUIRE(img.pixelColor(0, 0) == white);
|
||||
REQUIRE(img.pixelColor(0, 1) == white);
|
||||
REQUIRE(img.pixelColor(1, 0) == white);
|
||||
REQUIRE(img.pixelColor(1, 1) == white);
|
||||
}
|
||||
}
|
||||
|
||||
WHEN("Digest is \"f\"")
|
||||
{
|
||||
img = identicon.generate("f", 2);
|
||||
THEN("Is completely black")
|
||||
{
|
||||
REQUIRE(img.pixelColor(0, 0) == black);
|
||||
REQUIRE(img.pixelColor(0, 1) == black);
|
||||
REQUIRE(img.pixelColor(1, 0) == black);
|
||||
REQUIRE(img.pixelColor(1, 1) == black);
|
||||
}
|
||||
}
|
||||
|
||||
WHEN("Digest is \"7\"")
|
||||
{
|
||||
// 0111 = 00
|
||||
// 11
|
||||
img = identicon.generate("7", 2);
|
||||
THEN("Produces white pixel at 0x0")
|
||||
{
|
||||
REQUIRE(img.pixelColor(0, 0) == white);
|
||||
}
|
||||
THEN("Produces white pixel at 1x0")
|
||||
{
|
||||
REQUIRE(img.pixelColor(1, 0) == white);
|
||||
}
|
||||
THEN("Produces black pixel at 1x0")
|
||||
{
|
||||
REQUIRE(img.pixelColor(0, 1) == black);
|
||||
}
|
||||
THEN("Produces black pixel at 1x1")
|
||||
{
|
||||
REQUIRE(img.pixelColor(1, 1) == black);
|
||||
}
|
||||
}
|
||||
|
||||
WHEN("Digest is \"8\"")
|
||||
{
|
||||
// 1000 = 11
|
||||
// 00
|
||||
img = identicon.generate("8", 2);
|
||||
THEN("Produces black pixel at 0x0")
|
||||
{
|
||||
REQUIRE(img.pixelColor(0, 0) == black);
|
||||
}
|
||||
THEN("Produces black pixel at 1x0")
|
||||
{
|
||||
REQUIRE(img.pixelColor(1, 0) == black);
|
||||
}
|
||||
THEN("Produces white pixel at 1x0")
|
||||
{
|
||||
REQUIRE(img.pixelColor(0, 1) == white);
|
||||
}
|
||||
THEN("Produces white pixel at 1x1")
|
||||
{
|
||||
REQUIRE(img.pixelColor(1, 1) == white);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,88 @@
|
|||
#include <catch2/catch.hpp>
|
||||
#include <string>
|
||||
#include <Magick++/Image.h>
|
||||
#include "identiconpp.hpp"
|
||||
|
||||
using std::string;
|
||||
#include <iostream>
|
||||
|
||||
SCENARIO("sigil")
|
||||
{
|
||||
GIVEN("An identicon instance with 2x2 dots")
|
||||
{
|
||||
Identiconpp identicon(2, 2, Identiconpp::algorithm::sigil);
|
||||
Magick::Image img;
|
||||
Magick::Color black("#000000ff");
|
||||
Magick::Color white("#ffffffff");
|
||||
|
||||
WHEN("Digest is \"000\"")
|
||||
{
|
||||
img = identicon.generate("000", 2);
|
||||
THEN("Is completely white")
|
||||
{
|
||||
REQUIRE(img.pixelColor(0, 0) == white);
|
||||
REQUIRE(img.pixelColor(0, 1) == white);
|
||||
REQUIRE(img.pixelColor(1, 0) == white);
|
||||
REQUIRE(img.pixelColor(1, 1) == white);
|
||||
}
|
||||
}
|
||||
|
||||
WHEN("Digest is \"fff\"")
|
||||
{
|
||||
img = identicon.generate("fff", 2);
|
||||
THEN("Is completely black")
|
||||
{
|
||||
REQUIRE(img.pixelColor(0, 0) == black);
|
||||
REQUIRE(img.pixelColor(0, 1) == black);
|
||||
REQUIRE(img.pixelColor(1, 0) == black);
|
||||
REQUIRE(img.pixelColor(1, 1) == black);
|
||||
}
|
||||
}
|
||||
|
||||
WHEN("Digest is \"007\"")
|
||||
{
|
||||
// 0000 0000 0111 = 00
|
||||
// 11
|
||||
img = identicon.generate("007", 2);
|
||||
THEN("Produces white pixel at 0x0")
|
||||
{
|
||||
REQUIRE(img.pixelColor(0, 0) == white);
|
||||
}
|
||||
THEN("Produces white pixel at 1x0")
|
||||
{
|
||||
REQUIRE(img.pixelColor(1, 0) == white);
|
||||
}
|
||||
THEN("Produces black pixel at 1x0")
|
||||
{
|
||||
REQUIRE(img.pixelColor(0, 1) == black);
|
||||
}
|
||||
THEN("Produces black pixel at 1x1")
|
||||
{
|
||||
REQUIRE(img.pixelColor(1, 1) == black);
|
||||
}
|
||||
}
|
||||
|
||||
WHEN("Digest is \"008\"")
|
||||
{
|
||||
// 0000 0000 1000 = 11
|
||||
// 00
|
||||
img = identicon.generate("008", 2);
|
||||
THEN("Produces black pixel at 0x0")
|
||||
{
|
||||
REQUIRE(img.pixelColor(0, 0) == black);
|
||||
}
|
||||
THEN("Produces black pixel at 1x0")
|
||||
{
|
||||
REQUIRE(img.pixelColor(1, 0) == black);
|
||||
}
|
||||
THEN("Produces white pixel at 1x0")
|
||||
{
|
||||
REQUIRE(img.pixelColor(0, 1) == white);
|
||||
}
|
||||
THEN("Produces white pixel at 1x1")
|
||||
{
|
||||
REQUIRE(img.pixelColor(1, 1) == white);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
if(WITH_TESTS)
|
||||
find_package(Catch2 REQUIRED)
|
||||
include(CTest)
|
||||
|
||||
file(GLOB sources_tests src/tests/test_*.cpp)
|
||||
foreach(src ${sources_tests})
|
||||
get_filename_component(bin ${src} NAME_WE)
|
||||
add_executable(${bin} src/tests/main.cpp ${src})
|
||||
target_link_libraries(${bin} ${CMAKE_PROJECT_NAME} Catch2::Catch2)
|
||||
add_test(${bin} ${bin})
|
||||
endforeach()
|
||||
endif()
|
Loading…
Reference in New Issue