tesseract  5.0.0
colpartition_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 "colpartition.h"
13 
14 #include "include_gunit.h"
15 
16 namespace tesseract {
17 
19 public:
20  void SetColumnRange(int first, int last) {
21  set_first_column(first);
23  }
24 };
25 
26 class ColPartitionTest : public testing::Test {
27 protected:
28  void SetUp() override {
29  std::locale::global(std::locale(""));
30  }
31 
32  void TearDown() override {}
33 };
34 
35 TEST_F(ColPartitionTest, IsInSameColumnAsReflexive) {
37  a.SetColumnRange(1, 2);
38  b.SetColumnRange(3, 3);
39 
40  EXPECT_TRUE(a.IsInSameColumnAs(a));
41  EXPECT_TRUE(b.IsInSameColumnAs(b));
42 }
43 
44 TEST_F(ColPartitionTest, IsInSameColumnAsBorders) {
45  TestableColPartition a, b, c, d;
46  a.SetColumnRange(0, 1);
47  b.SetColumnRange(1, 2);
48  c.SetColumnRange(2, 3);
49  d.SetColumnRange(4, 5);
50 
51  EXPECT_TRUE(a.IsInSameColumnAs(b));
52  EXPECT_TRUE(b.IsInSameColumnAs(a));
53  EXPECT_FALSE(c.IsInSameColumnAs(d));
54  EXPECT_FALSE(d.IsInSameColumnAs(c));
55  EXPECT_FALSE(a.IsInSameColumnAs(d));
56 }
57 
58 TEST_F(ColPartitionTest, IsInSameColumnAsSuperset) {
60  a.SetColumnRange(4, 7);
61  b.SetColumnRange(2, 8);
62 
63  EXPECT_TRUE(a.IsInSameColumnAs(b));
64  EXPECT_TRUE(b.IsInSameColumnAs(a));
65 }
66 
67 TEST_F(ColPartitionTest, IsInSameColumnAsPartialOverlap) {
69  a.SetColumnRange(3, 8);
70  b.SetColumnRange(6, 10);
71 
72  EXPECT_TRUE(a.IsInSameColumnAs(b));
73  EXPECT_TRUE(b.IsInSameColumnAs(a));
74 }
75 
76 } // namespace tesseract
LIST last(LIST var_list)
Definition: oldlist.cpp:153
TEST_F(EuroText, FastLatinOCR)
bool IsInSameColumnAs(const ColPartition &part) const
void set_last_column(int column)
Definition: colpartition.h:732
void set_first_column(int column)
Definition: colpartition.h:729
void SetColumnRange(int first, int last)