tesseract  5.0.0-alpha-619-ge9db
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 
17 
18 namespace {
19 
20 class TestableColPartition : public ColPartition {
21  public:
22  void SetColumnRange(int first, int last) {
23  set_first_column(first);
25  }
26 };
27 
28 class ColPartitionTest : public testing::Test {
29  protected:
30  void SetUp() {
31  std::locale::global(std::locale(""));
32  }
33 
34  void TearDown() {}
35 };
36 
37 TEST_F(ColPartitionTest, IsInSameColumnAsReflexive) {
38  TestableColPartition a, b;
39  a.SetColumnRange(1, 2);
40  b.SetColumnRange(3, 3);
41 
42  EXPECT_TRUE(a.IsInSameColumnAs(a));
43  EXPECT_TRUE(b.IsInSameColumnAs(b));
44 }
45 
46 TEST_F(ColPartitionTest, IsInSameColumnAsBorders) {
47  TestableColPartition a, b, c, d;
48  a.SetColumnRange(0, 1);
49  b.SetColumnRange(1, 2);
50  c.SetColumnRange(2, 3);
51  d.SetColumnRange(4, 5);
52 
53  EXPECT_TRUE(a.IsInSameColumnAs(b));
54  EXPECT_TRUE(b.IsInSameColumnAs(a));
55  EXPECT_FALSE(c.IsInSameColumnAs(d));
56  EXPECT_FALSE(d.IsInSameColumnAs(c));
57  EXPECT_FALSE(a.IsInSameColumnAs(d));
58 }
59 
60 TEST_F(ColPartitionTest, IsInSameColumnAsSuperset) {
61  TestableColPartition a, b;
62  a.SetColumnRange(4, 7);
63  b.SetColumnRange(2, 8);
64 
65  EXPECT_TRUE(a.IsInSameColumnAs(b));
66  EXPECT_TRUE(b.IsInSameColumnAs(a));
67 }
68 
69 TEST_F(ColPartitionTest, IsInSameColumnAsPartialOverlap) {
70  TestableColPartition a, b;
71  a.SetColumnRange(3, 8);
72  b.SetColumnRange(6, 10);
73 
74  EXPECT_TRUE(a.IsInSameColumnAs(b));
75  EXPECT_TRUE(b.IsInSameColumnAs(a));
76 }
77 
78 } // namespace
tesseract::ColPartition::set_last_column
void set_last_column(int column)
Definition: colpartition.h:734
tesseract::ColPartition::set_first_column
void set_first_column(int column)
Definition: colpartition.h:731
colpartition.h
include_gunit.h
tesseract::TEST_F
TEST_F(EquationFinderTest, IdentifySpecialText)
Definition: equationdetect_test.cc:181
tesseract::ColPartition
Definition: colpartition.h:67
last
LIST last(LIST var_list)
Definition: oldlist.cpp:151