50 HybridPrimeTable(
bool force_on_the_fly,
int max_precalculated)
52 precalc_impl_(force_on_the_fly
55 max_precalculated_(max_precalculated) {}
56 ~HybridPrimeTable()
override {
57 delete on_the_fly_impl_;
61 bool IsPrime(
int n)
const override {
62 if (precalc_impl_ !=
nullptr && n < max_precalculated_)
63 return precalc_impl_->IsPrime(n);
65 return on_the_fly_impl_->IsPrime(n);
70 if (precalc_impl_ !=
nullptr && p < max_precalculated_)
71 next_prime = precalc_impl_->GetNextPrime(p);
73 return next_prime != -1 ? next_prime : on_the_fly_impl_->GetNextPrime(p);
79 int max_precalculated_;
82 using ::testing::TestWithParam;
92 class PrimeTableTest :
public TestWithParam< ::std::tuple<bool, int> > {
94 void SetUp()
override {
95 bool force_on_the_fly;
96 int max_precalculated;
97 std::tie(force_on_the_fly, max_precalculated) = GetParam();
98 table_ =
new HybridPrimeTable(force_on_the_fly, max_precalculated);
100 void TearDown()
override {
104 HybridPrimeTable* table_;
107 TEST_P(PrimeTableTest, ReturnsFalseForNonPrimes) {
122 TEST_P(PrimeTableTest, ReturnsTrueForPrimes) {
131 TEST_P(PrimeTableTest, CanGetNextPrime) {
137 EXPECT_EQ(131, table_->GetNextPrime(128));
internal::ValueArray< T...> Values(T...v)
internal::ParamGenerator< bool > Bool()
internal::CartesianProductHolder< Generator...> Combine(const Generator &...g)
#define EXPECT_EQ(val1, val2)
#define TEST_P(test_suite_name, test_name)
#define EXPECT_TRUE(condition)
#define EXPECT_FALSE(condition)
#define INSTANTIATE_TEST_SUITE_P(prefix, test_suite_name,...)