Skip to content
Snippets Groups Projects
Commit 475ac26b authored by Malte Harms's avatar Malte Harms
Browse files

Merge remote-tracking branch 'upstream/master'

parents a7026369 900a3e08
No related branches found
No related tags found
No related merge requests found
......@@ -9,6 +9,7 @@ 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 pow( int a, int b) { return std::pow(a, b); }
int modulo( int a, int b) { return a % b; }
int pop_stack(auto &stack) {
const auto ret{stack.top()};
......@@ -32,6 +33,7 @@ int evaluate(const std::string &s) {
case '*': change_stack_state(multiply, stack); break;
case '/': change_stack_state(divide, stack); break;
case '^': change_stack_state(pow, stack); break;
case '%': change_stack_state(modulo, stack); break;
case '0'...'9': stack.push(c - '0'); break;
}
}
......
......@@ -12,3 +12,9 @@ TEST_CASE( "pow function works", "[calc]") {
REQUIRE( evaluate("43^") == 64 );
REQUIRE_FALSE( evaluate("11^") == 2);
}
TEST_CASE( "Test modulo function", "[calc]") {
REQUIRE( evaluate("11%") == 0 );
REQUIRE( evaluate("32%") == 1 );
REQUIRE( evaluate("51%") == 0 );
}
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