2 * Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "VISQErrorApproximator.h"
21 #include <gtest/gtest.h>
26 void writeDataToFile(const std::string &path, const std::string &data)
34 void makeTemporaryFile(char *name_template)
36 int fd = mkstemp(name_template);
39 throw std::runtime_error{"mkstemp failed"};
45 TEST(CircleMPQSolverVISQErrorApproximatorTest, verifyResultsTest)
47 static std::string errors_key = "error";
48 static std::string layer_key = "layer_0";
49 static float layer_error = 0.5f;
50 // trivial json with a single layer
51 Json::Value error_data;
52 Json::Value layer_data;
53 layer_data[layer_key] = layer_error;
54 error_data[errors_key].append(layer_data);
56 Json::StreamWriterBuilder builder;
57 auto data = Json::writeString(builder, error_data);
59 char path[] = "VISQErrorApproximator-TEST-XXXXXX";
60 makeTemporaryFile(path);
61 writeDataToFile(path, data);
63 mpqsolver::bisection::VISQErrorApproximator approximator;
64 EXPECT_NO_THROW(approximator.init(path));
65 EXPECT_FLOAT_EQ(approximator.approximate(layer_key), layer_error);
69 TEST(CircleMPQSolverVISQErrorApproximatorTest, verifyResultsTest_NEG)
71 Json::Value error_data;
73 Json::StreamWriterBuilder builder;
74 auto data = Json::writeString(builder, error_data);
76 char path[] = "VISQErrorApproximator-TEST-NEG-XXXXXX";
77 makeTemporaryFile(path);
78 writeDataToFile(path, data);
80 mpqsolver::bisection::VISQErrorApproximator approximator;
81 EXPECT_THROW(approximator.init(path), std::exception);