diff options
author | HampusM <hampus@hampusmat.com> | 2022-03-19 17:31:19 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-06-13 17:56:56 +0200 |
commit | cef38fcb5cf2e1b091ebb40397f376f05d211d1e (patch) | |
tree | 14dbad22851da6dd8f7c2a0c7e1f2ed95c0699e9 /test | |
parent | 592244455cabfd5891471bb29fd84fcb85cc41e4 (diff) |
test: add normalize_lambda unit test
Diffstat (limited to 'test')
-rw-r--r-- | test/CMakeLists.txt | 1 | ||||
-rw-r--r-- | test/function.test.cpp | 52 |
2 files changed, 53 insertions, 0 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index ac84f42..243c1dd 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,6 +1,7 @@ file(GLOB SOURCES main.cpp string_matrix.test.cpp + "function.test.cpp" ${CMAKE_SOURCE_DIR}/src/engine/data/vector2.cpp ${CMAKE_SOURCE_DIR}/src/engine/data/bounds.cpp ${CMAKE_SOURCE_DIR}/src/engine/graphics/string_matrix.cpp diff --git a/test/function.test.cpp b/test/function.test.cpp new file mode 100644 index 0000000..9aca0eb --- /dev/null +++ b/test/function.test.cpp @@ -0,0 +1,52 @@ +#include "util/function.hpp" + +#include <cstdint> +#include <doctest/doctest.h> + +TEST_CASE("normalize_lamda") +{ + SUBCASE("Can return a function that returns a int") + { + const int number = 58; + + CHECK(normalize_lambda( + [number]() + { + return number; + })() == number); + } + + SUBCASE("Can preserve object state") + { + class Book + { + public: + Book() noexcept = default; + + void read_page() noexcept + { + _pages_read++; + } + + [[nodiscard]] uint32_t pages_read() const noexcept + { + return _pages_read; + } + + private: + uint32_t _pages_read{0U}; + }; + + auto book = Book(); + + book.read_page(); + book.read_page(); + book.read_page(); + + CHECK(normalize_lambda( + [book]() + { + return book.pages_read(); + })() == 3); + } +} |