MCPcopy Create free account
hub / github.com/cel-expr/cel-cpp / TEST_P

Function TEST_P

extensions/formatting_test.cc:65–97  ·  view source on GitHub ↗

Check that formatted floating points are reversible.

Source from the content-addressed store, hash-verified

63
64// Check that formatted floating points are reversible.
65TEST_P(StringFormatLimitsTest, FormatLimits) {
66 google::protobuf::Arena arena;
67 const RuntimeOptions options;
68 ASSERT_OK_AND_ASSIGN(auto builder,
69 CreateStandardRuntimeBuilder(
70 internal::GetTestingDescriptorPool(), options));
71 ASSERT_THAT(
72 RegisterStringFormattingFunctions(builder.function_registry(), options),
73 IsOk());
74
75 ASSERT_OK_AND_ASSIGN(auto runtime, std::move(builder).Build());
76
77 ASSERT_OK_AND_ASSIGN(ParsedExpr expr,
78 Parse(GetParam(), "<input>", ParserOptions{}));
79 ASSERT_OK_AND_ASSIGN(std::unique_ptr<Program> program,
80 ProtobufRuntimeAdapter::CreateProgram(*runtime, expr));
81 Activation activation;
82
83 static_assert(std::numeric_limits<double>::min_exponent == -1021);
84 for (double x : {
85 0x1p-1021,
86 0x3p-1021,
87 std::numeric_limits<double>::epsilon() * 0x1p-3,
88 std::numeric_limits<double>::epsilon() * 0x7p-3,
89 1.1 / 7.0 * 1e-101,
90 1.2 / 7.0 * 1e-101,
91 }) {
92 activation.InsertOrAssignValue("x", DoubleValue(x));
93 ASSERT_OK_AND_ASSIGN(Value value, program->Evaluate(&arena, activation));
94 ASSERT_TRUE(value.Is<BoolValue>());
95 EXPECT_TRUE(value.GetBool().NativeValue());
96 }
97}
98
99TEST(StringFormatLimitsTest, MaxPrecisionOption) {
100 google::protobuf::Arena arena;

Callers

nothing calls this directly

Calls 14

CreateProgramFunction · 0.85
InsertOrAssignValueMethod · 0.80
messageMethod · 0.80
ASSERT_OK_AND_ASSIGNFunction · 0.50
DoubleValueClass · 0.50
NativeValueMethod · 0.45
GetBoolMethod · 0.45
has_valueMethod · 0.45
okMethod · 0.45
EvaluateMethod · 0.45
DebugStringMethod · 0.45

Tested by

no test coverage detected