Skip to content

Instantly share code, notes, and snippets.

@xealits
Created February 20, 2022 21:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xealits/f07d486b889205cf07cb0c194b68a944 to your computer and use it in GitHub Desktop.
Save xealits/f07d486b889205cf07cb0c194b68a944 to your computer and use it in GitHub Desktop.
C/C++ doctest with separate implementation file and source with tests
#define DOCTEST_CONFIG_IMPLEMENTATION_IN_DLL
#include "doctest.h"
//int factorial(int number) { return number <= 1 ? number : factorial(number - 1) * number; }
int factorial(int number) { return number <= 1 ? 1 : factorial(number - 1) * number; }
TEST_CASE("testing the factorial function") {
CHECK(factorial(0) == 1);
CHECK(factorial(1) == 1);
CHECK(factorial(2) == 2);
CHECK(factorial(3) == 6);
CHECK(factorial(10) == 3628800);
}
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "doctest.h"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment