Loading CMakeLists.txt +6 −0 Original line number Diff line number Diff line Loading @@ -6,3 +6,9 @@ SET(CMAKE_CXX_FLAGS "-pedantic -Wall -Wextra") # factorial library ADD_LIBRARY(fact STATIC fact.c) # tests FILE(GLOB TEST_SOURCES "tests/*.cpp") ADD_EXECUTABLE(fact_test ${TEST_SOURCES}) TARGET_LINK_LIBRARIES(fact_test fact) TARGET_INCLUDE_DIRECTORIES(fact_test PRIVATE ".") tests/catch.hpp 0 → 100644 +12749 −0 File added.File size exceeds preview limit. View file tests/test-fact.cpp 0 → 100644 +25 −0 Original line number Diff line number Diff line #include "catch.hpp" #include <map> #include "fact.h" SCENARIO("computing factorials") { GIVEN("input is zero") { REQUIRE( factorial(0UL) == 1UL ); } GIVEN("input is non-zero") { using ull_t = unsigned long long; std::map<ull_t, ull_t> table = { { 1UL, 1UL }, { 2UL, 2UL }, { 5UL, 120UL }, { 10UL, 3628800UL }, }; for (const auto& kv : table) { REQUIRE( factorial(kv.first) == kv.second ); } } } tests/test-main.cpp 0 → 100644 +2 −0 Original line number Diff line number Diff line #define CATCH_CONFIG_MAIN #include "catch.hpp" Loading
CMakeLists.txt +6 −0 Original line number Diff line number Diff line Loading @@ -6,3 +6,9 @@ SET(CMAKE_CXX_FLAGS "-pedantic -Wall -Wextra") # factorial library ADD_LIBRARY(fact STATIC fact.c) # tests FILE(GLOB TEST_SOURCES "tests/*.cpp") ADD_EXECUTABLE(fact_test ${TEST_SOURCES}) TARGET_LINK_LIBRARIES(fact_test fact) TARGET_INCLUDE_DIRECTORIES(fact_test PRIVATE ".")
tests/test-fact.cpp 0 → 100644 +25 −0 Original line number Diff line number Diff line #include "catch.hpp" #include <map> #include "fact.h" SCENARIO("computing factorials") { GIVEN("input is zero") { REQUIRE( factorial(0UL) == 1UL ); } GIVEN("input is non-zero") { using ull_t = unsigned long long; std::map<ull_t, ull_t> table = { { 1UL, 1UL }, { 2UL, 2UL }, { 5UL, 120UL }, { 10UL, 3628800UL }, }; for (const auto& kv : table) { REQUIRE( factorial(kv.first) == kv.second ); } } }
tests/test-main.cpp 0 → 100644 +2 −0 Original line number Diff line number Diff line #define CATCH_CONFIG_MAIN #include "catch.hpp"