Skip to content
Snippets Groups Projects
Commit 61c531da authored by Stauder, Lucas's avatar Stauder, Lucas
Browse files

improve sieve tests

parent 49add3cb
Branches master
No related tags found
No related merge requests found
......@@ -4,7 +4,19 @@ extern "C" {
#include <gtest/gtest.h>
TEST(sieve_of_eratosthenes, primes) {
bool primes[1000];
bool primes[1001];
// Set some entries explicitely to the wrong values to check if the
// function doesn't expect a initialization with false or true.
primes[0] = true;
primes[1] = true;
primes[2] = false,
primes[3] = false;
// the function should not touch this value, as it is called with
// size = 1000
primes[1000] = true;
sieve_of_eratosthenes(primes, 1000);
EXPECT_TRUE(primes[2]);
EXPECT_TRUE(primes[3]);
......@@ -19,6 +31,7 @@ TEST(sieve_of_eratosthenes, primes) {
EXPECT_TRUE(primes[997]);
EXPECT_TRUE(primes[947]);
EXPECT_FALSE(primes[0]);
EXPECT_FALSE(primes[1]);
EXPECT_FALSE(primes[4]);
EXPECT_FALSE(primes[15]);
......@@ -27,4 +40,7 @@ TEST(sieve_of_eratosthenes, primes) {
EXPECT_FALSE(primes[33]);
EXPECT_FALSE(primes[998]);
EXPECT_FALSE(primes[999]);
// check if this entry wasn't touched
EXPECT_TRUE(primes[1000]);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment