summaryrefslogtreecommitdiffstats
path: root/searchlib/src/tests/bitcompression/expgolomb/expgolomb_test.cpp
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2023-01-31 05:36:45 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2023-01-31 05:36:45 +0000
commitbe060eef1311058577311846e68c3b60525482ed (patch)
treef9410f38da6af65a58fe01e582e6e108f364920a /searchlib/src/tests/bitcompression/expgolomb/expgolomb_test.cpp
parentefaf9b0b8f93dfdc6b2399db252007b705857c31 (diff)
Minor cleanup
Diffstat (limited to 'searchlib/src/tests/bitcompression/expgolomb/expgolomb_test.cpp')
-rw-r--r--searchlib/src/tests/bitcompression/expgolomb/expgolomb_test.cpp185
1 files changed, 55 insertions, 130 deletions
diff --git a/searchlib/src/tests/bitcompression/expgolomb/expgolomb_test.cpp b/searchlib/src/tests/bitcompression/expgolomb/expgolomb_test.cpp
index 591e1935ea7..5bb36a8462e 100644
--- a/searchlib/src/tests/bitcompression/expgolomb/expgolomb_test.cpp
+++ b/searchlib/src/tests/bitcompression/expgolomb/expgolomb_test.cpp
@@ -29,7 +29,6 @@ public:
}
};
-
class IDecodeFunc
{
public:
@@ -38,12 +37,9 @@ public:
virtual uint64_t decodeSmall() = 0;
virtual uint64_t decodeSmallApply() = 0;
virtual void skipSmall() = 0;
-
virtual ~IDecodeFunc() = default;
-
};
-
/*
* Exp golomb decode functions getting kValue from a variable, i.e.
* compiler is not allowed to generate shift instructions with immediate values.
@@ -64,53 +60,40 @@ public:
DecodeExpGolombVarK(DCB &dc, int kValue)
: _dc(dc),
_kValue(kValue)
- {
- }
+ { }
- uint64_t decode() override
- {
+ uint64_t decode() override {
unsigned int length;
uint64_t val64;
- UC64_DECODEEXPGOLOMB(_dc._val, _dc._valI, _dc._preRead,
- _dc._cacheInt, _kValue, EC);
+ UC64_DECODEEXPGOLOMB(_dc._val, _dc._valI, _dc._preRead, _dc._cacheInt, _kValue, EC);
return val64;
}
- void skip() override
- {
+ void skip() override {
unsigned int length;
- UC64_SKIPEXPGOLOMB(_dc._val, _dc._valI, _dc._preRead,
- _dc._cacheInt, _kValue, EC);
+ UC64_SKIPEXPGOLOMB(_dc._val, _dc._valI, _dc._preRead, _dc._cacheInt, _kValue, EC);
}
- uint64_t decodeSmall() override
- {
+ uint64_t decodeSmall() override {
unsigned int length;
uint64_t val64;
- UC64_DECODEEXPGOLOMB_SMALL(_dc._val, _dc._valI, _dc._preRead,
- _dc._cacheInt, _kValue, EC);
+ UC64_DECODEEXPGOLOMB_SMALL(_dc._val, _dc._valI, _dc._preRead, _dc._cacheInt, _kValue, EC);
return val64;
}
- uint64_t decodeSmallApply() override
- {
+ uint64_t decodeSmallApply() override {
unsigned int length;
uint64_t val64;
- UC64_DECODEEXPGOLOMB_SMALL_APPLY(_dc._val, _dc._valI, _dc._preRead,
- _dc._cacheInt, _kValue, EC, val64 =);
+ UC64_DECODEEXPGOLOMB_SMALL_APPLY(_dc._val, _dc._valI, _dc._preRead, _dc._cacheInt, _kValue, EC, val64 =);
return val64;
}
- void skipSmall() override
- {
+ void skipSmall() override {
unsigned int length;
- UC64_SKIPEXPGOLOMB_SMALL(_dc._val, _dc._valI, _dc._preRead,
- _dc._cacheInt, _kValue, EC);
+ UC64_SKIPEXPGOLOMB_SMALL(_dc._val, _dc._valI, _dc._preRead, _dc._cacheInt, _kValue, EC);
}
- static std::unique_ptr<IDecodeFunc>
- make(DCB &dc, int kValue)
- {
+ static std::unique_ptr<IDecodeFunc> make(DCB &dc, int kValue) {
return std::make_unique<DecodeExpGolombVarK<bigEndian>>(dc, kValue);
}
};
@@ -133,61 +116,45 @@ public:
explicit DecodeExpGolombConstK(DCB &dc)
: _dc(dc)
- {
- }
+ { }
- uint64_t decode() override
- {
+ uint64_t decode() override {
unsigned int length;
uint64_t val64;
- UC64_DECODEEXPGOLOMB(_dc._val, _dc._valI, _dc._preRead,
- _dc._cacheInt, kValue, EC);
+ UC64_DECODEEXPGOLOMB(_dc._val, _dc._valI, _dc._preRead, _dc._cacheInt, kValue, EC);
return val64;
}
- void skip() override
- {
+ void skip() override {
unsigned int length;
- UC64_SKIPEXPGOLOMB(_dc._val, _dc._valI, _dc._preRead,
- _dc._cacheInt, kValue, EC);
+ UC64_SKIPEXPGOLOMB(_dc._val, _dc._valI, _dc._preRead, _dc._cacheInt, kValue, EC);
}
- uint64_t decodeSmall() override
- {
+ uint64_t decodeSmall() override {
unsigned int length;
uint64_t val64;
- UC64_DECODEEXPGOLOMB_SMALL(_dc._val, _dc._valI, _dc._preRead,
- _dc._cacheInt, kValue, EC);
+ UC64_DECODEEXPGOLOMB_SMALL(_dc._val, _dc._valI, _dc._preRead, _dc._cacheInt, kValue, EC);
return val64;
}
- uint64_t decodeSmallApply() override
- {
+ uint64_t decodeSmallApply() override {
unsigned int length;
uint64_t val64;
- UC64_DECODEEXPGOLOMB_SMALL_APPLY(_dc._val, _dc._valI, _dc._preRead,
- _dc._cacheInt, kValue, EC, val64 =);
+ UC64_DECODEEXPGOLOMB_SMALL_APPLY(_dc._val, _dc._valI, _dc._preRead, _dc._cacheInt, kValue, EC, val64 =);
return val64;
}
- void skipSmall() override
- {
+ void skipSmall() override {
unsigned int length;
- UC64_SKIPEXPGOLOMB_SMALL(_dc._val, _dc._valI, _dc._preRead,
- _dc._cacheInt, kValue, EC);
+ UC64_SKIPEXPGOLOMB_SMALL(_dc._val, _dc._valI, _dc._preRead, _dc._cacheInt, kValue, EC);
}
- static std::unique_ptr<IDecodeFunc>
- make(DCB &dc, int)
- {
+ static std::unique_ptr<IDecodeFunc> make(DCB &dc, int){
return std::make_unique<DecodeExpGolombConstK<bigEndian, kValue>>(dc);
}
};
-
-using IDecodeFuncFactory =
- std::unique_ptr<IDecodeFunc> (*)(DecodeContext64Base &dc, int kValue);
-
+using IDecodeFuncFactory = std::unique_ptr<IDecodeFunc> (*)(DecodeContext64Base &dc, int kValue);
template <bool bigEndian>
class DecodeFuncFactories
@@ -219,7 +186,6 @@ DecodeFuncFactories<bigEndian>::addConstKFactory(int kValue, IDecodeFuncFactory
_constK.push_back(factory);
}
-
template <bool bigEndian>
struct RegisterFactoryPtr;
@@ -228,7 +194,6 @@ template <bool bigEndian>
using RegisterFactory = void (*)(DecodeFuncFactories<bigEndian> &factories,
RegisterFactoryPtr<bigEndian> &ptr);
-
template <bool bigEndian>
struct RegisterFactoryPtr
{
@@ -236,11 +201,9 @@ struct RegisterFactoryPtr
explicit RegisterFactoryPtr(RegisterFactory<bigEndian> ptr)
: _ptr(ptr)
- {
- }
+ { }
};
-
template <bool bigEndian, int kValue>
class RegisterFactories
{
@@ -253,7 +216,6 @@ public:
}
};
-
template <bool bigEndian>
class RegisterFactories<bigEndian, 64>
{
@@ -266,20 +228,17 @@ public:
}
};
-
template <bool bigEndian>
DecodeFuncFactories<bigEndian>::DecodeFuncFactories()
: _constK(),
_varK(&DecodeExpGolombVarK<bigEndian>::make)
{
- RegisterFactoryPtr<bigEndian> f(
- &RegisterFactories<bigEndian, 0>::registerFactory);
+ RegisterFactoryPtr<bigEndian> f(&RegisterFactories<bigEndian, 0>::registerFactory);
while (f._ptr) {
(*f._ptr)(*this, f);
}
}
-
class TestFixtureBase
{
public:
@@ -289,23 +248,12 @@ public:
void fillRandNums();
static void calcBoundaries(int kValue, bool small, std::vector<uint64_t> &v);
- static void
- testBoundaries(int kValue, bool small,
- std::vector<uint64_t> &v,
- DecodeContext64Base &dc,
- DecodeContext64Base &dcSkip,
- DecodeContext64Base &dcApply,
- IDecodeFunc &df,
- IDecodeFunc &dfSkip,
- IDecodeFunc &dfApply);
-
- void
- testRandNums(DecodeContext64Base &dc,
- DecodeContext64Base &dcSkip,
- IDecodeFunc &df,
- IDecodeFunc &dfSkip);
-};
+ static void testBoundaries(int kValue, bool small, std::vector<uint64_t> &v,
+ DecodeContext64Base &dc, DecodeContext64Base &dcSkip, DecodeContext64Base &dcApply,
+ IDecodeFunc &df, IDecodeFunc &dfSkip, IDecodeFunc &dfApply);
+ void testRandNums(DecodeContext64Base &dc, DecodeContext64Base &dcSkip, IDecodeFunc &df, IDecodeFunc &dfSkip);
+};
void
TestFixtureBase::fillRandNums()
@@ -326,7 +274,6 @@ TestFixtureBase::fillRandNums()
}
}
-
namespace {
/*
@@ -339,12 +286,8 @@ addBoundary(uint64_t boundary, uint64_t maxVal, std::vector<uint64_t> &v)
uint64_t high = maxVal - 2u < boundary ? maxVal : boundary + 2;
assert(low <= high);
LOG(info, "low=0x%" PRIx64 ", high=0x%" PRIx64, low, high);
- uint64_t i = low;
- for (;;) {
+ for (uint64_t i = low; i != high; ++i) {
v.push_back(i);
- if (i == high)
- break;
- ++i;
}
}
@@ -383,14 +326,9 @@ TestFixtureBase::calcBoundaries(int kValue, bool small, std::vector<uint64_t> &v
void
-TestFixtureBase::testBoundaries(int kValue, bool small,
- std::vector<uint64_t> &v,
- DecodeContext64Base &dc,
- DecodeContext64Base &dcSkip,
- DecodeContext64Base &dcApply,
- IDecodeFunc &df,
- IDecodeFunc &dfSkip,
- IDecodeFunc &dfApply)
+TestFixtureBase::testBoundaries(int kValue, bool small, std::vector<uint64_t> &v,
+ DecodeContext64Base &dc, DecodeContext64Base &dcSkip, DecodeContext64Base &dcApply,
+ IDecodeFunc &df, IDecodeFunc &dfSkip, IDecodeFunc &dfApply)
{
uint32_t bits = 0;
uint64_t maxSame = 0;
@@ -426,12 +364,9 @@ TestFixtureBase::testBoundaries(int kValue, bool small,
}
}
-
void
-TestFixtureBase::testRandNums(DecodeContext64Base &dc,
- DecodeContext64Base &dcSkip,
- IDecodeFunc &df,
- IDecodeFunc &dfSkip)
+TestFixtureBase::testRandNums(DecodeContext64Base &dc, DecodeContext64Base &dcSkip,
+ IDecodeFunc &df, IDecodeFunc &dfSkip)
{
for (auto num : _randNums) {
uint64_t val64 = df.decode();
@@ -442,8 +377,6 @@ TestFixtureBase::testRandNums(DecodeContext64Base &dc,
}
}
-
-
template <bool bigEndian>
class TestFixture : public TestFixtureBase
{
@@ -455,18 +388,11 @@ public:
using Parent::testBoundaries;
using Parent::testRandNums;
- TestFixture()
- : TestFixtureBase(),
- _factories()
- {
- fillRandNums();
- }
+ TestFixture();
+ ~TestFixture();
- void
- testBoundaries(int kValue, bool small,
- std::vector<uint64_t> &v,
- IDecodeFuncFactory f,
- search::ComprFileWriteContext &wc);
+ void testBoundaries(int kValue, bool small, std::vector<uint64_t> &v,
+ IDecodeFuncFactory f, search::ComprFileWriteContext &wc);
void testBoundaries(int kValue, bool small, std::vector<uint64_t> &v);
void testBoundaries();
void testRandNums(int kValue, IDecodeFuncFactory f, search::ComprFileWriteContext &wc);
@@ -474,13 +400,21 @@ public:
void testRandNums();
};
+template <bool bigEndian>
+TestFixture<bigEndian>::TestFixture()
+ : TestFixtureBase(),
+ _factories()
+{
+ fillRandNums();
+}
+
+template <bool bigEndian>
+TestFixture<bigEndian>::~TestFixture() = default;
template <bool bigEndian>
void
-TestFixture<bigEndian>::testBoundaries(int kValue, bool small,
- std::vector<uint64_t> &v,
- IDecodeFuncFactory f,
- search::ComprFileWriteContext &wc)
+TestFixture<bigEndian>::testBoundaries(int kValue, bool small, std::vector<uint64_t> &v,
+ IDecodeFuncFactory f, search::ComprFileWriteContext &wc)
{
DC dc(wc.getComprBuf(), 0);
DC dcSkip(wc.getComprBuf(), 0);
@@ -488,11 +422,9 @@ TestFixture<bigEndian>::testBoundaries(int kValue, bool small,
std::unique_ptr<IDecodeFunc> df((*f)(dc, kValue));
std::unique_ptr<IDecodeFunc> dfSkip((*f)(dcSkip, kValue));
std::unique_ptr<IDecodeFunc> dfApply((*f)(dcApply, kValue));
- testBoundaries(kValue, small, v, dc, dcSkip, dcApply,
- *df, *dfSkip, *dfApply);
+ testBoundaries(kValue, small, v, dc, dcSkip, dcApply, *df, *dfSkip, *dfApply);
}
-
template <bool bigEndian>
void
TestFixture<bigEndian>::testBoundaries(int kValue, bool small, std::vector<uint64_t> &v)
@@ -514,7 +446,6 @@ TestFixture<bigEndian>::testBoundaries(int kValue, bool small, std::vector<uint6
testBoundaries(kValue, small, v, f, wc);
}
-
template <bool bigEndian>
void
TestFixture<bigEndian>::testBoundaries()
@@ -536,7 +467,6 @@ TestFixture<bigEndian>::testBoundaries()
}
}
-
template <bool bigEndian>
void
TestFixture<bigEndian>::testRandNums(int kValue, IDecodeFuncFactory f, search::ComprFileWriteContext &wc)
@@ -548,7 +478,6 @@ TestFixture<bigEndian>::testRandNums(int kValue, IDecodeFuncFactory f, search::C
testRandNums(dc, dcSkip, *df, *dfSkip);
}
-
template <bool bigEndian>
void
TestFixture<bigEndian>::testRandNums(int kValue)
@@ -570,7 +499,6 @@ TestFixture<bigEndian>::testRandNums(int kValue)
testRandNums(kValue, f, wc);
}
-
template <bool bigEndian>
void
TestFixture<bigEndian>::testRandNums()
@@ -580,19 +508,16 @@ TestFixture<bigEndian>::testRandNums()
}
}
-
TEST_F("Test bigendian expgolomb encoding/decoding", TestFixture<true>)
{
f.testRandNums();
f.testBoundaries();
}
-
TEST_F("Test little expgolomb encoding/decoding", TestFixture<false>)
{
f.testRandNums();
f.testBoundaries();
}
-
TEST_MAIN() { TEST_RUN_ALL(); }