I am trying to work on a C++ tutorial for my college. I tried everything possible, such as importing Catch library in a catch.hpp file, but I always get the error of TEST_CASE not found in scope. Can anyone help me here? I really need to get this to work.
Here's my code,
#include <iostream>
#include <fstream>
#include <string>
std::string FizzBuzz(int number) {
if (number % 3 == 0 && number % 5 == 0) {
return "FizzBuzz";
} else if (number % 3 == 0) {
return "Fizz";
} else if (number % 5 == 0) {
return "Buzz";
} else {
return std::to_string(number);
}
}
int main() {
TEST_CASE("FIZZ if div by 3", "[Fizz]") {
REQUIRE(FizzBuzz(3) == "Fizz");
REQUIRE(FizzBuzz(9) == "Fizz");
REQUIRE(FizzBuzz(15) == "Fizz");
}
TEST_CASE("BUZZ if div by 7", "[Buzz]") {
REQUIRE(FizzBuzz(7) == "Buzz");
REQUIRE(FizzBuzz(14) == "Buzz");
REQUIRE(FizzBuzz(35) == "Buzz");
}
TEST_CASE("FIZZBUZZ if div by 3,7", "[Buzz]") {
REQUIRE(FizzBuzz(21) == "FizzBuzz");
REQUIRE(FizzBuzz(42) == "FizzBuzz");
REQUIRE(FizzBuzz(63) == "FizzBuzz");
}
TEST_CASE("Return Num if div by 3,7", "[ReturnNum]") {
REQUIRE(FizzBuzz(13) == "13");
REQUIRE(FizzBuzz(17) == "17");
REQUIRE(FizzBuzz(24) == "24");
}
return 0;
}
And here is a screenshot of the error: