Change 2 map to bimap in TextConfigurationSerialization

This commit is contained in:
Filip Sykala 2022-03-08 08:35:26 +01:00
parent 6fdaee3cfe
commit 41a506688a
2 changed files with 76 additions and 16 deletions
tests/libslic3r

View file

@ -2,6 +2,12 @@
#include "libslic3r/Utils.hpp"
// bimap test
#include <string_view>
#include <boost/bimap.hpp>
#include <boost/assign.hpp>
namespace {
TEST_CASE("sort_remove_duplicates", "[utils]") {
@ -38,4 +44,46 @@ TEST_CASE("string_printf", "[utils]") {
}
}
TEST_CASE("Bimap duplicity behavior") {
enum class number {
one = 1,
three = 3,
tri = 3 // ONLY alias
};
using BimapType = boost::bimap<std::string_view, number>;
BimapType bimap = boost::assign::list_of<BimapType::relation>
("one", number::one)
("three", number::three)
("tri", number::tri) // no matter if it is there
;
const auto& to_type = bimap.left;
auto item_number1 = to_type.find("one");
REQUIRE(item_number1 != to_type.end());
CHECK(item_number1->second == number::one);
auto item_number3 = to_type.find("three");
REQUIRE(item_number3 != to_type.end());
CHECK(item_number3->second == number::three);
// to_type.find("tri"); // not in map
const auto &to_name = bimap.right;
auto it1 = to_name.find(number::one);
REQUIRE(it1 != to_name.end());
CHECK(it1->second == "one");
auto it2 = to_name.find(number::three);
REQUIRE(it2 != to_name.end());
CHECK(it2->second == "three");
auto it3 = to_name.find(number::tri);
REQUIRE(it3 != to_name.end());
REQUIRE(number::three == number::tri);
CHECK(it3->second == "three");
}
} // end namespace