Skip to content

Commit

Permalink
Calc
Browse files Browse the repository at this point in the history
  • Loading branch information
rkatiyar committed Jul 17, 2020
1 parent c7d5498 commit f7c8c12
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
6 changes: 6 additions & 0 deletions project.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,10 @@ namespace dev {
int Project::run() {
return 0;
}

double Project::calc(std::string s)
{
return 0.0;
}

} // namespace dev
2 changes: 2 additions & 0 deletions project.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#pragma once
#include "iproject.h"
#include "string"

namespace dev {

class Project : public IProject {
// IProject interface
public:
int run();
double calc(std::string);
};
} // namespace dev
42 changes: 41 additions & 1 deletion test/project_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,46 @@ class ProjectTest : public ::testing::Test {
TEST_F(ProjectTest, Run) {
ASSERT_EQ(0, project_.run());
}
TEST_F(ProjectTest, BasicOPTestWithInt)
{
EXPECT_EQ(7, project_.calc("5 2 +"));
}
TEST_F(ProjectTest, BasicOPTestWithDouble)
{
EXPECT_EQ(7.8, project_.calc("5.5 2.3 +"));
}
TEST_F(ProjectTest, MissingOperand)
{
EXPECT_EQ(-1, project_.calc("5 +"));
}
TEST_F(ProjectTest, MissingOperator)
{
EXPECT_EQ(-1, project_.calc("5 2"));
}
TEST_F(ProjectTest, EmptyString)
{
EXPECT_EQ(0, project_.calc(""));
}
TEST_F(ProjectTest, DivideByZero)
{
EXPECT_ANY_THROW(project_.calc("7 0 /"));
// try{
// project_.calc("7 0 /");
// }
// catch (const std::string& s)
// {

} // namespace testing
// }
}
TEST_F(ProjectTest, PerformComplexOpeartions)
{
EXPECT_EQ(405, project_.calc("50 31 + 10 5 - * "));
}

TEST_F(ProjectTest, MixingDoubleAndInt)
{
EXPECT_EQ(4.16, project_.calc("12.5 3 / "));
}
}
// namespace testing
} // namespace dev

0 comments on commit f7c8c12

Please sign in to comment.