How to check for zero and negative values? What to do with "std::domain_error"?

FAILED
Test 5
zero_is_an_error

TEST FAILURE

FAILED: REQUIRE_THROWS_AS( collatz_conjecture::steps(0), std::domain_error ) at /tmp/collatz-conjecture/collatz_conjecture_test.cpp:30

1 Like

Hi @ArtyomCoder, welcome to the Exercism Forum and thank you for posting! My name is Jonathan and Iā€™m the Community Manager - great to have you here.

If you could help us out by fleshing out the issue you are having with more detail that would be great. For example, is there a screenshot of your code? What was the issue specifically? What were you trying to do etc?

Currently it is a little tricky to understand what you need help with :slight_smile:

Thanks!

Look at the last two tests:

TEST_CASE("zero_is_an_error")
{
    REQUIRE_THROWS_AS(collatz_conjecture::steps(0), std::domain_error);
}

TEST_CASE("negative_value_is_an_error")
{
    REQUIRE_THROWS_AS(collatz_conjecture::steps(-15), std::domain_error);
}

They expect the function to throw an exception (specifically std::domain_error) if the parameter is non-positive.
For more about exceptions you might want to read Chapter 20: Exceptions at LearnCpp.com.

1 Like

@ArtyomCoder Were you able to solve your problem? Let us know if you need help. Cheers!

1 Like