22 class TabVectorTest :
public testing::Test {
25 std::locale::global(std::locale(
""));
31 void MakeSimpleTabVector(
int x1,
int y1,
int x2,
int y2) {
33 vector_->set_startpt(
ICOORD(x1, y1));
34 vector_->set_endpt(
ICOORD(x2, y2));
37 std::unique_ptr<TabVector> vector_;
40 TEST_F(TabVectorTest, SetStartEndPointsMatch) {
46 vector_->set_startpt(start);
47 EXPECT_EQ(start.x(), vector_->startpt().x());
48 EXPECT_EQ(start.y(), vector_->startpt().y());
49 vector_->set_endpt(end);
50 EXPECT_EQ(end.x(), vector_->endpt().x());
51 EXPECT_EQ(end.y(), vector_->endpt().y());
54 TEST_F(TabVectorTest, XAtY45DegreeSlopeInRangeExact) {
55 MakeSimpleTabVector(0, 0, 100, 100);
56 for (
int y = 0; y <= 100; ++y) {
57 int x = vector_->XAtY(y);
62 TEST_F(TabVectorTest, XAtYVerticalInRangeExact) {
64 MakeSimpleTabVector(x, 0, x, 100);
65 for (
int y = 0; y <= 100; ++y) {
66 int result_x = vector_->XAtY(y);
67 EXPECT_EQ(x, result_x);
71 TEST_F(TabVectorTest, XAtYHorizontal) {
73 MakeSimpleTabVector(0, y, 100, y);
74 EXPECT_EQ(0, vector_->XAtY(y));
77 EXPECT_EQ(0, vector_->XAtY(10));
80 TEST_F(TabVectorTest, XAtYRoundingSimple) {
81 MakeSimpleTabVector(0, 0, 2, 10000);
82 int x = vector_->XAtY(1);
84 x = vector_->XAtY(4999);
86 x = vector_->XAtY(5001);
88 x = vector_->XAtY(9999);
92 TEST_F(TabVectorTest, XAtYLargeNumbers) {
96 MakeSimpleTabVector(7804, 504, 7968, 11768);
97 int x = vector_->XAtY(6136);
101 TEST_F(TabVectorTest, XAtYHorizontalInRangeExact) {
103 MakeSimpleTabVector(50, y, 150, y);
105 int x = vector_->XAtY(y);
109 TEST_F(TabVectorTest, VOverlapInRangeSimple) {
110 MakeSimpleTabVector(0, 0, 100, 100);
111 int overlap = vector_->VOverlap(90, 10);
112 EXPECT_EQ(80, overlap);
113 overlap = vector_->VOverlap(100, 0);
114 EXPECT_EQ(100, overlap);
117 TEST_F(TabVectorTest, VOverlapOutOfRange) {
118 MakeSimpleTabVector(0, 10, 100, 90);
119 int overlap = vector_->VOverlap(100, 0);
120 EXPECT_EQ(80, overlap);
123 TEST_F(TabVectorTest, XYFlip) {
124 MakeSimpleTabVector(1, 2, 3, 4);
126 EXPECT_EQ(2, vector_->startpt().x());
127 EXPECT_EQ(1, vector_->startpt().y());
128 EXPECT_EQ(4, vector_->endpt().x());
129 EXPECT_EQ(3, vector_->endpt().y());