File size: 1,778 Bytes
985c397 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | #include <gtest/gtest.h>
#include <Base/Tools3D.h>
#include <Base/Vector3D.h>
class Line3D: public ::testing::Test
{
protected:
Line3D()
: pt1(0, 0, 0)
, pt2(3, 4, 0)
{}
void SetUp() override
{}
void TearDown() override
{}
Base::Vector3d GetFirst() const
{
return pt1;
}
Base::Vector3d GetSecond() const
{
return pt2;
}
Base::Line3d GetLine() const
{
Base::Line3d line(pt1, pt2);
return line;
}
private:
Base::Vector3d pt1, pt2;
};
TEST_F(Line3D, TestLength)
{
Base::Line3d line(GetLine());
EXPECT_DOUBLE_EQ(line.Length(), 5.0);
}
TEST_F(Line3D, TestSqrLength)
{
Base::Line3d line(GetLine());
EXPECT_DOUBLE_EQ(line.SqrLength(), 25.0);
}
TEST_F(Line3D, TestPoints)
{
Base::Line3d line(GetLine());
EXPECT_EQ(line.GetBase(), GetFirst());
EXPECT_EQ(line.GetDirection(), GetSecond());
}
TEST_F(Line3D, TestFromPos)
{
Base::Line3d line(GetLine());
EXPECT_EQ(line.FromPos(2.5), Base::Vector3d(1.5, 2, 0));
}
TEST_F(Line3D, TestContains)
{
Base::Line3d line(GetLine());
EXPECT_EQ(line.Contains(Base::Vector3d(1.5, 2, 0)), true);
}
TEST(Polygon3D, TestDefault)
{
Base::Polygon3d poly;
EXPECT_EQ(poly.GetSize(), 0);
}
TEST(Polygon3D, TestAdd)
{
Base::Polygon3d poly;
poly.Add(Base::Vector3d());
EXPECT_EQ(poly.GetSize(), 1);
}
TEST(Polygon3D, TestRemove)
{
Base::Polygon3d poly;
poly.Add(Base::Vector3d());
EXPECT_EQ(poly.GetSize(), 1);
EXPECT_EQ(poly.Remove(1), false);
EXPECT_EQ(poly.Remove(0), true);
EXPECT_EQ(poly.GetSize(), 0);
}
TEST(Polygon3D, TestClear)
{
Base::Polygon3d poly;
poly.Add(Base::Vector3d());
poly.Clear();
EXPECT_EQ(poly.GetSize(), 0);
}
|