diff --git a/src/sieve_of_eratosthenes.test.cpp b/src/sieve_of_eratosthenes.test.cpp index 0abe5b60a6e682521152efdd140d35e0664e43af..6c532b8cf3965c7de4c3626cfe9a9205c24d54b5 100644 --- a/src/sieve_of_eratosthenes.test.cpp +++ b/src/sieve_of_eratosthenes.test.cpp @@ -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]); }