Skip to content
Snippets Groups Projects
Commit 2ce417a5 authored by Jacek Galowicz's avatar Jacek Galowicz
Browse files

Merge branch 'fix-missing-operands' into 'master'

Fix missing operands

See merge request jg943598/rpn_collab!10
parents 03d344d9 f19337db
No related branches found
No related tags found
No related merge requests found
......@@ -28,6 +28,9 @@ int pop_stack(auto &stack) {
}
void change_stack_state(auto &operation, auto &stack) {
if (stack.size() < 2) {
throw std::out_of_range("The first two digits should be numbers");
}
const auto op_b{pop_stack(stack)};
const auto op_a{pop_stack(stack)};
stack.push(operation(op_a, op_b));
......
......@@ -19,7 +19,8 @@ int main() {
} catch (const std::domain_error& e){
std::cout << "encountered div by zero" << e.what() << "\n";
return -1;
} catch(const std::out_of_range& e){
std::cout << "encountered " << e.what() << "\n";
return -1;
}
}
......@@ -52,15 +52,15 @@ TEST_CASE( "Basic power function test", "[calc]") {
}
TEST_CASE( "Parameters are misaligned and excpetion is thrown", "[calc]") {
// REQUIRE_THROWS( evaluate("40*/") );
// REQUIRE_THROWS( evaluate("14--") );
// REQUIRE_THROWS( evaluate("1+1") );
// REQUIRE_THROWS( evaluate("+11") );
REQUIRE_THROWS( evaluate("40*/") );
REQUIRE_THROWS( evaluate("14--") );
REQUIRE_THROWS( evaluate("1+1") );
REQUIRE_THROWS( evaluate("+11") );
}
TEST_CASE( "Two Operants in a row are detected and exception is thrown", "[calc]") {
//REQUIRE_THROWS( evaluate("11+3-+4") );
//REQUIRE_THROWS( evaluate("11/3*+4") );
REQUIRE_THROWS( evaluate("11+3-+4") );
REQUIRE_THROWS( evaluate("11/3*+4") );
}
TEST_CASE( "Unrecognized characters are detected and exception is thrown", "[calc]") {
......
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