mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-21 15:57:31 +09:00
re-introduce old nss im too tired for this
This commit is contained in:
parent
3c46be320d
commit
3a838106b9
2871 changed files with 1374431 additions and 1762417 deletions
|
|
@ -37,6 +37,7 @@
|
|||
|
||||
#include "gtest/gtest.h"
|
||||
namespace {
|
||||
#if GTEST_HAS_COMBINE
|
||||
|
||||
// Suppose we want to introduce a new, improved implementation of PrimeTable
|
||||
// which combines speed of PrecalcPrimeTable and versatility of
|
||||
|
|
@ -49,25 +50,24 @@ class HybridPrimeTable : public PrimeTable {
|
|||
public:
|
||||
HybridPrimeTable(bool force_on_the_fly, int max_precalculated)
|
||||
: on_the_fly_impl_(new OnTheFlyPrimeTable),
|
||||
precalc_impl_(force_on_the_fly
|
||||
? nullptr
|
||||
: new PreCalculatedPrimeTable(max_precalculated)),
|
||||
precalc_impl_(force_on_the_fly ? NULL :
|
||||
new PreCalculatedPrimeTable(max_precalculated)),
|
||||
max_precalculated_(max_precalculated) {}
|
||||
~HybridPrimeTable() override {
|
||||
virtual ~HybridPrimeTable() {
|
||||
delete on_the_fly_impl_;
|
||||
delete precalc_impl_;
|
||||
}
|
||||
|
||||
bool IsPrime(int n) const override {
|
||||
if (precalc_impl_ != nullptr && n < max_precalculated_)
|
||||
virtual bool IsPrime(int n) const {
|
||||
if (precalc_impl_ != NULL && n < max_precalculated_)
|
||||
return precalc_impl_->IsPrime(n);
|
||||
else
|
||||
return on_the_fly_impl_->IsPrime(n);
|
||||
}
|
||||
|
||||
int GetNextPrime(int p) const override {
|
||||
virtual int GetNextPrime(int p) const {
|
||||
int next_prime = -1;
|
||||
if (precalc_impl_ != nullptr && p < max_precalculated_)
|
||||
if (precalc_impl_ != NULL && p < max_precalculated_)
|
||||
next_prime = precalc_impl_->GetNextPrime(p);
|
||||
|
||||
return next_prime != -1 ? next_prime : on_the_fly_impl_->GetNextPrime(p);
|
||||
|
|
@ -89,17 +89,24 @@ using ::testing::Combine;
|
|||
// PreCalculatedPrimeTable disabled. We do this by defining fixture which will
|
||||
// accept different combinations of parameters for instantiating a
|
||||
// HybridPrimeTable instance.
|
||||
class PrimeTableTest : public TestWithParam< ::std::tuple<bool, int> > {
|
||||
class PrimeTableTest : public TestWithParam< ::testing::tuple<bool, int> > {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
bool force_on_the_fly;
|
||||
int max_precalculated;
|
||||
std::tie(force_on_the_fly, max_precalculated) = GetParam();
|
||||
virtual void SetUp() {
|
||||
// This can be written as
|
||||
//
|
||||
// bool force_on_the_fly;
|
||||
// int max_precalculated;
|
||||
// tie(force_on_the_fly, max_precalculated) = GetParam();
|
||||
//
|
||||
// once the Google C++ Style Guide allows use of ::std::tr1::tie.
|
||||
//
|
||||
bool force_on_the_fly = ::testing::get<0>(GetParam());
|
||||
int max_precalculated = ::testing::get<1>(GetParam());
|
||||
table_ = new HybridPrimeTable(force_on_the_fly, max_precalculated);
|
||||
}
|
||||
void TearDown() override {
|
||||
virtual void TearDown() {
|
||||
delete table_;
|
||||
table_ = nullptr;
|
||||
table_ = NULL;
|
||||
}
|
||||
HybridPrimeTable* table_;
|
||||
};
|
||||
|
|
@ -148,7 +155,19 @@ TEST_P(PrimeTableTest, CanGetNextPrime) {
|
|||
// will put some of the tested numbers beyond the capability of the
|
||||
// PrecalcPrimeTable instance and some inside it (10). Combine will produce all
|
||||
// possible combinations.
|
||||
INSTANTIATE_TEST_SUITE_P(MeaningfulTestParameters, PrimeTableTest,
|
||||
Combine(Bool(), Values(1, 10)));
|
||||
INSTANTIATE_TEST_CASE_P(MeaningfulTestParameters,
|
||||
PrimeTableTest,
|
||||
Combine(Bool(), Values(1, 10)));
|
||||
|
||||
#else
|
||||
|
||||
// Google Test may not support Combine() with some compilers. If we
|
||||
// use conditional compilation to compile out all code referring to
|
||||
// the gtest_main library, MSVC linker will not link that library at
|
||||
// all and consequently complain about missing entry point defined in
|
||||
// that library (fatal error LNK1561: entry point must be
|
||||
// defined). This dummy test keeps gtest_main linked in.
|
||||
TEST(DummyTest, CombineIsNotSupportedOnThisPlatform) {}
|
||||
|
||||
#endif // GTEST_HAS_COMBINE
|
||||
} // namespace
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue