tesseract  5.0.0
tesseract::BitVectorTest Class Reference
Inheritance diagram for tesseract::BitVectorTest:

Public Member Functions

std::string OutputNameToPath (const std::string &name)
 
void ComputePrimes (BitVector *map)
 
void TestPrimes (const BitVector &map)
 
void TestAll (const BitVector &map, bool value)
 
void SetBitPattern (int start_byte, int end_byte, int spacing, BitVector *bv)
 
void ExpectCorrectBits (const BitVector &bv)
 

Protected Member Functions

void SetUp () override
 

Detailed Description

Definition at line 24 of file bitvector_test.cc.

Member Function Documentation

◆ ComputePrimes()

void tesseract::BitVectorTest::ComputePrimes ( BitVector map)
inline

Definition at line 36 of file bitvector_test.cc.

36  {
37  map->Init(kPrimeLimit + 1);
38  TestAll(*map, false);
39  map->SetBit(2);
40  // Set all the odds to true.
41  for (int i = 3; i <= kPrimeLimit; i += 2) {
42  map->SetValue(i, true);
43  }
44  int factor_limit = static_cast<int>(sqrt(1.0 + kPrimeLimit));
45  for (int f = 3; f <= factor_limit; f += 2) {
46  if (map->At(f)) {
47  for (int m = 2; m * f <= kPrimeLimit; ++m) {
48  map->ResetBit(f * m);
49  }
50  }
51  }
52  }
const int kPrimeLimit
void TestAll(const BitVector &map, bool value)

◆ ExpectCorrectBits()

void tesseract::BitVectorTest::ExpectCorrectBits ( const BitVector bv)
inline

Definition at line 92 of file bitvector_test.cc.

92  {
93  int bit_index = -1;
94  int prev_bit_index = -1;
95  int num_bits_tested = 0;
96  while ((bit_index = bv.NextSetBit(bit_index)) >= 0) {
97  EXPECT_LT(bit_index, bv.size());
98  // All bits in between must be 0.
99  for (int i = prev_bit_index + 1; i < bit_index; ++i) {
100  EXPECT_EQ(0, bv[i]) << "i = " << i << " prev = " << prev_bit_index;
101  }
102  // This bit must be 1.
103  EXPECT_EQ(1, bv[bit_index]) << "Bit index = " << bit_index;
104  ++num_bits_tested;
105  prev_bit_index = bit_index;
106  }
107  // Check the bits between the last and the end.
108  for (int i = prev_bit_index + 1; i < bv.size(); ++i) {
109  EXPECT_EQ(0, bv[i]);
110  }
111  EXPECT_EQ(num_bits_tested, bv.NumSetBits());
112  }

◆ OutputNameToPath()

std::string tesseract::BitVectorTest::OutputNameToPath ( const std::string &  name)
inline

Definition at line 32 of file bitvector_test.cc.

32  {
33  return file::JoinPath(FLAGS_test_tmpdir, name);
34  }
static std::string JoinPath(const std::string &s1, const std::string &s2)
Definition: include_gunit.h:65

◆ SetBitPattern()

void tesseract::BitVectorTest::SetBitPattern ( int  start_byte,
int  end_byte,
int  spacing,
BitVector bv 
)
inline

Definition at line 79 of file bitvector_test.cc.

79  {
80  bv->Init((end_byte - start_byte) * 8 * spacing);
81  for (int byte_value = start_byte; byte_value < end_byte; ++byte_value) {
82  for (int bit = 0; bit < 8; ++bit) {
83  if (byte_value & (1 << bit)) {
84  bv->SetBit((byte_value - start_byte) * 8 * spacing + bit);
85  }
86  }
87  }
88  }

◆ SetUp()

void tesseract::BitVectorTest::SetUp ( )
inlineoverrideprotected

Definition at line 26 of file bitvector_test.cc.

26  {
27  std::locale::global(std::locale(""));
29  }
static void MakeTmpdir()
Definition: include_gunit.h:38

◆ TestAll()

void tesseract::BitVectorTest::TestAll ( const BitVector map,
bool  value 
)
inline

Definition at line 70 of file bitvector_test.cc.

70  {
71  for (int i = 0; i < map.size(); ++i) {
72  EXPECT_EQ(value, map[i]);
73  }
74  }

◆ TestPrimes()

void tesseract::BitVectorTest::TestPrimes ( const BitVector map)
inline

Definition at line 54 of file bitvector_test.cc.

54  {
55  // Now all primes in the vector are true, and all others false.
56  // According to Wikipedia, there are 168 primes under 1000, the last
57  // of which is 997.
58  int total_primes = 0;
59  for (int i = 0; i <= kPrimeLimit; ++i) {
60  if (map[i]) {
61  ++total_primes;
62  }
63  }
64  EXPECT_EQ(168, total_primes);
65  EXPECT_TRUE(map[997]);
66  EXPECT_FALSE(map[998]);
67  EXPECT_FALSE(map[999]);
68  }

The documentation for this class was generated from the following file: