From 61c531da387db9c4ebc81313eb0882a6abad8fdd Mon Sep 17 00:00:00 2001 From: Lucas Stauder <git@lucas-stauder.de> Date: Wed, 20 Nov 2024 16:04:32 +0000 Subject: [PATCH] improve sieve tests --- src/sieve_of_eratosthenes.test.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/sieve_of_eratosthenes.test.cpp b/src/sieve_of_eratosthenes.test.cpp index 0abe5b6..6c532b8 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]); } -- GitLab