ROOT
ROOT project
Loading...
Searching...
No Matches
function_parser_base_tester.hpp
Go to the documentation of this file.
1#ifndef FUNCTION_PARSER_BASE_TESTER_HPP
2#define FUNCTION_PARSER_BASE_TESTER_HPP
3
4#include <gtest/gtest.h>
5
7
12class FunctionParserBaseTester : public ::testing::Test {
13 public:
20 void testIsPolynomial(const std::string& input, bool expected) {
21 bool result = FunctionParserBase::isPolynomial(input);
22 EXPECT_EQ(result, expected);
23 }
24
31 void testIsTrigonometric(const std::string& input, bool expected) {
32 bool result = FunctionParserBase::isTrigonometric(input);
33 EXPECT_EQ(result, expected);
34 }
35
43 void testIcontains(const std::string& hay, const std::string& needle, bool expected) {
44 bool result = FunctionParserBase::icontains(hay, needle);
45 EXPECT_EQ(result, expected);
46 }
47
54 void testRemoveSpaces(const std::string& input, const std::string& expected) {
55 std::string result = FunctionParserBase::removeSpaces(input);
56 EXPECT_EQ(result, expected);
57 }
58
65 void testSplitSignTokens(const std::string& input, const std::vector<std::string>& expected) {
66 std::vector<std::string> result = FunctionParserBase::splitSignTokens(input);
67 EXPECT_EQ(result, expected);
68 }
69
76 void testParseOptionalCoefficient(const std::string& input, const std::pair<double, std::string>& expected) {
77 std::pair<double, std::string> result = FunctionParserBase::parseOptionalCoefficient(input);
78 EXPECT_EQ(result, expected);
79 }
80
89 void testParseFunction(const std::string& input, const std::function<double(double)>& expected, double test_value,
90 double tolerance) {
91 std::function<double(double)> result = FunctionParserBase::parseFunction(input);
92 double result_value = result(test_value);
93 double expected_value = expected(test_value);
94 EXPECT_NEAR(result_value, expected_value, tolerance);
95 }
96};
97
98#endif // FUNCTION_PARSER_BASE_TESTER_HPP
Test fixture class for FunctionParserBase unit tests.
Definition function_parser_base_tester.hpp:12
void testSplitSignTokens(const std::string &input, const std::vector< std::string > &expected)
Test the splitSignTokens method of FunctionParserBase.
Definition function_parser_base_tester.hpp:65
void testIsTrigonometric(const std::string &input, bool expected)
Test the isTrigonometric method of FunctionParserBase.
Definition function_parser_base_tester.hpp:31
void testIsPolynomial(const std::string &input, bool expected)
Test the parseMethod method of ReaderBase.
Definition function_parser_base_tester.hpp:20
void testRemoveSpaces(const std::string &input, const std::string &expected)
Test the removeSpaces method of FunctionParserBase.
Definition function_parser_base_tester.hpp:54
void testIcontains(const std::string &hay, const std::string &needle, bool expected)
Test the icontains method of FunctionParserBase.
Definition function_parser_base_tester.hpp:43
void testParseFunction(const std::string &input, const std::function< double(double)> &expected, double test_value, double tolerance)
Test the parseFunction method of FunctionParserBase.
Definition function_parser_base_tester.hpp:89
void testParseOptionalCoefficient(const std::string &input, const std::pair< double, std::string > &expected)
Test the parseOptionalCoefficient method of FunctionParserBase.
Definition function_parser_base_tester.hpp:76
static std::pair< double, std::string > parseOptionalCoefficient(const std::string &token)
Helper static method to parse an optional coefficient from a token.
Definition function_parser.cpp:66
static std::function< double(double)> parseFunction(const std::string &function_str)
Static method to parse a function string and return a callable function.
Definition function_parser.cpp:234
static std::string removeSpaces(const std::string &function_str)
Helper static method to remove all whitespace from a string.
Definition function_parser.cpp:37
static bool isTrigonometric(const std::string &expression)
Static method to check if the expression is a trigonometric function.
Definition function_parser.cpp:22
static std::vector< std::string > splitSignTokens(const std::string &expr_no_ws)
Helper static method to split an expression into tokens based on sign characters.
Definition function_parser.cpp:48
static bool isPolynomial(const std::string &expression)
Static method to check if the expression is a polynomial.
Definition function_parser.cpp:15
static bool icontains(const std::string &hay, const std::string &needle)
Helper static method to check if a string contains a substring (case-insensitive).
Definition function_parser.cpp:29
Function parser classes for parsing mathematical functions from strings.