tesseract  5.0.0
qrsequence_test.cc
Go to the documentation of this file.
1 // (C) Copyright 2017, Google Inc.
2 // Licensed under the Apache License, Version 2.0 (the "License");
3 // you may not use this file except in compliance with the License.
4 // You may obtain a copy of the License at
5 // http://www.apache.org/licenses/LICENSE-2.0
6 // Unless required by applicable law or agreed to in writing, software
7 // distributed under the License is distributed on an "AS IS" BASIS,
8 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9 // See the License for the specific language governing permissions and
10 // limitations under the License.
11 
12 #include <algorithm>
13 #include <vector>
14 
15 #include "cycletimer.h"
16 #include "include_gunit.h"
17 #include "log.h"
18 #include "qrsequence.h"
19 
20 namespace tesseract {
21 
23 public:
24  explicit TestableQRSequenceGenerator(const int &N) : QRSequenceGenerator(N) {}
25  // Overriding scope for testing
27 };
28 
29 // Verifies binary inversion for a small range.
30 TEST(QRSequenceGenerator, GetBinaryReversedInteger) {
31  const int kRangeSize = 8;
32  TestableQRSequenceGenerator generator(kRangeSize);
33  int reversed_vals[kRangeSize] = {0, 4, 2, 6, 1, 5, 3, 7};
34  for (int i = 0; i < kRangeSize; ++i) {
35  EXPECT_EQ(reversed_vals[i], generator.GetBinaryReversedInteger(i));
36  }
37 }
38 
39 // Trivial test fixture for a parameterized test.
40 class QRSequenceGeneratorTest : public ::testing::TestWithParam<int> {
41 protected:
42  void SetUp() override {
43  std::locale::global(std::locale(""));
44  }
45 };
46 
47 TEST_P(QRSequenceGeneratorTest, GeneratesValidSequence) {
48  const int kRangeSize = GetParam();
49  TestableQRSequenceGenerator generator(kRangeSize);
50  std::vector<int> vals(kRangeSize);
51  CycleTimer timer;
52  timer.Restart();
53  for (int i = 0; i < kRangeSize; ++i) {
54  vals[i] = generator.GetVal();
55  }
56  LOG(INFO) << kRangeSize << "-length sequence took " << timer.GetInMs() << "ms";
57  // Sort the numbers to verify that we've covered the range without repetition.
58  std::sort(vals.begin(), vals.end());
59  for (int i = 0; i < kRangeSize; ++i) {
60  EXPECT_EQ(i, vals[i]);
61  if (i != vals[i]) {
62  LOG(INFO) << "Aborting remaining comparisons";
63  break;
64  }
65  }
66 }
67 
68 // Run a parameterized test using the following range sizes.
70  ::testing::Values(2, 7, 8, 9, 16, 1e2, 1e4, 1e6));
71 } // namespace tesseract
@ LOG
@ INFO
Definition: log.h:28
INSTANTIATE_TEST_SUITE_P(Eng, MatchGroundTruth, ::testing::Values("eng"))
TEST_P(MatchGroundTruth, FastPhototestOCR)
TEST(TesseractInstanceTest, TestMultipleTessInstances)
int GetBinaryReversedInteger(int in_val) const
Definition: qrsequence.h:60
void Restart()
Definition: cycletimer.h:43
int64_t GetInMs() const
Definition: cycletimer.h:54
int GetBinaryReversedInteger(int in_val) const
Definition: qrsequence.h:60