feat: provide and use a common calling interface to all chapter tests

This commit is contained in:
Michael Mandl 2023-10-21 12:31:23 +02:00
parent dfaee89d56
commit 89d1469088
Signed by: mandlm
GPG key ID: 4AA25D647AA54CC7
13 changed files with 52 additions and 26 deletions

View file

@ -1 +1,2 @@
add_subdirectory(interface)
add_subdirectory(chapter_02)

View file

@ -1,4 +1,8 @@
add_library(chapter_02 src/initlist.cpp src/null.cpp src/constexp.cpp
src/ifswitch.cpp)
target_compile_features(chapter_02 PUBLIC cxx_std_20)
target_include_directories(chapter_02 PUBLIC include)
target_link_libraries(chapter_02 PUBLIC chapter_interface)

View file

@ -1,5 +1,8 @@
#pragma once
namespace constexp {
void test();
#include "chapter_interface.h"
class ConstExpTest : public ChapterTest {
public:
virtual void test() override;
};

View file

@ -1,7 +1,8 @@
#pragma once
namespace ifswitch {
void test();
#include "chapter_interface.h"
class IfswitchTest : public ChapterTest {
public:
virtual void test() override;
};

View file

@ -1,5 +1,8 @@
#pragma once
namespace initlist {
void test();
#include "chapter_interface.h"
class InitListTest : public ChapterTest {
public:
virtual void test() override;
};

View file

@ -1,5 +1,8 @@
#pragma once
namespace null {
void test();
#include "chapter_interface.h"
class NullTest : public ChapterTest {
public:
virtual void test() override;
};

View file

@ -9,7 +9,7 @@ constexpr unsigned int fibonacci(const unsigned int n) {
return fibonacci(n - 2) + fibonacci(n - 1);
}
void constexp::test() {
void ConstExpTest::test() {
std::cout << "Fibonacci(10): ";
for (const unsigned int n : {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) {
std::cout << fibonacci(n) << " ";

View file

@ -5,7 +5,7 @@
#include "ifswitch.h"
void ifswitch::test() {
void IfswitchTest::test() {
std::vector<uint32_t> vec = {1, 2, 3, 4};
if (auto it = std::find(vec.begin(), vec.end(), 23); it != vec.end()) {

View file

@ -10,7 +10,7 @@ public:
InitList(std::initializer_list<unsigned int> list) : _list(list) {}
};
void initlist::test() {
void InitListTest::test() {
InitList initList{1, 2, 3, 4, 5};

View file

@ -7,7 +7,7 @@ void call_test(char *) { std::cout << "call_test(char *) called" << std::endl; }
void call_test(int) { std::cout << "call_test(int) called" << std::endl; }
void null::test() {
void NullTest::test() {
if (std::is_same<decltype(NULL), decltype(0)>::value) {
std::cout << "NULL == 0" << std::endl;
}

View file

@ -0,0 +1,3 @@
add_library(chapter_interface INTERFACE)
target_compile_features(chapter_interface INTERFACE cxx_std_20)
target_include_directories(chapter_interface INTERFACE include)

View file

@ -0,0 +1,7 @@
#pragma once
class ChapterTest {
public:
virtual ~ChapterTest() = default;
virtual void test() = 0;
};