From 5faf18d03a563d02ce1ffcb6275ff344721fcabd Mon Sep 17 00:00:00 2001 From: Kristofers Solo Date: Sun, 10 Mar 2024 18:58:51 +0200 Subject: [PATCH 1/7] build(ninja): add ninja support - Added ninja build support - Updated readme --- .gitignore | 29 +++++++++++++++++++++++++++++ README.md | 22 ++++++++++++++++------ 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 123517b..c6a6574 100644 --- a/.gitignore +++ b/.gitignore @@ -68,6 +68,35 @@ build # Clang .cache +# clangd +/.clangd/ +/compile_commands.json +/.cache/ + +# Ninja output +.ninja_deps +.ninja_log + +*.pyc +*.obj +*.ilk +/build*/ +/build.ninja +/ninja +/ninja.bootstrap +/build_log_perftest +/canon_perftest +/clparser_perftest +/depfile_parser_perftest +/hash_collision_bench +/ninja_test +/manifest_parser_perftest +/graph.png +/doc/manual.html +/doc/doxygen +*.patch +.DS_Store + input.txt output.txt diff --git a/README.md b/README.md index e2205b6..c3a10e5 100644 --- a/README.md +++ b/README.md @@ -4,11 +4,11 @@ This is a simple C++ project that includes the function for our colleagues to test. The function (i.e., the main function and the subfunctions used in it) is -located in `main_lib.cpp`. +located in `lib.cpp`. ## Additional libraries and executable -Our library `Prep` is concerned with preparation of data prior to the function +Our library `prep` is concerned with preparation of data prior to the function call. `test.cpp` is a single test file that will contain the tests of our colleagues and our own development tests. GTest is used for tests. @@ -18,12 +18,22 @@ and our own development tests. GTest is used for tests. Compilation on Linux requires cmake and CXX compiler (e.g., g++). +### ninja + ```bash -cd src -mkdir build +cmake -Gninja -Bbuild cd build -cmake ../ -cmake --build . +ninja +./main +``` + +### Make + +```bash +cmake -Bbuild +cd build +make +./main ``` Resulting binaries are `build/main` - the program and `build/runtests` to From 6d8e56f962c524fb1c1dc776090a367311543979 Mon Sep 17 00:00:00 2001 From: Jorens Shtekels Date: Sun, 10 Mar 2024 19:19:00 +0200 Subject: [PATCH 2/7] feat[prep]: role, player constructors --- src/lib.cpp | 7 +++++-- src/prep/prep.cpp | 28 ++++++++++++++++++++++++++++ src/prep/prep.hh | 7 +++++++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/lib.cpp b/src/lib.cpp index 75f8cf9..2b58745 100644 --- a/src/lib.cpp +++ b/src/lib.cpp @@ -1,10 +1,13 @@ -#include "lib.hh" - #include "prep/prep.hh" +#include + void run() { Room room1(1, "Room 1", 1710087364, RoomStatus::IN_PROGRESS); Room room2(2, "Room 2", 1710087384, RoomStatus::ENDED); + Role role1({Action::KILL, Action::HEAL}); + std::vector actions = {Action::HEAL}; + Role role2(actions); } int functionToTest(int a) { diff --git a/src/prep/prep.cpp b/src/prep/prep.cpp index 5d4d199..0cd8665 100644 --- a/src/prep/prep.cpp +++ b/src/prep/prep.cpp @@ -2,13 +2,41 @@ #include "timeUtils.hh" +#include + int add(int a, int b) { return a + b; } +Role::Role(std::initializer_list actions) { + for (auto &a : actions) { + this->actions.push_back(a); + } +} + +Role::Role(std::vector actions) { + for (auto &a : actions) { + this->actions.push_back(a); + } +} + +Player::Player(std::string username, Role role, PlayerStatus playerStatus): + username(username), + role(role), + playerStatus(playerStatus) { +} + Room::Room(uint32_t id, std::string title, uint32_t utcTimestampCreatedAt, RoomStatus status): id(id), title(title), status(status) { this->utcTimestampCreatedAt = createUTCTimestamp(utcTimestampCreatedAt); } + +Event::Event(std::string title, uint32_t utcTimestampCreatedAt, uint32_t numberNight, bool isVisible): + title(title), + utcTimestampCreatedAt(createUTCTimestamp(utcTimestampCreatedAt)), + numberNight(numberNight), + isVisible(isVisible) { + this->utcTimestampCreatedAt = createUTCTimestamp(utcTimestampCreatedAt); +} diff --git a/src/prep/prep.hh b/src/prep/prep.hh index 9a8d1aa..eadd4e6 100644 --- a/src/prep/prep.hh +++ b/src/prep/prep.hh @@ -47,12 +47,17 @@ struct Event; struct Role { std::vector actions; + + Role(std::initializer_list actions); + Role(std::vector actions); }; struct Player { std::string username; Role role; PlayerStatus playerStatus; + + Player(std::string username, Role role, PlayerStatus playerStatus); }; struct Room { @@ -71,6 +76,8 @@ struct Event { bool isVisible; std::vector causedBy; std::vector influenced; + + Event(std::string title, uint32_t utcTimestampCreatedAt, uint32_t numberNight, bool isVisible); }; #endif From a9cb8835718c8358bfecd2cb60d6d3dec13baa1d Mon Sep 17 00:00:00 2001 From: Kristofers Solo Date: Sun, 10 Mar 2024 19:39:21 +0200 Subject: [PATCH 3/7] chore(actions): add automated testing --- .github/workflows/test.yml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..e544b59 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,25 @@ +name: Tests +on: + push: + branches: + - main + pull_request: + branches: + - main +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Setup CMake + uses: jwlawson/actions-setup-cmake@v1.14 + - name: Setup Ninja + uses: seanmiddleditch/gha-setup-ninja@master + - name: Configure and build + run: | + cmake -G Ninja -B build + cd build + ninja + - name: Run tests + run: ./build/runtests From 83c2f9fdb5eb5aae8a8452644d2b9a7e448b6cda Mon Sep 17 00:00:00 2001 From: Kristofers Solo Date: Sun, 10 Mar 2024 19:41:53 +0200 Subject: [PATCH 4/7] docs(actions): add "Tests" badge --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c3a10e5..d116405 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Overview +![Tests](https://github.com/jorenchik/testing-spring-2024/actions/workflows/tests.yml/badge.svg) + ## Project This is a simple C++ project that includes the function for our colleagues to @@ -21,7 +23,7 @@ Compilation on Linux requires cmake and CXX compiler (e.g., g++). ### ninja ```bash -cmake -Gninja -Bbuild +cmake -G ninja -B build cd build ninja ./main @@ -30,7 +32,7 @@ ninja ### Make ```bash -cmake -Bbuild +cmake -B build cd build make ./main From 9781fa0cd913216e62b321802853d0a6dc135173 Mon Sep 17 00:00:00 2001 From: Jorens Shtekels Date: Sun, 10 Mar 2024 19:46:40 +0200 Subject: [PATCH 5/7] merge readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d116405..128940f 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Compilation on Linux requires cmake and CXX compiler (e.g., g++). ### ninja ```bash -cmake -G ninja -B build +cmake -Gninja -Bbuild cd build ninja ./main @@ -32,7 +32,7 @@ ninja ### Make ```bash -cmake -B build +cmake -Bbuild cd build make ./main From 30eef4d797414c8dcf11660c3d47583a7e4847bc Mon Sep 17 00:00:00 2001 From: Jorens Shtekels Date: Sun, 10 Mar 2024 19:28:46 +0200 Subject: [PATCH 6/7] feat[prep]: event prohibits and allows other actions --- src/prep/prep.cpp | 34 +++++++++++++++++++++++++++++++++- src/prep/prep.hh | 18 ++++++++++++++++-- 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/src/prep/prep.cpp b/src/prep/prep.cpp index 0cd8665..6ef7707 100644 --- a/src/prep/prep.cpp +++ b/src/prep/prep.cpp @@ -33,10 +33,42 @@ Room::Room(uint32_t id, std::string title, uint32_t utcTimestampCreatedAt, RoomS this->utcTimestampCreatedAt = createUTCTimestamp(utcTimestampCreatedAt); } -Event::Event(std::string title, uint32_t utcTimestampCreatedAt, uint32_t numberNight, bool isVisible): +Event::Event(std::string title, + uint32_t utcTimestampCreatedAt, + uint32_t numberNight, + bool isVisible, + std::vector causedBy, + std::vector prohibits, + std::vector allows): title(title), utcTimestampCreatedAt(createUTCTimestamp(utcTimestampCreatedAt)), numberNight(numberNight), isVisible(isVisible) { this->utcTimestampCreatedAt = createUTCTimestamp(utcTimestampCreatedAt); + for (auto &a : causedBy) { + this->causedBy.push_back(a); + } + for (auto &a : prohibits) { + this->prohibits.push_back(a); + } + for (auto &a : allows) { + this->allows.push_back(a); + } +} + +Event::Event(std::string title, + uint32_t utcTimestampCreatedAt, + uint32_t numberNight, + bool isVisible, + std::initializer_list causedBy, + std::initializer_list prohibits, + std::initializer_list allows): + Event(title, + utcTimestampCreatedAt, + numberNight, + isVisible, + std::vector(causedBy), + std::vector(prohibits), + std::vector(allows)) { + this->utcTimestampCreatedAt = createUTCTimestamp(utcTimestampCreatedAt); } diff --git a/src/prep/prep.hh b/src/prep/prep.hh index eadd4e6..01969c3 100644 --- a/src/prep/prep.hh +++ b/src/prep/prep.hh @@ -75,9 +75,23 @@ struct Event { uint32_t numberNight; bool isVisible; std::vector causedBy; - std::vector influenced; + std::vector prohibits; + std::vector allows; - Event(std::string title, uint32_t utcTimestampCreatedAt, uint32_t numberNight, bool isVisible); + Event(std::string title, + uint32_t utcTimestampCreatedAt, + uint32_t numberNight, + bool isVisible, + std::vector causedBy, + std::vector prohibits, + std::vector allows); + Event(std::string title, + uint32_t utcTimestampCreatedAt, + uint32_t numberNight, + bool isVisible, + std::initializer_list causedBy, + std::initializer_list prohibits, + std::initializer_list allows); }; #endif From 6aea36d05b245414e09e863e0a57df6801f8e5bb Mon Sep 17 00:00:00 2001 From: Jorens Shtekels Date: Sun, 10 Mar 2024 19:41:59 +0200 Subject: [PATCH 7/7] feat[lib]: function placeholder --- src/lib.cpp | 13 +++++++++++++ src/lib.hh | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/src/lib.cpp b/src/lib.cpp index 2b58745..3ab6cb5 100644 --- a/src/lib.cpp +++ b/src/lib.cpp @@ -10,6 +10,19 @@ void run() { Role role2(actions); } +enum VALIDATION_STATUS { + NO_PLAYER, + ROOM_NOT_IN_PROGRESS, + ACTION_PROHIBITED, + ACTION_NOT_ALLOWED, + ACTION_VALID, +}; + +int validateAction( + Player *actor, Action *action, Room *room, std::vector *relatedEvents, Player *target = nullptr) { + return ACTION_VALID; +} + int functionToTest(int a) { return a * 2; } diff --git a/src/lib.hh b/src/lib.hh index a0bce46..fc6a08b 100644 --- a/src/lib.hh +++ b/src/lib.hh @@ -1,2 +1,6 @@ +#include "prep/prep.hh" + void run(); +int validateAction( + Player *actor, Action *action, Room *room, std::vector *relatedEvents, Player *target = nullptr); int functionToTest(int);