Skip to content

Next cpp setup #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 26 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
adb3d2e
Test possibilities of Catch2 reporter
hobovsky Jan 22, 2024
a422cfd
CW preprocessor for solution and preloaded snippets
hobovsky Jan 22, 2024
30eac8c
Setup using preprocessed snippets
hobovsky Jan 22, 2024
53a7517
Dockerfile - initial attempt
hobovsky Jan 22, 2024
766d0d9
Organization of snippets
hobovsky Jan 22, 2024
5321634
make scripts runnable in my docker
hobovsky Jan 22, 2024
0ae9f21
Organize examples of migrated kata
hobovsky Jan 22, 2024
eccb2d8
Update locations of files in the original example to my proposed solu…
hobovsky Jan 22, 2024
602b6b3
Add example "Cafeteria"
hobovsky Jan 22, 2024
3f6333a
Remove preprocessor from the Docker image, copy processed files into …
hobovsky Jan 24, 2024
f5d1a4d
Add missing newlines around `<DESCRIBE::>`
hobovsky Jan 24, 2024
18e7a0b
Example with parametrized tests
hobovsky Jan 25, 2024
709f7bb
Example with exceptions
hobovsky Jan 25, 2024
2cea213
Example with crashes
hobovsky Jan 25, 2024
c730982
Add/fix missing includes and macros
hobovsky Jan 25, 2024
3b3cd17
Showcase of assertions and matchers most useful in context of CW
hobovsky Jan 25, 2024
2a1c45a
Update README.md
hobovsky Jan 25, 2024
e022dce
Presentation of results for various kinds of test fixtures
hobovsky Jan 25, 2024
95f6b5c
Remove test_Case_name from test titles
hobovsky Jan 25, 2024
2d17807
Presentation of results for various kinds of test fixtures
hobovsky Jan 25, 2024
9cf36c3
Move preprocessor out of the GTest folder
hobovsky Jan 25, 2024
701a234
Docker image for Catch2
hobovsky Jan 25, 2024
cbfd1df
Reporter - initial version, all events
hobovsky Jan 25, 2024
9c1962f
Examples for organization of tests
hobovsky Jan 25, 2024
273c4c8
Update codewars_reporter.cpp
hobovsky Jan 25, 2024
d6f314d
Fix markers
kazk Nov 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Example with parametrized tests
  • Loading branch information
hobovsky committed Jan 25, 2024
commit 18e7a0b22161786676bc6326e4c0460898c83ad7
1 change: 1 addition & 0 deletions gtest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ The `kata_code` directory contains source file of a kata as produced by the CW p

## Example kata

- `ExampleParametrized` - a set of parametrized/generated tests to evaluate output of the reporter.
- `OriginalExample` - the original example of Google Test tests prepared by kazk. It uses no CW preprocessor markers, and only `preloaded.h` and `solution.cpp` are relevant. `preloaded.cpp` and `solution.h` are also saved, but are irrelevant, and cause no problems when buiding and testing the kata.
- `UniqueInOrder` - a kata which requires separate cpp file and header file for solution, because it requires users to implement two functions: one is a template, and one is a "normal" function. It uses CW preprocessor markers to split submitted solution snippet into two files.
- `Cafeteria` - a kata with no preprocessing markers, with a complex preloaded, where both solution and preloaded are treated as headers, and the cpp part of both gets (apparently) ignored. It also defines custom `operator <<` for the preloaded types, which is used by GTest to present instances in failure messages. To be honest, I am not sure why this example works because I expected it to fail with linker errors caused by standalone definitions of `operator<<`. I need to take a better look.
Empty file.
1 change: 1 addition & 0 deletions gtest/kata_code/ExampleParametrized/include/solution.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bool evenOrOdd(int n);
Empty file.
3 changes: 3 additions & 0 deletions gtest/kata_code/ExampleParametrized/src/solution.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bool evenOrOdd(int n) {
return n % 2 == 0;
}
49 changes: 49 additions & 0 deletions gtest/kata_code/ExampleParametrized/tests/test_solution.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include <gtest/gtest.h>
#include <solution.h>
#include <utility>

namespace {
TEST(FixedTests, test_0) {
EXPECT_EQ(evenOrOdd(0), true) << "evenOrOdd(0)";
}
TEST(FixedTests, test_1) {
EXPECT_EQ(evenOrOdd(1), false) << "evenOrOdd(1)";
}
TEST(FixedTests, test_minus_1) {
EXPECT_EQ(evenOrOdd(-1), false) << "evenOrOdd(-1)";
}

typedef std::pair<int, bool> MyTestCase;
class RandomTests: public ::testing::TestWithParam<MyTestCase> {
public:
int n;
bool exp;

void SetUp() override {
auto param = GetParam();
n = param.first;
exp = param.second;
}
};

static std::vector<MyTestCase> generateTests() {
std::vector<MyTestCase> cases;
for(int i=0; i<5; ++i) {
cases.push_back({ i * 2 + 540, true });
cases.push_back({ i * 2 + 947, false});
}
return cases;
}

TEST_P(RandomTests, PassingCases) {
EXPECT_EQ(evenOrOdd(n), exp) << "evenOrOdd(" << n << ")";
}
TEST_P(RandomTests, FailingCases) {
EXPECT_EQ(evenOrOdd(n), true) << "evenOrOdd(" << n << ")";
}
INSTANTIATE_TEST_SUITE_P(BasicForm,RandomTests,::testing::ValuesIn(generateTests()));
INSTANTIATE_TEST_SUITE_P(WithNameGen,RandomTests,::testing::ValuesIn(generateTests()),
[](const testing::TestParamInfo<MyTestCase>& info) {
return "evenOrOdd_" + std::to_string(info.param.first);
});
}