< Summary - calculator library documentation coverage (Windows)

Information
Class: D:\a\cpp-cmake-ctest-template\cpp-cmake-ctest-template\src\calculator\header\expressionParser.h
Assembly: Default
File(s): D:\a\cpp-cmake-ctest-template\cpp-cmake-ctest-template\src\calculator\header\expressionParser.h
Line coverage
100%
Covered lines: 7
Uncovered lines: 0
Coverable lines: 7
Total lines: 79
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 9/30/2026 - 3:07:40 AM Line coverage: 100% (7/7) Total lines: 79

File(s)

D:\a\cpp-cmake-ctest-template\cpp-cmake-ctest-template\src\calculator\header\expressionParser.h

#LineLine coverage
 11/**
 2 * @file expressionParser.h
 3 *
 4 * @brief Converts an infix arithmetic expression to postfix (Reverse Polish
 5 *        Notation) and evaluates it, on top of the Calculator functions.
 6 */
 7
 8#ifndef EXPRESSION_PARSER_H
 9#define EXPRESSION_PARSER_H
 10
 11#include <string>
 12
 13namespace Coruh
 14{
 15    namespace Calculator
 16    {
 17        /**
 18            @class ExpressionParser
 19            @brief Parses and evaluates infix arithmetic expressions built from
 20                   +, -, *, /, parentheses, and (possibly decimal) numbers.
 21
 22            This class used to live inline inside the calculatorapp sample
 23            application; it was moved into the library so it can be unit
 24            tested with googletest independently of the interactive app.
 25        */
 126        class ExpressionParser
 27        {
 28        public:
 29            /**
 30             * @brief Converts an infix expression to postfix (RPN) notation
 31             *        using the shunting-yard algorithm.
 32             *
 33             * @param infix The infix expression, e.g. "2 + 3 * (4 - 1)".
 34             * @return The postfix form, tokens separated by single spaces,
 35             *         e.g. "2 3 4 1 - * +".
 36             * @throws std::invalid_argument If the expression is empty, has
 37             *         an unmatched '(' or ')', is missing an operand or an
 38             *         operator, has a number with more than one decimal
 39             *         point or a decimal point with no digits, or contains
 40             *         a character that is not a digit, '.', an operator, a
 41             *         parenthesis, or whitespace.
 42             */
 143            static std::string toPostfix(const std::string& infix);
 44
 45            /**
 46             * @brief Evaluates a postfix (RPN) expression as produced by
 47             *        toPostfix().
 48             *
 49             * @param postfix The postfix expression, tokens separated by
 50             *        whitespace.
 51             * @return The numeric result.
 52             * @throws std::invalid_argument If there are not enough operands
 53             *         for an operator, the expression does not reduce to a
 54             *         single value, or a division by zero is attempted.
 55             */
 156            static double evaluatePostfix(const std::string& postfix);
 57
 58            /**
 59             * @brief Convenience helper: parses and evaluates an infix
 60             *        expression in one call (toPostfix() + evaluatePostfix()).
 61             *
 62             * @param infix The infix expression.
 63             * @return The numeric result.
 64             * @throws std::invalid_argument See toPostfix() and
 65             *         evaluatePostfix().
 66             */
 167            static double evaluateInfix(const std::string& infix);
 68
 69        private:
 70            /// True for '+', '-', '*', '/'.
 171            static bool isOperator(char c);
 72
 73            /// Operator precedence: 2 for '*','/'; 1 for '+','-'; 0 otherwise.
 174            static int precedence(char c);
 75        };
 76    }
 77}
 78
 79#endif // EXPRESSION_PARSER_H

Methods/Properties