mirror of
https://github.com/tesseract-ocr/tesseract.git
synced 2025-01-18 14:41:36 +08:00
2b7df59187
They were provided by Jeff Breidenbach <jbreiden@google.com>. Signed-off-by: Stefan Weil <sw@weilnetz.de>
121 lines
3.1 KiB
C++
121 lines
3.1 KiB
C++
|
|
#include <memory>
|
|
|
|
#include "tesseract/textord/tabvector.h"
|
|
|
|
using tesseract::TabVector;
|
|
|
|
namespace {
|
|
|
|
class TabVectorTest : public testing::Test {
|
|
protected:
|
|
void SetUp() {
|
|
vector_.reset();
|
|
}
|
|
|
|
void TearDown() {
|
|
}
|
|
|
|
void MakeSimpleTabVector(int x1, int y1, int x2, int y2) {
|
|
vector_.reset(new TabVector());
|
|
vector_->set_startpt(ICOORD(x1, y1));
|
|
vector_->set_endpt(ICOORD(x2, y2));
|
|
}
|
|
|
|
std::unique_ptr<TabVector> vector_;
|
|
};
|
|
|
|
TEST_F(TabVectorTest, SetStartEndPointsMatch) {
|
|
vector_.reset(new TabVector());
|
|
ICOORD start(51, 65);
|
|
ICOORD end(7568, 234);
|
|
// Test coordinates individually to avoid adding an ostream operator
|
|
// explicitly to the ICOORD class (Droid doesn't support it).
|
|
vector_->set_startpt(start);
|
|
EXPECT_EQ(start.x(), vector_->startpt().x());
|
|
EXPECT_EQ(start.y(), vector_->startpt().y());
|
|
vector_->set_endpt(end);
|
|
EXPECT_EQ(end.x(), vector_->endpt().x());
|
|
EXPECT_EQ(end.y(), vector_->endpt().y());
|
|
}
|
|
|
|
TEST_F(TabVectorTest, XAtY45DegreeSlopeInRangeExact) {
|
|
MakeSimpleTabVector(0, 0, 100, 100);
|
|
for (int y = 0; y <= 100; ++y) {
|
|
int x = vector_->XAtY(y);
|
|
EXPECT_EQ(y, x);
|
|
}
|
|
}
|
|
|
|
TEST_F(TabVectorTest, XAtYVerticalInRangeExact) {
|
|
const int x = 120; // Arbitrary choice
|
|
MakeSimpleTabVector(x, 0, x, 100);
|
|
for (int y = 0; y <= 100; ++y) {
|
|
int result_x = vector_->XAtY(y);
|
|
EXPECT_EQ(x, result_x);
|
|
}
|
|
}
|
|
|
|
TEST_F(TabVectorTest, XAtYHorizontal) {
|
|
const int y = 76; // arbitrary
|
|
MakeSimpleTabVector(0, y, 100, y);
|
|
EXPECT_EQ(0, vector_->XAtY(y));
|
|
// TODO(nbeato): What's the failure condition?
|
|
// Undefined! Should not pass! Allow until resolved answer.
|
|
EXPECT_EQ(0, vector_->XAtY(10));
|
|
}
|
|
|
|
TEST_F(TabVectorTest, XAtYRoundingSimple) {
|
|
MakeSimpleTabVector(0, 0, 2, 10000);
|
|
int x = vector_->XAtY(1);
|
|
EXPECT_EQ(0, x);
|
|
x = vector_->XAtY(4999);
|
|
EXPECT_EQ(0, x);
|
|
x = vector_->XAtY(5001);
|
|
EXPECT_EQ(1, x);
|
|
x = vector_->XAtY(9999);
|
|
EXPECT_EQ(1, x);
|
|
}
|
|
|
|
TEST_F(TabVectorTest, XAtYLargeNumbers) {
|
|
// Assume a document is 800 DPI,
|
|
// the width of a page is 10 inches across (8000 pixels), and
|
|
// the height of the page is 15 inches (12000 pixels).
|
|
MakeSimpleTabVector(7804, 504, 7968, 11768); // Arbitrary for vertical line
|
|
int x = vector_->XAtY(6136); // test mid point
|
|
EXPECT_EQ(7886, x);
|
|
}
|
|
|
|
TEST_F(TabVectorTest, XAtYHorizontalInRangeExact) {
|
|
const int y = 120; // Arbitrary choice
|
|
MakeSimpleTabVector(50, y, 150, y);
|
|
|
|
int x = vector_->XAtY(y);
|
|
EXPECT_EQ(50, x);
|
|
}
|
|
|
|
TEST_F(TabVectorTest, VOverlapInRangeSimple) {
|
|
MakeSimpleTabVector(0, 0, 100, 100);
|
|
int overlap = vector_->VOverlap(90, 10);
|
|
EXPECT_EQ(80, overlap);
|
|
overlap = vector_->VOverlap(100, 0);
|
|
EXPECT_EQ(100, overlap);
|
|
}
|
|
|
|
TEST_F(TabVectorTest, VOverlapOutOfRange) {
|
|
MakeSimpleTabVector(0, 10, 100, 90);
|
|
int overlap = vector_->VOverlap(100, 0);
|
|
EXPECT_EQ(80, overlap);
|
|
}
|
|
|
|
TEST_F(TabVectorTest, XYFlip) {
|
|
MakeSimpleTabVector(1, 2, 3, 4);
|
|
vector_->XYFlip();
|
|
EXPECT_EQ(2, vector_->startpt().x());
|
|
EXPECT_EQ(1, vector_->startpt().y());
|
|
EXPECT_EQ(4, vector_->endpt().x());
|
|
EXPECT_EQ(3, vector_->endpt().y());
|
|
}
|
|
|
|
} // namespace
|