-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
358 additions
and
401 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,155 +1,149 @@ | ||
#include <catch2/catch_test_macros.hpp> | ||
#include <bar/Bar.hpp> | ||
|
||
#include <gtest/gtest.h> | ||
#include <iostream> | ||
#include <numeric> | ||
#include <string> | ||
|
||
#include <bar/Bar.hpp> | ||
|
||
namespace bar { | ||
|
||
TEST_CASE("Bar free function", "[Bar]") { | ||
SECTION("Int Function") { REQUIRE_NOTHROW(freeFunction(42)); } | ||
SECTION("Int64_t Function") { REQUIRE_NOTHROW(freeFunction(int64_t{42})); } | ||
TEST(BarTest, FreeFunction) { | ||
EXPECT_NO_THROW(freeFunction(42)); | ||
EXPECT_NO_THROW(freeFunction(int64_t{42})); | ||
} | ||
|
||
TEST_CASE("String Vector usage", "[Bar]") { | ||
SECTION("Vector of String Output") { | ||
std::vector<std::string> result; | ||
REQUIRE_NOTHROW(result = stringVectorOutput(8)); | ||
REQUIRE(result.size() == 8); | ||
for (const auto& it : result) { | ||
REQUIRE(it == std::to_string(8)); | ||
} | ||
} | ||
SECTION("Vector of String Input by value") { | ||
std::vector<std::string> data{"1", "2", "3", "4", "5"}; | ||
int size = 0; | ||
REQUIRE_NOTHROW(size = stringVectorInput(data)); | ||
REQUIRE(size == 5); | ||
} | ||
SECTION("Vector of String Input by const ref") { | ||
std::vector<std::string> data{"1", "2", "3", "4", "5"}; | ||
int size = 0; | ||
REQUIRE_NOTHROW(size = stringVectorRefInput(data)); | ||
REQUIRE(size == 5); | ||
TEST(BarTest, StringVectorOutput) { | ||
std::vector<std::string> result; | ||
ASSERT_NO_THROW(result = stringVectorOutput(8)); | ||
EXPECT_EQ(result.size(), 8); | ||
for (const auto& it : result) { | ||
EXPECT_EQ(it, std::to_string(8)); | ||
} | ||
} | ||
|
||
TEST_CASE("String Jagged Array usage", "[Bar]") { | ||
SECTION("Jagged Array of String Output") { | ||
std::vector<std::vector<std::string>> result; | ||
REQUIRE_NOTHROW(result = stringJaggedArrayOutput(8)); | ||
REQUIRE(result.size() == 8); | ||
for (int i = 0; i < result.size(); ++i) { | ||
REQUIRE(i + 1 == result[i].size()); | ||
} | ||
for (int i = 1; i <= result.size(); ++i) { | ||
const auto& inner = result[i - 1]; | ||
for (const auto& it : inner) { | ||
REQUIRE(it == std::to_string(i)); | ||
} | ||
} | ||
} | ||
SECTION("Jagged Array of String Input by value") { | ||
std::vector<std::vector<std::string>> data{{"1", "2", "3"}, {"4", "5"}}; | ||
int size = 0; | ||
REQUIRE_NOTHROW(size = stringJaggedArrayInput(data)); | ||
REQUIRE(size == 2); | ||
} | ||
SECTION("Jagged Array of String Input by const ref") { | ||
std::vector<std::vector<std::string>> data{{"1", "2", "3"}, {"4", "5"}}; | ||
int size = 0; | ||
REQUIRE_NOTHROW(size = stringJaggedArrayRefInput(data)); | ||
REQUIRE(size == 2); | ||
} | ||
TEST(BarTest, StringVectorValueInput) { | ||
const std::vector<std::string> data{"1", "2", "3", "4", "5"}; | ||
int size = 0; | ||
ASSERT_NO_THROW(size = stringVectorInput(data)); | ||
EXPECT_EQ(size, 5); | ||
} | ||
|
||
TEST_CASE("Pair Vector usage", "[Bar]") { | ||
SECTION("Vector of Pair Output") { | ||
std::vector<std::string> result; | ||
REQUIRE_NOTHROW(result = stringVectorOutput(8)); | ||
REQUIRE(result.size() == 8); | ||
for (const auto& it : result) { | ||
REQUIRE(it == std::to_string(8)); | ||
} | ||
} | ||
SECTION("Vector of Pair Input by value") { | ||
std::vector<std::string> data{"1", "2", "3", "4", "5"}; | ||
int size = 0; | ||
REQUIRE_NOTHROW(size = stringVectorInput(data)); | ||
REQUIRE(size == 5); | ||
} | ||
SECTION("Vector of Pair Input by const ref") { | ||
std::vector<std::string> data{"1", "2", "3", "4", "5"}; | ||
int size = 0; | ||
REQUIRE_NOTHROW(size = stringVectorRefInput(data)); | ||
REQUIRE(size == 5); | ||
} | ||
TEST(BarTest, StringVectorRefInput) { | ||
const std::vector<std::string> data{"1", "2", "3", "4", "5"}; | ||
int size = 0; | ||
ASSERT_NO_THROW(size = stringVectorRefInput(data)); | ||
EXPECT_EQ(size, 5); | ||
} | ||
|
||
TEST_CASE("Pair Jagged Array usage", "[Bar]") { | ||
SECTION("Jagged Array of Pair Output") { | ||
std::vector<std::vector<std::pair<int, int>>> result; | ||
REQUIRE_NOTHROW(result = pairJaggedArrayOutput(8)); | ||
REQUIRE(result.size() == 8); | ||
for (int i = 0; i < result.size(); ++i) { | ||
REQUIRE(i + 1 == result[i].size()); | ||
} | ||
for (int i = 1; i <= result.size(); ++i) { | ||
const auto& inner = result[i - 1]; | ||
for (const auto& it : inner) { | ||
REQUIRE(it == std::make_pair(i, i)); | ||
} | ||
} | ||
TEST(BarTest, StringJaggedArrayOutput) { | ||
std::vector<std::vector<std::string>> result; | ||
ASSERT_NO_THROW(result = stringJaggedArrayOutput(8)); | ||
EXPECT_EQ(result.size(), 8); | ||
for (std::size_t i = 0; i < result.size(); ++i) { | ||
EXPECT_EQ(i + 1, result[i].size()); | ||
} | ||
SECTION("Jagged Array of Pair Input by value") { | ||
std::vector<std::vector<std::pair<int, int>>> data{{{1, 1}, {2, 2}, {3, 3}}, {{4, 4}, {5, 5}}}; | ||
int size = 0; | ||
REQUIRE_NOTHROW(size = pairJaggedArrayInput(data)); | ||
REQUIRE(size == 2); | ||
} | ||
SECTION("Jagged Array of Pair Input by const ref") { | ||
std::vector<std::vector<std::pair<int, int>>> data{{{1, 1}, {2, 2}, {3, 3}}, {{4, 4}, {5, 5}}}; | ||
int size = 0; | ||
REQUIRE_NOTHROW(size = pairJaggedArrayRefInput(data)); | ||
REQUIRE(size == 2); | ||
for (std::size_t i = 1; i <= result.size(); ++i) { | ||
const auto& inner = result[i - 1]; | ||
for (const auto& it : inner) { | ||
EXPECT_EQ(it, std::to_string(i)); | ||
} | ||
} | ||
} | ||
|
||
TEST_CASE("Bar static method", "[Bar]") { | ||
SECTION("Int Method") { REQUIRE_NOTHROW(Bar::staticFunction(42)); } | ||
SECTION("Int64_t Method") { REQUIRE_NOTHROW(Bar::staticFunction(int64_t{42})); } | ||
TEST(BarTest, StringJaggedArrayValueInput) { | ||
const std::vector<std::vector<std::string>> data{{"1", "2", "3"}, {"4", "5"}}; | ||
int size = 0; | ||
ASSERT_NO_THROW(size = stringJaggedArrayInput(data)); | ||
EXPECT_EQ(size, 2); | ||
} | ||
|
||
TEST_CASE("Bar::Ctor", "[Bar]") { | ||
SECTION("Default constructor") { | ||
Bar* b = new Bar(); | ||
REQUIRE(b != nullptr); | ||
} | ||
TEST(BarTest, StringJaggedArrayRefInput) { | ||
const std::vector<std::vector<std::string>> data{{"1", "2", "3"}, {"4", "5"}}; | ||
int size = 0; | ||
ASSERT_NO_THROW(size = stringJaggedArrayRefInput(data)); | ||
EXPECT_EQ(size, 2); | ||
} | ||
|
||
SCENARIO("Bar Int", "[Bar]") { | ||
GIVEN("A Bar instance") { | ||
Bar bar; | ||
WHEN("Setting a value") { | ||
REQUIRE_NOTHROW(bar.setInt(42)); | ||
THEN("The value is updated") { REQUIRE(bar.getInt() == 42); } | ||
} | ||
TEST(BarTest, PairVectorOutput) { | ||
std::vector<std::pair<int, int>> result; | ||
ASSERT_NO_THROW(result = pairVectorOutput(8)); | ||
EXPECT_EQ(result.size(), 8); | ||
for (const auto& it : result) { | ||
EXPECT_EQ(it.first, 8); | ||
EXPECT_EQ(it.second, 8); | ||
} | ||
} | ||
|
||
SCENARIO("Bar Int64", "[Bar]") { | ||
GIVEN("A Bar instance") { | ||
Bar bar; | ||
WHEN("Setting a value") { | ||
REQUIRE_NOTHROW(bar.setInt64(31)); | ||
THEN("The value is updated") { REQUIRE(bar.getInt64() == 31); } | ||
TEST(BarTest, PairVectorValueInput) { | ||
const std::vector<std::pair<int, int>> data{{1, 2}, {3, 4}, {5, 6}}; | ||
int size = 0; | ||
ASSERT_NO_THROW(size = pairVectorInput(data)); | ||
EXPECT_EQ(size, 3); | ||
} | ||
|
||
TEST(BarTest, PairVectorRefInput) { | ||
const std::vector<std::pair<int, int>> data{{1, 2}, {3, 4}, {5, 6}}; | ||
int size = 0; | ||
ASSERT_NO_THROW(size = pairVectorRefInput(data)); | ||
EXPECT_EQ(size, 3); | ||
} | ||
|
||
TEST(BarTest, PairJaggedArrayOutput) { | ||
std::vector<std::vector<std::pair<int, int>>> result; | ||
ASSERT_NO_THROW(result = pairJaggedArrayOutput(8)); | ||
EXPECT_EQ(result.size(), 8); | ||
for (std::size_t i = 0; i < result.size(); ++i) { | ||
EXPECT_EQ(i + 1, result[i].size()); | ||
} | ||
for (int i = 1; i <= static_cast<int>(result.size()); ++i) { | ||
const auto& inner = result[i - 1]; | ||
for (const auto& it : inner) { | ||
EXPECT_EQ(it, std::make_pair(i, i)); | ||
} | ||
} | ||
} | ||
|
||
TEST_CASE("Bar::operator()", "[Bar]") { | ||
SECTION("Debug print") { INFO("Bar: " << Bar()()); } | ||
TEST(BarTest, PairJaggedArrayValueInput) { | ||
std::vector<std::vector<std::pair<int, int>>> data{{{1, 1}, {2, 2}, {3, 3}}, {{4, 4}, {5, 5}}}; | ||
int size = 0; | ||
ASSERT_NO_THROW(size = pairJaggedArrayInput(data)); | ||
EXPECT_EQ(size, 2); | ||
} | ||
|
||
TEST(BarTest, PairJaggedArrayRefInput) { | ||
std::vector<std::vector<std::pair<int, int>>> data{{{1, 1}, {2, 2}, {3, 3}}, {{4, 4}, {5, 5}}}; | ||
int size = 0; | ||
ASSERT_NO_THROW(size = pairJaggedArrayRefInput(data)); | ||
EXPECT_EQ(size, 2); | ||
} | ||
|
||
TEST(BarTest, StaticMethods) { | ||
EXPECT_NO_THROW(Bar::staticFunction(42)); | ||
EXPECT_NO_THROW(Bar::staticFunction(int64_t{42})); | ||
} | ||
|
||
TEST(BarTest, Constructor) { | ||
Bar* b = new Bar(); | ||
EXPECT_NE(b, nullptr); | ||
} | ||
|
||
TEST(BarTest, IntMethods) { | ||
Bar bar; | ||
ASSERT_NO_THROW(bar.setInt(42)); | ||
EXPECT_EQ(42, bar.getInt()); | ||
} | ||
|
||
TEST(BarTest, Int64Methods) { | ||
Bar bar; | ||
ASSERT_NO_THROW(bar.setInt64(31)); | ||
EXPECT_EQ(31, bar.getInt64()); | ||
} | ||
|
||
TEST(BarTest, PrintMethod) { | ||
Bar bar; | ||
std::string str(""); | ||
ASSERT_NO_THROW(str = bar()); | ||
EXPECT_EQ("\"Bar\":{\"int\":0,\"int64\":0}", str); | ||
} | ||
|
||
} // namespace bar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.