15#ifndef ORTOOLS_MATH_OPT_CPP_ENUMS_TESTING_H_
16#define ORTOOLS_MATH_OPT_CPP_ENUMS_TESTING_H_
23#include "absl/numeric/int128.h"
24#include "absl/strings/string_view.h"
25#include "gtest/gtest.h"
48 using underlying_type_limits =
49 std::numeric_limits<std::underlying_type_t<TypeParam>>;
58 bool found_unspecified =
false;
59 std::vector<TypeParam> found_values;
65 const auto proto_value =
static_cast<Proto
>(i);
66 SCOPED_TRACE(proto_value);
68 const std::optional<TypeParam> cpp_enum =
EnumFromProto(proto_value);
70 found_unspecified =
true;
71 ASSERT_FALSE(cpp_enum.has_value());
73 ASSERT_TRUE(cpp_enum.has_value());
74 found_values.push_back(*cpp_enum);
77 const Proto reconverted_proto_value =
EnumToProto(cpp_enum);
78 EXPECT_EQ(proto_value, reconverted_proto_value);
84 ASSERT_TRUE(found_unspecified);
85 ASSERT_THAT(found_values, ::testing::UnorderedElementsAreArray(
91 const auto cpp_underlying_value =
92 static_cast<std::underlying_type_t<TypeParam>
>(cpp_value);
93 const std::optional<absl::string_view> opt_str_value =
95 ASSERT_TRUE(opt_str_value.has_value())
96 <<
"cpp_value: " << cpp_underlying_value;
98 ::testing::Optional(cpp_value))
99 <<
"cpp_value: " << cpp_underlying_value;
EXPECT_THAT(ComputeInfeasibleSubsystem(model, GetParam().solver_type), IsOkAndHolds(IsInfeasible(true, ModelSubset{ .variable_bounds={{x, ModelSubset::Bounds{.lower=false,.upper=true}}},.linear_constraints={ {c, ModelSubset::Bounds{.lower=true,.upper=false}}}})))
std::optional< absl::string_view > EnumToOptString(E value)
std::optional< typename EnumProto< P >::Cpp > EnumFromProto(P proto_value)
REGISTER_TYPED_TEST_SUITE_P(EnumTest, UnderlyingTypeFits, AllProtoValues, AllCppValuesString)
TYPED_TEST_P(EnumTest, UnderlyingTypeFits)
std::optional< E > EnumFromString(absl::string_view str)
Enum< E >::Proto EnumToProto(std::optional< E > value)
TYPED_TEST_SUITE_P(EnumTest)
static constexpr ProtoEnumIsValid kIsValid
static constexpr Proto kProtoUnspecifiedValue
static absl::Span< const E > AllValues()