Welcome to mirror list, hosted at ThFree Co, Russian Federation.

elias_coder_test.cpp « coding_tests « coding - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1abab6283dc0b1476cc96466fa0f4c7ecb45153d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "testing/testing.hpp"

#include "coding/bit_streams.hpp"
#include "coding/elias_coder.hpp"
#include "coding/reader.hpp"
#include "coding/writer.hpp"

#include "base/bits.hpp"

#include "std/vector.hpp"

namespace
{
template <typename TCoder>
void TestCoder(string const & name)
{
  using TBuffer = vector<uint8_t>;
  using TWriter = MemWriter<TBuffer>;

  uint64_t const kMask = 0xfedcba9876543210;

  TBuffer buf;
  {
    TWriter w(buf);
    BitWriter<TWriter> bits(w);
    for (int i = 0; i <= 64; ++i)
    {
      uint64_t const mask = bits::GetFullMask(i);
      uint64_t const value = kMask & mask;
      if (value == 0)
        TEST(!TCoder::Encode(bits, value), (name, i));
      else
        TEST(TCoder::Encode(bits, value), (name, i));
    }
  }

  {
    MemReader r(buf.data(), buf.size());
    ReaderSource<MemReader> src(r);
    BitReader<ReaderSource<MemReader>> bits(src);
    for (int i = 0; i <= 64; ++i)
    {
      uint64_t const mask = bits::GetFullMask(i);
      uint64_t const expected = kMask & mask;
      if (expected == 0)
        continue;
      TEST_EQUAL(expected, TCoder::Decode(bits), (name, i));
    }
  }
}

UNIT_TEST(EliasCoder_Gamma) { TestCoder<coding::GammaCoder>("Gamma"); }
UNIT_TEST(EliasCoder_Delta) { TestCoder<coding::DeltaCoder>("Delta"); }
}  // namespace