Skip to content

Instantly share code, notes, and snippets.

@leira
Created September 24, 2018 08:27
Show Gist options
  • Select an option

  • Save leira/a3cba2cb66f9f46c4b61daa228ac9b0e to your computer and use it in GitHub Desktop.

Select an option

Save leira/a3cba2cb66f9f46c4b61daa228ac9b0e to your computer and use it in GitHub Desktop.
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "doctest.h"
using ll = long long;
bool isPrime(ll n)
{
if (n == 1) return false;
auto ub = std::sqrt(n);
for (int i = 2; i <= ub; i += 1) {
if ((n % i) == 0) return false;
}
return true;
}
TEST_CASE("Check primes") {
for (ll i : {2, 3, 5, 7, 1117, 7639}) {
CHECK(isPrime(i));
}
for (ll i : {1, 4, 6, 9, 1118, 7631}) {
CHECK_FALSE(isPrime(i));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment