Skip to content

Commit

Permalink
test : vector_utils contains() & contains_that()
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaslepoix committed Dec 15, 2022
1 parent 3e26ba6 commit c33c975
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/domain/board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class Board : public Entity, public Visitable<Board, EntityVisitor> {
[[nodiscard]] std::unique_ptr<Board> build();

private:
Params params;
PlaneSpace<std::vector<std::unique_ptr<Polygon>>> polygons;
AxisSpace<std::vector<std::unique_ptr<MeshlinePolicy>>> line_policies;
};
Expand Down
2 changes: 0 additions & 2 deletions src/domain/geometrics/point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

namespace domain {

using namespace std;

//******************************************************************************
Point::Point(Coord x, Coord y) noexcept
: x(x)
Expand Down
62 changes: 60 additions & 2 deletions test/unit/utils/test_vector_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@
#include "utils/vector_utils.hpp"

/// @test template<typename T> std::vector<T*> create_view(
/// std::vector<std::unique_ptr<T>> const& original)
/// std::vector<std::unique_ptr<T>> const& original) noexcept
/// @test template<typename T> std::vector<std::unique_ptr<T const>> from_init_list(
/// std::initializer_list<T> const& original)
/// std::initializer_list<T> const& original) noexcept
/// @test template<typename T> bool contains(
/// std::vector<T> const& vector,
// T const& value) noexcept
/// @test template<typename T, typename P> bool contains_that(
/// std::vector<T> const& vector,
/// P&& predicate) noexcept
///*****************************************************************************

//******************************************************************************
Expand Down Expand Up @@ -68,3 +74,55 @@ std::initializer_list<T> const& original)", "[vector_utils]") {
}
}
}

//******************************************************************************
SCENARIO("template<typename T> bool contains(std::vector<T> const& vector, T const& value) noexcept", "[vector_utils]") {
GIVEN("A vector of strings") {
std::vector<std::string> a;
a.emplace_back("aa");
a.emplace_back("b");
a.emplace_back("333");
a.emplace_back("dd");
WHEN("Looking for a string that is in the vector") {
THEN("Should return true") {
REQUIRE(contains(a, std::string("b")));
}
}

WHEN("Looking for a string that is not in the vector") {
THEN("Should return false") {
REQUIRE_FALSE(contains(a, std::string("ccc")));
}
}
}
}

//******************************************************************************
SCENARIO("template<typename T, typename P> bool contains_that(std::vector<T> const& vector, P&& predicate) noexcept", "[vector_utils]") {
GIVEN("A vector of unique_ptr to strings") {
std::vector<std::unique_ptr<std::string>> a;
a.emplace_back(std::make_unique<std::string>("aa"));
a.emplace_back(std::make_unique<std::string>("b"));
a.emplace_back(std::make_unique<std::string>("333"));
a.emplace_back(std::make_unique<std::string>("dd"));
WHEN("Looking for a predicate that matches a string in the vector") {
THEN("Should return true") {
std::string b("b");
REQUIRE(contains_that(a,
[&b](std::unique_ptr<std::string> const& str) {
return str->c_str() == b.c_str();
}));
}
}

WHEN("Looking for a predicate that does not match any string in the vector") {
THEN("Should return false") {
std::string b("ccc");
REQUIRE_FALSE(contains_that(a,
[&b](std::unique_ptr<std::string> const& str) {
return str->c_str() == b.c_str();
}));
}
}
}
}

0 comments on commit c33c975

Please sign in to comment.