Skip to content
Snippets Groups Projects
Commit 9d930dab authored by Damian Puente's avatar Damian Puente
Browse files

merged

parents d4887873 1c945b35
No related branches found
No related tags found
No related merge requests found
......@@ -2,10 +2,12 @@
#include <stack>
#include <stdexcept>
#include <cmath>
int plus( int a, int b) { return a + b; }
int minus( int a, int b) { return a - b; }
int multiply(int a, int b) { return a * b; }
int power( int a, int b) { return std::pow(a, b); }
int modulo( int a, int b) { return a % b; }
int divide( int a, int b) {
if(b == 0) {
......@@ -35,6 +37,7 @@ int evaluate(const std::string &s) {
case '-': change_stack_state(minus, stack); break;
case '*': change_stack_state(multiply, stack); break;
case '/': change_stack_state(divide, stack); break;
case '^': change_stack_state(power, stack); break;
case '%': change_stack_state(modulo, stack); break;
case '0'...'9': stack.push(c - '0'); break;
default:
......
......@@ -7,6 +7,12 @@ TEST_CASE( "some example calculations", "[calc]") {
REQUIRE( evaluate("12+2-3*") == 3 );
}
TEST_CASE( "pow function works", "[calc]") {
REQUIRE( evaluate("22^") == 4 );
REQUIRE( evaluate("43^") == 64 );
REQUIRE( evaluate("11^") == 1);
}
TEST_CASE( "basic addition", "[calc]"){
REQUIRE( evaluate("55+") == 10);
REQUIRE( evaluate("34+") == 7);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment