summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt33
-rw-r--r--inc/fact.h6
-rw-r--r--src/fact/fact.cc7
-rw-r--r--tests/tests.cc11
4 files changed, 52 insertions, 5 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 505517f..03f0ca3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,13 +1,36 @@
-cmake_minimum_required(VERSION 3.11)
+cmake_minimum_required(VERSION 3.5)
project(risc_vector)
+# cpp standard
set(CMAKE_CXX_STANDARD 17)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+
set(CMAKE_CXX_COMPILER "g++")
-set(SRCDIR src)
-set(PYTHON_VERSION 3.10)
+# header files
+include_directories(
+ ${PROJECT_SOURCE_DIR}/inc
+)
+
+# gather source files
+file(GLOB_RECURSE SRCS "src/*.cc")
+list(REMOVE_ITEM SRCS "${CMAKE_CURRENT_SOURCE_DIR}/src/rv.cc")
+
+# find python3 components
find_package(Python3 COMPONENTS Development REQUIRED)
-add_executable(${PROJECT_NAME} ${SRCDIR}/rv.cc)
+# binary executable
+add_executable(${PROJECT_NAME} ${SRCS} src/rv.cc)
+target_link_libraries(${PROJECT_NAME} PRIVATE Python3::Python)
+
+find_package(Catch2 REQUIRED)
+set(TESTDIR tests)
+
+# test executable
+add_executable(tests ${SRCS} ${TESTDIR}/tests.cc)
+target_link_libraries(tests PRIVATE Catch2::Catch2 PRIVATE Python3::Python)
-target_link_libraries(${PROJECT_NAME} Python3::Python)
+# test discovery
+include(CTest)
+include(Catch)
+catch_discover_tests(tests)
diff --git a/inc/fact.h b/inc/fact.h
new file mode 100644
index 0000000..de1220a
--- /dev/null
+++ b/inc/fact.h
@@ -0,0 +1,6 @@
+#ifndef FACT_H
+#define FACT_H
+
+unsigned int factorial(unsigned int);
+
+#endif
diff --git a/src/fact/fact.cc b/src/fact/fact.cc
new file mode 100644
index 0000000..026ad94
--- /dev/null
+++ b/src/fact/fact.cc
@@ -0,0 +1,7 @@
+#include "fact.h"
+
+unsigned int
+factorial(unsigned int number)
+{
+ return number <= 1 ? number : factorial(number-1)*number;
+}
diff --git a/tests/tests.cc b/tests/tests.cc
new file mode 100644
index 0000000..d866172
--- /dev/null
+++ b/tests/tests.cc
@@ -0,0 +1,11 @@
+#define CATCH_CONFIG_MAIN
+#include "catch2/catch.hpp"
+#include "fact.h"
+
+TEST_CASE( "factorials are computed", "[factorial]")
+{
+ REQUIRE( factorial(1) == 1 );
+ REQUIRE( factorial(2) == 2 );
+ REQUIRE( factorial(3) == 6 );
+ REQUIRE( factorial(10) == 3628800 );
+}