tesseract v5.3.3.20231005
tesseract::IndexMapBiDiTest Class Reference
Inheritance diagram for tesseract::IndexMapBiDiTest:
testing::Test

Public Member Functions

std::string OutputNameToPath (const std::string &name)
 
void ComputePrimes (IndexMapBiDi *map)
 
void TestPrimes (const IndexMap &map)
 
- Public Member Functions inherited from testing::Test
virtual ~Test ()
 

Protected Member Functions

void SetUp () override
 
- Protected Member Functions inherited from testing::Test
 Test ()
 
virtual void SetUp ()
 
virtual void TearDown ()
 

Additional Inherited Members

- Static Public Member Functions inherited from testing::Test
static void SetUpTestSuite ()
 
static void TearDownTestSuite ()
 
static void TearDownTestCase ()
 
static void SetUpTestCase ()
 
static bool HasFatalFailure ()
 
static bool HasNonfatalFailure ()
 
static bool IsSkipped ()
 
static bool HasFailure ()
 
static void RecordProperty (const std::string &key, const std::string &value)
 
static void RecordProperty (const std::string &key, int value)
 

Detailed Description

Definition at line 24 of file indexmapbidi_test.cc.

Member Function Documentation

◆ ComputePrimes()

void tesseract::IndexMapBiDiTest::ComputePrimes ( IndexMapBiDi map)
inline

Definition at line 36 of file indexmapbidi_test.cc.

36 {
37 map->Init(kPrimeLimit + 1, false);
38 map->SetMap(2, true);
39 // Set all the odds to true.
40 for (int i = 3; i <= kPrimeLimit; i += 2) {
41 map->SetMap(i, true);
42 }
43 int factor_limit = static_cast<int>(sqrt(1.0 + kPrimeLimit));
44 for (int f = 3; f <= factor_limit; f += 2) {
45 if (map->SparseToCompact(f) >= 0) {
46 for (int m = 2; m * f <= kPrimeLimit; ++m) {
47 map->SetMap(f * m, false);
48 }
49 }
50 }
51 map->Setup();
52 }
const int kPrimeLimit

◆ OutputNameToPath()

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

Definition at line 32 of file indexmapbidi_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

◆ SetUp()

void tesseract::IndexMapBiDiTest::SetUp ( )
inlineoverrideprotectedvirtual

Reimplemented from testing::Test.

Definition at line 26 of file indexmapbidi_test.cc.

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

◆ TestPrimes()

void tesseract::IndexMapBiDiTest::TestPrimes ( const IndexMap map)
inline

Definition at line 54 of file indexmapbidi_test.cc.

54 {
55 // Now all primes are mapped in the sparse map to their index.
56 // According to Wikipedia, the 168th prime is 997, and it has compact
57 // index 167 because we are indexing from 0.
58 EXPECT_EQ(167, map.SparseToCompact(997));
59 EXPECT_EQ(997, map.CompactToSparse(167));
60 // 995, 996, 998, 999 are not prime.
61 EXPECT_EQ(-1, map.SparseToCompact(995));
62 EXPECT_EQ(-1, map.SparseToCompact(996));
63 EXPECT_EQ(-1, map.SparseToCompact(998));
64 EXPECT_EQ(-1, map.SparseToCompact(999));
65 // The 167th prime is 991.
66 EXPECT_EQ(991, map.CompactToSparse(166));
67 // There are 168 primes in 0..1000.
68 EXPECT_EQ(168, map.CompactSize());
69 EXPECT_EQ(kPrimeLimit + 1, map.SparseSize());
70 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:2043

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