Riddle #6: Po**t
Focus is on a routine calculating a midpoint. Tests for other code is out of scope.
``````#include <gtest/gtest.h>

struct Point {
int x, y;
};

bool operator==(const Point& lhs, const Point& rhs) {
return (lhs.x == rhs.x) && (lhs.y == rhs.y);
}
// assume Point and its operator== have sufficient test coverage

Point midpoint(const Point& topLeft, const Point& bottomRight) {
return Point{
(topLeft.x + bottomRight.x) / 2,
(topLeft.y + bottomRight.y) / 2};
}

TEST(PointTest, midpoint) {
const Point topLeft{10, 20};
const Point bottomRight{30, 40};

EXPECT_EQ((Point{20, 30}), midpoint(topLeft, bottomRight));
}
``````
``````#include <gtest/gtest.h>
#include <ostream>

struct Point {
int x, y;
};

bool operator==(const Point& lhs, const Point& rhs) {
return (lhs.x == rhs.x) && (lhs.y == rhs.y);
}
// assume Point and its operator== have sufficient test coverage

std::ostream& operator<<(std::ostream& os, const Point& p) {
if (!os) return os;
return os << "Point[x=" << p.x << ",y=" << p.y << ']';
}

Point midpoint(const Point& topLeft, const Point& bottomRight) {
return Point{
(topLeft.x + topLeft.x) / 2,
(bottomRight.y + bottomRight.y) / 2};
}

TEST(PointTest, midpoint) {
const Point topLeft{10, 20};
const Point bottomRight{30, 40};

EXPECT_EQ((Point{20, 30}), midpoint(topLeft, bottomRight));
}
``````
``````#include <gtest/gtest.h>

struct Point {
int x, y;
};

bool operator==(const Point& lhs, const Point& rhs) {
return (lhs.x == rhs.x) && (lhs.y == rhs.y);
}
// assume Point and its operator== have sufficient test coverage

Point midpoint(const Point& topLeft, const Point& bottomRight) {
return Point{
(topLeft.x + topLeft.x) / 2,
(bottomRight.y + bottomRight.y) / 2};
}

TEST(PointTest, midpoint) {
const Point topLeft{10, 20};
const Point bottomRight{30, 40};

EXPECT_EQ((Point{20, 30}), midpoint(topLeft, bottomRight));
}
``````
Can you spot a weakness in the test?
Give me a hint
What will happen in case of a test failure? Show me