ROOT
ROOT project
Loading...
Searching...
No Matches
polynomial_parser_tester.hpp
Go to the documentation of this file.
1#ifndef POLYNOMIAL_PARSER_TESTER_HPP
2#define POLYNOMIAL_PARSER_TESTER_HPP
3
4#include <gtest/gtest.h>
5
7
12class PolynomialParserTester : public ::testing::Test {
13 public:
20 void testParseTokenAsPolyTerm(const std::string& input, const std::function<double(double)>& expected) {
21 std::function<double(double)> result;
22 bool success = PolynomialParser::parseTokenAsPolyTerm(input, result);
23 EXPECT_TRUE(success);
24
25 // Test the resulting function at a few sample points
26 for (double x : {-2.0, -1.0, 0.0, 1.0, 2.0}) {
27 double expected_value = expected(x);
28 double result_value = result(x);
29 EXPECT_DOUBLE_EQ(result_value, expected_value);
30 }
31 }
32
39 void testParse(const std::string& input, const std::function<double(double)>& expected) {
40 PolynomialParser parser(input);
41 std::function<double(double)> result = parser.parse();
42 // Test the resulting function at a few sample points
43 for (double x : {-2.0, -1.0, 0.0, 1.0, 2.0}) {
44 double expected_value = expected(x);
45 double result_value = result(x);
46 EXPECT_DOUBLE_EQ(result_value, expected_value);
47 }
48 }
49};
50
51#endif // POLYNOMIAL_PARSER_TESTER_HPP
Test fixture class for PolynomialParser unit tests.
Definition polynomial_parser_tester.hpp:12
void testParseTokenAsPolyTerm(const std::string &input, const std::function< double(double)> &expected)
Test the parseTokenAsPolyTerm method of PolynomialParser.
Definition polynomial_parser_tester.hpp:20
void testParse(const std::string &input, const std::function< double(double)> &expected)
Test the parse method of PolynomialParser.
Definition polynomial_parser_tester.hpp:39
Parser class for polynomial functions.
Definition function_parser.hpp:110
std::function< double(double)> parse() override
Parse the polynomial function string.
Definition function_parser.cpp:132
static bool parseTokenAsPolyTerm(const std::string &raw_token, std::function< double(double)> &out_term)
Helper static method to parse a token as a polynomial term.
Definition function_parser.cpp:80
Function parser classes for parsing mathematical functions from strings.