8#include <gtest/gtest.h>
44 this->set_input(
"2x^2 - 8");
46 token = this->lexer.next();
48 ASSERT_EQ(token.
value, 2.0);
50 token = this->lexer.next();
52 ASSERT_EQ(token.
value, 0.0);
54 token = this->lexer.next();
56 ASSERT_EQ(token.
value, 0.0);
58 token = this->lexer.next();
60 ASSERT_EQ(token.
value, 2.0);
62 token = this->lexer.next();
64 ASSERT_EQ(token.
value, 0.0);
66 token = this->lexer.next();
68 ASSERT_EQ(token.
value, 8.0);
70 token = this->lexer.next();
72 ASSERT_EQ(token.
value, 0.0);
79 this->set_input(
"1.11x^2.22");
81 token = this->lexer.next();
83 ASSERT_EQ(token.
value, 1.11);
85 token = this->lexer.next();
87 ASSERT_EQ(token.
value, 0.0);
89 token = this->lexer.next();
91 ASSERT_EQ(token.
value, 0.0);
93 token = this->lexer.next();
95 ASSERT_EQ(token.
value, 2.22);
97 token = this->lexer.next();
99 ASSERT_EQ(token.
value, 0.0);
106 this->set_input(
"2*8/4^3 x^ 2^2");
108 token = this->lexer.next();
110 ASSERT_EQ(token.
value, 64.0);
112 token = this->lexer.next();
114 ASSERT_EQ(token.
value, 0.0);
116 token = this->lexer.next();
118 ASSERT_EQ(token.
value, 0.0);
120 token = this->lexer.next();
122 ASSERT_EQ(token.
value, 4.0);
124 token = this->lexer.next();
126 ASSERT_EQ(token.
value, 0.0);
132 this->set_input(
"x"); ASSERT_EQ(this->parser.parse_monomial(),
emth::Monomial(1, 1));
133 this->set_input(
"2x"); ASSERT_EQ(this->parser.parse_monomial(),
emth::Monomial(2, 1));
134 this->set_input(
"x^2"); ASSERT_EQ(this->parser.parse_monomial(),
emth::Monomial(1, 2));
135 this->set_input(
"2x^2"); ASSERT_EQ(this->parser.parse_monomial(),
emth::Monomial(2, 2));
140TEST_F(
EParserTest, Compound) {this->set_input(
"2x^2 - 2x + 2"); ASSERT_EQ(this->parser.parse_polynomial(),
emth::Polynomial({emth::Monomial(2, 2), emth::Monomial(-2, 1), emth::Monomial(2, 0)}));}
145 this->set_input(
"-x"); ASSERT_EQ(this->parser.parse_monomial(),
emth::Monomial(-1, 1));
146 this->set_input(
"--x"); ASSERT_EQ(this->parser.parse_monomial(),
emth::Monomial(1, 1));
147 this->set_input(
"---x"); ASSERT_EQ(this->parser.parse_monomial(),
emth::Monomial(-1, 1));
148 this->set_input(
"-+x"); ASSERT_EQ(this->parser.parse_monomial(),
emth::Monomial(-1, 1));
149 this->set_input(
"+-+x"); ASSERT_EQ(this->parser.parse_monomial(),
emth::Monomial(-1, 1));
155 this->set_input(
"(1)<···(0)<···_x_···>^{2}"); ASSERT_EQ(this->parser.parse_monomial(),
emth::Monomial(10, 2));
156 this->set_input(
"(1)<···(0)<···_x_···>^{2} - (0)<···(5)<···_x_···>^{2}"); ASSERT_EQ(this->parser.parse_polynomial(),
emth::Polynomial({emth::Monomial(5, 2)}));
169int main(
int argc,
char** argv) {testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();}
Class that provides a test fixture for the test cases.
emthp::Parser parser
The parser object on which to perform the tests on.
void set_input(const std::string &input)
Function for setting the input to the lexer and parser objects.
emthp::Lexer lexer
The lexer object on which to perform the tests on.
EParserTest()
Standalone constructor for the EParserTest class.
Class for representing and operating monomials.
Class for representing and operating polynomials.
Class that works as a token supplier for the Parser class.
Class that wraps a std::string and parses it as a Monomial or as a Polynomial.
This is the main header file for the equation parser.
int main()
The main function that creates the efc::Application instance, runs it and when it finishes it deletes...
@ T_MINUS
Minus sign type.
@ T_EXPONENT
Exponent sign type.
Struct for representing a token as a type and a value.
double value
The token's numerical value as a double.
TokenType type
The token's type as a TokenType.
TEST_F(EParserTest, Lexer)