202 std::string expression;
208 const std::vector<TestCase> cases = {
210 {
"@{abs(-5)}",
"5",
false, 0.001 },
211 {
"@{abs(3.14)}",
"3.14",
false, 0.001 },
212 {
"@{sqrt(16)}",
"4",
false, 0.001 },
213 {
"@{sqrt(2)}",
"1.414",
false, 0.01 },
214 {
"@{pow(2, 3)}",
"8",
false, 0.001 },
215 {
"@{pow(3, 2)}",
"9",
false, 0.001 },
218 {
"@{floor(3.7)}",
"3",
false, 0.001 },
219 {
"@{ceil(3.2)}",
"4",
false, 0.001 },
220 {
"@{round(3.7)}",
"4",
false, 0.001 },
221 {
"@{round(3.2)}",
"3",
false, 0.001 },
222 {
"@{round(3.14159, 2)}",
"3.14",
false, 0.001 },
225 {
"@{min(5, 3, 8, 1)}",
"1",
false, 0.001 },
226 {
"@{max(5, 3, 8, 1)}",
"8",
false, 0.001 },
227 {
"@{min(3.5, 3.1)}",
"3.1",
false, 0.001 },
230 {
"@{sum(1, 2, 3, 4)}",
"10",
false, 0.001 },
231 {
"@{avg(2, 4, 6)}",
"4",
false, 0.001 },
234 {
"@{sqrt(-1)}",
"Text @{sqrt(-1)} more text",
true, 0 },
237 for(
const auto& testCase : cases )
241 if( testCase.shouldError )
249 if( testCase.tolerance > 0 )
252 double actualValue = wxStrtod(
result,
nullptr );
253 double expectedValue = wxStrtod( testCase.expected,
nullptr );
254 BOOST_CHECK_CLOSE( actualValue, expectedValue, testCase.tolerance * 100 );
574 std::string expression;
579 const std::vector<TestCase> cases = {
581 {
"@{2 * ${pi} * ${radius}}",
"31.42", 0.01 },
582 {
"@{${pi} * pow(${radius}, 2)}",
"78.54", 0.01 },
583 {
"@{sqrt(pow(3, 2) + pow(4, 2))}",
"5", 0.001 },
586 {
"@{max(abs(-5), sqrt(16), floor(3.7))}",
"5", 0.001 },
587 {
"@{round(avg(1.1, 2.2, 3.3), 1)}",
"2.2", 0.001 },
590 {
"Circle with radius @{${radius}} has area @{format(${pi} * pow(${radius}, 2), 1)}",
591 "Circle with radius 5 has area 78.5", 0 },
594 for(
const auto& testCase : cases )
597 std::string resultStr =
result.ToStdString();
600 if( testCase.tolerance > 0 )
603 std::regex numberRegex( R
"([\d.]+)" );
606 if( std::regex_search( resultStr, match, numberRegex ) )
608 double actualValue = std::stod( match[0].str() );
609 double expectedValue = std::stod( testCase.expected );
610 BOOST_CHECK_CLOSE( actualValue, expectedValue, testCase.tolerance * 100 );
628 std::string largeExpression =
"Result: ";
629 for(
int i = 0; i < 50; ++i )
631 largeExpression +=
"@{" + std::to_string(i) +
" * 2} ";
634 auto start = std::chrono::high_resolution_clock::now();
636 auto end = std::chrono::high_resolution_clock::now();
638 auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(
end - start );
641 BOOST_CHECK( !
result.empty() );
644 BOOST_CHECK_LT( duration.count(), 1000 );
wxString result
Test unit parsing edge cases and error handling.
BOOST_CHECK_EQUAL(result, "25.4")
BOOST_AUTO_TEST_CASE(BasicArithmetic)
Declare the test suite.