From ebdf279a5ec06410eea6a11666fa84d743f53a10 Mon Sep 17 00:00:00 2001 From: Quinn Henthorne Date: Tue, 10 Dec 2024 16:49:31 -0500 Subject: [PATCH] Added an example test case --- unit-tests/CMakeLists.txt | 17 +++++++++++++++++ unit-tests/matrix-tests.cpp | 12 ++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 unit-tests/matrix-tests.cpp diff --git a/unit-tests/CMakeLists.txt b/unit-tests/CMakeLists.txt index e69de29..04e3ef4 100644 --- a/unit-tests/CMakeLists.txt +++ b/unit-tests/CMakeLists.txt @@ -0,0 +1,17 @@ +cmake_minimum_required (VERSION 3.11) + +project ("test_driver") + +include(FetchContent) + +FetchContent_Declare( + Catch2 + GIT_REPOSITORY https://github.com/catchorg/Catch2.git + GIT_TAG v3.0.1 # or a later release +) + +FetchContent_MakeAvailable(Catch2) + +add_executable(tests matrix-tests.cpp) + +target_link_libraries(tests PRIVATE Catch2::Catch2WithMain) \ No newline at end of file diff --git a/unit-tests/matrix-tests.cpp b/unit-tests/matrix-tests.cpp new file mode 100644 index 0000000..122dd35 --- /dev/null +++ b/unit-tests/matrix-tests.cpp @@ -0,0 +1,12 @@ +#include + +unsigned int Factorial(unsigned int number) { + return number <= 1 ? number : Factorial(number - 1) * number; +} + +TEST_CASE("Factorials are computed", "[factorial]") { + REQUIRE(Factorial(1) == 1); + REQUIRE(Factorial(2) == 2); + REQUIRE(Factorial(3) == 6); + REQUIRE(Factorial(10) == 3628800); +} \ No newline at end of file