Added first model tests. Super basic Part test
This commit is contained in:
parent
41183b8397
commit
9517b5b682
@ -16,3 +16,6 @@ add_library(model
|
||||
|
||||
target_link_libraries(model PRIVATE
|
||||
utils)
|
||||
|
||||
# Unit tests
|
||||
add_subdirectory(tests)
|
||||
|
@ -4,8 +4,30 @@
|
||||
namespace model
|
||||
{
|
||||
|
||||
Part::Part()
|
||||
{}
|
||||
Part::Part(const std::string& n,
|
||||
const Matrix3& I,
|
||||
double m,
|
||||
const Vector3& centerMass,
|
||||
double l,
|
||||
double inRadTop,
|
||||
double outRadTop,
|
||||
double inRadBottom,
|
||||
double outRadBottom)
|
||||
: parent(nullptr),
|
||||
name(n),
|
||||
inertiaTensor(I),
|
||||
compositeInertiaTensor(I),
|
||||
mass(m),
|
||||
compositeMass(m),
|
||||
cm(centerMass),
|
||||
length(l),
|
||||
innerRadiusTop(inRadTop),
|
||||
outerRadiusTop(outRadTop),
|
||||
innerRadiusBottom(inRadBottom),
|
||||
outerRadiusBottom(outRadBottom),
|
||||
needsRecomputing(false),
|
||||
childParts()
|
||||
{ }
|
||||
|
||||
Part::~Part()
|
||||
{}
|
||||
|
11
model/Part.h
11
model/Part.h
@ -21,7 +21,16 @@ namespace model
|
||||
class Part
|
||||
{
|
||||
public:
|
||||
Part();
|
||||
Part(const std::string& name,
|
||||
const Matrix3& I,
|
||||
double m,
|
||||
const Vector3& centerMass,
|
||||
double length,
|
||||
double inRadTop,
|
||||
double outRadTop,
|
||||
double inRadBottom,
|
||||
double outRadBottom);
|
||||
|
||||
virtual ~Part();
|
||||
|
||||
Part(const Part&);
|
||||
|
@ -5,6 +5,7 @@
|
||||
// C headers
|
||||
// C++ headers
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
// 3rd party headers
|
||||
/// \endcond
|
||||
@ -37,7 +38,12 @@ public:
|
||||
|
||||
virtual double getMass(double t) override
|
||||
{
|
||||
return topPart.getCompositeMass(t) + mm.getMass(t);
|
||||
if(topPart)
|
||||
{
|
||||
return topPart->getCompositeMass(t) + mm.getMass(t);
|
||||
}
|
||||
else
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
virtual double getDragCoefficient() override { return 1.0 ;}
|
||||
@ -58,7 +64,7 @@ public:
|
||||
private:
|
||||
std::string name;
|
||||
|
||||
Part topPart;
|
||||
std::shared_ptr<Part> topPart;
|
||||
|
||||
model::MotorModel mm;
|
||||
Vector3 motorModelPosition; // position of motor cg w.r.t. the stage c.g.
|
||||
|
15
model/tests/CMakeLists.txt
Normal file
15
model/tests/CMakeLists.txt
Normal file
@ -0,0 +1,15 @@
|
||||
enable_testing()
|
||||
|
||||
add_executable(model_tests
|
||||
PartTests.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(model_tests PRIVATE
|
||||
model
|
||||
utils
|
||||
GTest::gtest_main
|
||||
)
|
||||
|
||||
include(GoogleTest)
|
||||
gtest_discover_tests(model_tests)
|
||||
|
80
model/tests/PartTests.cpp
Normal file
80
model/tests/PartTests.cpp
Normal file
@ -0,0 +1,80 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "model/Part.h"
|
||||
|
||||
class PartTest : public testing::Test
|
||||
{
|
||||
protected:
|
||||
// Per-test-suite set-up.
|
||||
// Called before the first test in this test suite.
|
||||
// Can be omitted if not needed.
|
||||
static void SetUpTestSuite()
|
||||
{
|
||||
//shared_resource_ = new ...;
|
||||
|
||||
// If `shared_resource_` is **not deleted** in `TearDownTestSuite()`,
|
||||
// reallocation should be prevented because `SetUpTestSuite()` may be called
|
||||
// in subclasses of FooTest and lead to memory leak.
|
||||
//
|
||||
// if (shared_resource_ == nullptr) {
|
||||
// shared_resource_ = new ...;
|
||||
// }
|
||||
}
|
||||
|
||||
// Per-test-suite tear-down.
|
||||
// Called after the last test in this test suite.
|
||||
// Can be omitted if not needed.
|
||||
static void TearDownTestSuite()
|
||||
{
|
||||
//delete shared_resource_;
|
||||
//shared_resource_ = nullptr;
|
||||
}
|
||||
|
||||
// You can define per-test set-up logic as usual.
|
||||
void SetUp() override { }
|
||||
|
||||
// You can define per-test tear-down logic as usual.
|
||||
void TearDown() override { }
|
||||
|
||||
// Some expensive resource shared by all tests.
|
||||
//static T* shared_resource_;
|
||||
};
|
||||
|
||||
//T* FooTest::shared_resource_ = nullptr;
|
||||
|
||||
TEST(PartTest, CreationTests)
|
||||
{
|
||||
Matrix3 inertia;
|
||||
inertia << 1, 0, 0,
|
||||
0, 1, 0,
|
||||
0, 0, 1;
|
||||
Vector3 cm{1, 0, 0};
|
||||
model::Part testPart("testPart",
|
||||
inertia,
|
||||
1.0,
|
||||
cm,
|
||||
2.0,
|
||||
1.0,
|
||||
1.1,
|
||||
1.1,
|
||||
1.0);
|
||||
|
||||
Matrix3 inertia2;
|
||||
inertia2 << 1, 0, 0,
|
||||
0, 1, 0,
|
||||
0, 0, 1;
|
||||
Vector3 cm2{1, 0, 0};
|
||||
model::Part testPart2("testPart2",
|
||||
inertia2,
|
||||
1.0,
|
||||
cm2,
|
||||
2.0,
|
||||
1.0,
|
||||
1.1,
|
||||
1.1,
|
||||
1.0);
|
||||
Vector3 R{2.0, 2.0, 2.0};
|
||||
testPart.addChildPart(testPart2, R);
|
||||
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user