aboutsummaryrefslogtreecommitdiff
path: root/test.cc
diff options
context:
space:
mode:
Diffstat (limited to 'test.cc')
-rw-r--r--test.cc40
1 files changed, 17 insertions, 23 deletions
diff --git a/test.cc b/test.cc
index a752ad3..0b6f36b 100644
--- a/test.cc
+++ b/test.cc
@@ -6,35 +6,29 @@ class ParserTest : public ::testing::Test {
};
TEST_F(ParserTest, BasicCalc) {
- SimpleParser::Parser p;
-
- EXPECT_EQ(4, p.calculate("2+2"));
- EXPECT_EQ(0, p.calculate("2-2"));
- EXPECT_EQ(42, p.calculate("21*2"));
- EXPECT_EQ(21, p.calculate("42/2"));
+ EXPECT_EQ(4, SimpleParser::calculate("2+2"));
+ EXPECT_EQ(0, SimpleParser::calculate("2-2"));
+ EXPECT_EQ(42, SimpleParser::calculate("21*2"));
+ EXPECT_EQ(21, SimpleParser::calculate("42/2"));
}
TEST_F(ParserTest, OperatorPriority) {
- SimpleParser::Parser p;
-
- EXPECT_EQ(10, p.calculate("2+2*4"));
- EXPECT_EQ(4, p.calculate("2+4/2"));
- EXPECT_EQ(42, p.calculate("5+10*4-3"));
- EXPECT_EQ(17, p.calculate("10+20/2-3"));
- EXPECT_EQ(261, p.calculate("5+2^8"));
- EXPECT_EQ(32768, p.calculate("2*2^16/4"));
- EXPECT_EQ(32772, p.calculate("2*2^16/4+4"));
+ EXPECT_EQ(10, SimpleParser::calculate("2+2*4"));
+ EXPECT_EQ(4, SimpleParser::calculate("2+4/2"));
+ EXPECT_EQ(42, SimpleParser::calculate("5+10*4-3"));
+ EXPECT_EQ(17, SimpleParser::calculate("10+20/2-3"));
+ EXPECT_EQ(261, SimpleParser::calculate("5+2^8"));
+ EXPECT_EQ(32768, SimpleParser::calculate("2*2^16/4"));
+ EXPECT_EQ(32772, SimpleParser::calculate("2*2^16/4+4"));
}
TEST_F(ParserTest, BracketCalc) {
- SimpleParser::Parser p;
-
- EXPECT_EQ(16, p.calculate("(2+2)*4"));
- EXPECT_EQ(10, p.calculate("2+(2*4)"));
- EXPECT_EQ(10, p.calculate("(10-5)*(5-3)"));
- EXPECT_EQ(4, p.calculate("((((2))*((2))))"));
- EXPECT_EQ(37, p.calculate("(((5))*(((((3+2*2)))))+2)"));
- EXPECT_EQ(6.25, p.calculate("2.5*(2+3-(3/2+1))"));
+ EXPECT_EQ(16, SimpleParser::calculate("(2+2)*4"));
+ EXPECT_EQ(10, SimpleParser::calculate("2+(2*4)"));
+ EXPECT_EQ(10, SimpleParser::calculate("(10-5)*(5-3)"));
+ EXPECT_EQ(4, SimpleParser::calculate("((((2))*((2))))"));
+ EXPECT_EQ(37, SimpleParser::calculate("(((5))*(((((3+2*2)))))+2)"));
+ EXPECT_EQ(6.25, SimpleParser::calculate("2.5*(2+3-(3/2+1))"));
}
int main(int argc, char **argv) {