Skip to content
Snippets Groups Projects
Commit 34f12ab1 authored by Niklas Hannekotte's avatar Niklas Hannekotte
Browse files

merge

parents 9c83497e 9011d049
No related branches found
No related tags found
No related merge requests found
......@@ -7,6 +7,7 @@ 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 divide( int a, int b) { return a / b; }
int modulo( int a, int b) { return a % b; }
int pop_stack(auto &stack) {
const auto ret{stack.top()};
......@@ -29,6 +30,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(modulo, stack); break;
case '0'...'9': stack.push(c - '0'); break;
}
}
......
......@@ -27,4 +27,8 @@ TEST_CASE( "basic division", "[calc]"){
REQUIRE( evaluate("93/") == 3);
}
TEST_CASE( "Test modulo function", "[calc]") {
REQUIRE( evaluate("11%") == 0 );
REQUIRE( evaluate("32%") == 1 );
REQUIRE( evaluate("51%") == 4 );
}
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