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

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

Fix missing operands

See merge request dp173259/rpn_collab!5
parents 22c9e2ff dfd0dee2
No related branches found
No related tags found
No related merge requests found
......@@ -4,3 +4,4 @@ result
calc
fuzz_calc
unit_test
core.*
\ No newline at end of file
......@@ -24,7 +24,7 @@ int pop_stack(auto &stack) {
void change_stack_state(auto &operation, auto &stack) {
if (stack.size() < 2) {
throw std::invalid_argument("The first two digits should be numbers");
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)};
......
......@@ -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;
}
}
......@@ -38,3 +38,32 @@ TEST_CASE( "Test modulo function", "[calc]") {
REQUIRE( evaluate("32%") == 1 );
REQUIRE( evaluate("51%") == 0 );
}
TEST_CASE( "division by zero is detected and exception is thrown", "[calc]") {
REQUIRE_THROWS( evaluate("40/") );
REQUIRE_THROWS( evaluate("00/") );
REQUIRE_THROWS( evaluate("90/") );
}
TEST_CASE( "Basic power function test", "[calc]") {
REQUIRE( evaluate("22^") == 4 );
REQUIRE( evaluate("43^") == 64 );
REQUIRE( evaluate("25^") == 32 );
}
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") );
}
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") );
}
TEST_CASE( "Unrecognized characters are detected and exception is thrown", "[calc]") {
REQUIRE_THROWS( evaluate("11+3?4") );
REQUIRE_THROWS( evaluate("1F+") );
}
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