Skip to content

Commit

Permalink
Gtest added
Browse files Browse the repository at this point in the history
  • Loading branch information
aiksiongkoh committed Jul 15, 2024
1 parent be7e357 commit 02870d9
Show file tree
Hide file tree
Showing 152 changed files with 430 additions and 304 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ ELSE()
set( ONDSELSOLVER_BUILD_SHARED OFF )
ENDIF ()

add_compile_definitions(TEST_DATA_PATH="${CMAKE_CURRENT_SOURCE_DIR}/testapp")
add_subdirectory(OndselSolver)
add_subdirectory(OndselSolverMain)
include(CTest)
enable_testing()
add_subdirectory(tests)

target_compile_definitions(test_run PUBLIC TEST_DATA_PATH="${CMAKE_CURRENT_SOURCE_DIR}/testapp")
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/OndselSolverMain PROPERTY VS_STARTUP_PROJECT OndselSolverMain)
2 changes: 1 addition & 1 deletion OndselSolver/ASMTAllowRotation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ std::shared_ptr<ItemIJ> MbD::ASMTAllowRotation::mbdClassNew()
return AllowZRotation::With();
}

void MbD::ASMTAllowRotation::setMotionJoint(std::string motionJoint)
void MbD::ASMTAllowRotation::setMotionJoint(const std::string& motionJoint)
{
(void) motionJoint;
}
Expand Down
2 changes: 1 addition & 1 deletion OndselSolver/ASMTAllowRotation.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace MbD {
void readMotionJoint(std::vector<std::string>& lines);
void initMarkers() override;
std::shared_ptr<ItemIJ> mbdClassNew() override;
void setMotionJoint(std::string motionJoint);
void setMotionJoint(const std::string& motionJoint);
void storeOnLevel(std::ofstream& os, size_t level) override;
void storeOnTimeSeries(std::ofstream& os) override;

Expand Down
28 changes: 14 additions & 14 deletions OndselSolver/ASMTAssembly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ void MbD::ASMTAssembly::runSinglePendulum()
assembly->runKINEMATIC();
}

std::shared_ptr<ASMTAssembly> MbD::ASMTAssembly::assemblyFromFile(const char* fileName)
std::shared_ptr<ASMTAssembly> MbD::ASMTAssembly::assemblyFromFile(const std::string& fileName)
{
std::filesystem::path currentPath = std::filesystem::current_path();
std::cout << "Current directory: " << currentPath << std::endl;
Expand All @@ -380,7 +380,7 @@ std::shared_ptr<ASMTAssembly> MbD::ASMTAssembly::assemblyFromFile(const char* fi
return assembly;
}

void MbD::ASMTAssembly::runFile(const char* fileName)
void MbD::ASMTAssembly::runFile(const std::string& fileName)
{
std::ifstream stream(fileName);
if (stream.fail()) {
Expand Down Expand Up @@ -538,7 +538,7 @@ void MbD::ASMTAssembly::runDraggingTest3()
rotMat = rotPart->rotationMatrix;
}

void MbD::ASMTAssembly::readWriteFile(const char* fileName)
void MbD::ASMTAssembly::readWriteFile(const std::string& fileName)
{
std::ifstream stream(fileName);
if (stream.fail()) {
Expand Down Expand Up @@ -575,7 +575,7 @@ ASMTAssembly* MbD::ASMTAssembly::root()
return this;
}

void MbD::ASMTAssembly::setNotes(std::string str)
void MbD::ASMTAssembly::setNotes(const std::string& str)
{
notes = str;
}
Expand Down Expand Up @@ -1044,7 +1044,7 @@ void MbD::ASMTAssembly::readMotionSeries(std::vector<std::string>& lines)
motion->readMotionSeries(lines);
}

void MbD::ASMTAssembly::runDraggingLog(const char* fileName)
void MbD::ASMTAssembly::runDraggingLog(const std::string& fileName)
{
std::ifstream stream(fileName);
if (stream.fail()) {
Expand Down Expand Up @@ -1274,7 +1274,7 @@ void MbD::ASMTAssembly::createMbD(std::shared_ptr<System> mbdSys, std::shared_pt
// animationParameters = nullptr;
}

void MbD::ASMTAssembly::outputFile(std::string filename)
void MbD::ASMTAssembly::outputFile(const std::string& filename)
{
std::ofstream os(filename);
os << std::setprecision(std::numeric_limits<double>::max_digits10);
Expand Down Expand Up @@ -1462,7 +1462,7 @@ MbD::ASMTAssembly::spatialContainerAt(std::shared_ptr<ASMTAssembly> self,
return part;
}

std::shared_ptr<ASMTPart> MbD::ASMTAssembly::partAt(std::string& longname) const
std::shared_ptr<ASMTPart> MbD::ASMTAssembly::partAt(const std::string& longname) const
{
for (auto& part : *parts) {
if (part->fullName("") == longname) {
Expand All @@ -1472,7 +1472,7 @@ std::shared_ptr<ASMTPart> MbD::ASMTAssembly::partAt(std::string& longname) const
return nullptr;
}

std::shared_ptr<ASMTMarker> MbD::ASMTAssembly::markerAt(std::string& longname) const
std::shared_ptr<ASMTMarker> MbD::ASMTAssembly::markerAt(const std::string& longname) const
{
for (auto& refPoint : *refPoints) {
for (auto& marker : *refPoint->markers) {
Expand All @@ -1493,7 +1493,7 @@ std::shared_ptr<ASMTMarker> MbD::ASMTAssembly::markerAt(std::string& longname) c
return nullptr;
}

std::shared_ptr<ASMTJoint> MbD::ASMTAssembly::jointAt(std::string& longname) const
std::shared_ptr<ASMTJoint> MbD::ASMTAssembly::jointAt(const std::string& longname) const
{
auto it =
std::find_if(joints->begin(), joints->end(), [&](const std::shared_ptr<ASMTJoint>& jt) {
Expand All @@ -1503,7 +1503,7 @@ std::shared_ptr<ASMTJoint> MbD::ASMTAssembly::jointAt(std::string& longname) con
return joint;
}

std::shared_ptr<ASMTMotion> MbD::ASMTAssembly::motionAt(std::string& longname) const
std::shared_ptr<ASMTMotion> MbD::ASMTAssembly::motionAt(const std::string& longname) const
{
auto it =
std::find_if(motions->begin(), motions->end(), [&](const std::shared_ptr<ASMTMotion>& mt) {
Expand All @@ -1513,7 +1513,7 @@ std::shared_ptr<ASMTMotion> MbD::ASMTAssembly::motionAt(std::string& longname) c
return motion;
}

std::shared_ptr<ASMTForceTorque> MbD::ASMTAssembly::forceTorqueAt(std::string& longname) const
std::shared_ptr<ASMTForceTorque> MbD::ASMTAssembly::forceTorqueAt(const std::string& longname) const
{
auto it = std::find_if(forcesTorques->begin(),
forcesTorques->end(),
Expand Down Expand Up @@ -1625,7 +1625,7 @@ void MbD::ASMTAssembly::setSimulationParameters(
parameters->owner = this;
}

std::shared_ptr<ASMTPart> MbD::ASMTAssembly::partNamed(std::string partName) const
std::shared_ptr<ASMTPart> MbD::ASMTAssembly::partNamed(const std::string& partName) const
{
auto it = std::find_if(parts->begin(), parts->end(), [&](const std::shared_ptr<ASMTPart>& prt) {
return prt->fullName("") == partName;
Expand All @@ -1634,7 +1634,7 @@ std::shared_ptr<ASMTPart> MbD::ASMTAssembly::partNamed(std::string partName) con
return part;
}

std::shared_ptr<ASMTPart> MbD::ASMTAssembly::partPartialNamed(std::string partialName) const
std::shared_ptr<ASMTPart> MbD::ASMTAssembly::partPartialNamed(const std::string& partialName) const
{
auto it = std::find_if(parts->begin(), parts->end(), [&](const std::shared_ptr<ASMTPart>& prt) {
auto fullName = prt->fullName("");
Expand Down Expand Up @@ -1744,7 +1744,7 @@ void MbD::ASMTAssembly::storeOnTimeSeries(std::ofstream& os)
}
}

void MbD::ASMTAssembly::setFilename(std::string str)
void MbD::ASMTAssembly::setFilename(const std::string& str)
{
std::stringstream ss;
ss << "FileName = " << str << std::endl;
Expand Down
28 changes: 14 additions & 14 deletions OndselSolver/ASMTAssembly.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ namespace MbD {
static void runSinglePendulumSuperSimplified2();
static void runSinglePendulumSimplified();
static void runSinglePendulum();
static std::shared_ptr<ASMTAssembly> assemblyFromFile(const char* chars);
static void runFile(const char* chars);
static std::shared_ptr<ASMTAssembly> assemblyFromFile(const std::string& fileName);
static void runFile(const std::string& chars);
static void runDraggingLogTest();
static void runDraggingLogTest2();
static void runDraggingLogTest3();
static void runDraggingTest();
static void runDraggingTest2();
static void runDraggingTest3();

static void readWriteFile(const char* chars);
static void readWriteFile(const std::string& chars);
void initialize() override;
ASMTAssembly* root() override;
void setNotes(std::string str);
void setNotes(const std::string& str);
void parseASMT(std::vector<std::string>& lines) override;
void readNotes(std::vector<std::string>& lines);
void readParts(std::vector<std::string>& lines);
Expand All @@ -75,7 +75,7 @@ namespace MbD {
void readJointSeries(std::vector<std::string>& lines);
void readMotionSeriesMany(std::vector<std::string>& lines);
void readMotionSeries(std::vector<std::string>& lines);
void runDraggingLog(const char* chars);
void runDraggingLog(const std::string& chars);

void outputFor(AnalysisType type);
void preMbDrun(std::shared_ptr<System> mbdSys);
Expand All @@ -89,7 +89,7 @@ namespace MbD {
std::shared_ptr<std::map<std::string, std::shared_ptr<ASMTMarker>>>markerMap() const;
void deleteMbD() override;
void createMbD(std::shared_ptr<System> mbdSys, std::shared_ptr<Units> mbdUnits) override;
void outputFile(std::string filename);
void outputFile(const std::string& filename);
void storeOnLevel(std::ofstream& os, size_t level) override;

/* This function performs a one shot solve of the assembly.*/
Expand All @@ -102,11 +102,11 @@ namespace MbD {
void runKINEMATIC();
void initprincipalMassMarker();
std::shared_ptr<ASMTSpatialContainer> spatialContainerAt(std::shared_ptr<ASMTAssembly> self, std::string& longname) const;
std::shared_ptr<ASMTPart> partAt(std::string& longname) const;
std::shared_ptr<ASMTMarker> markerAt(std::string& longname) const;
std::shared_ptr<ASMTJoint> jointAt(std::string& longname) const;
std::shared_ptr<ASMTMotion> motionAt(std::string& longname) const;
std::shared_ptr<ASMTForceTorque> forceTorqueAt(std::string& longname) const;
std::shared_ptr<ASMTPart> partAt(const std::string& longname) const;
std::shared_ptr<ASMTMarker> markerAt(const std::string& longname) const;
std::shared_ptr<ASMTJoint> jointAt(const std::string& longname) const;
std::shared_ptr<ASMTMotion> motionAt(const std::string& longname) const;
std::shared_ptr<ASMTForceTorque> forceTorqueAt(const std::string& longname) const;
FColDsptr vOcmO() override;
FColDsptr omeOpO() override;
std::shared_ptr<ASMTTime> geoTime() const;
Expand All @@ -119,8 +119,8 @@ namespace MbD {
void addLimit(std::shared_ptr<ASMTLimit> limit);
void setConstantGravity(std::shared_ptr<ASMTConstantGravity> constantGravity);
void setSimulationParameters(std::shared_ptr<ASMTSimulationParameters> simulationParameters);
std::shared_ptr<ASMTPart> partNamed(std::string partName) const;
std::shared_ptr<ASMTPart> partPartialNamed(std::string partialName) const;
std::shared_ptr<ASMTPart> partNamed(const std::string& partName) const;
std::shared_ptr<ASMTPart> partPartialNamed(const std::string& partialName) const;
void storeOnLevelNotes(std::ofstream& os, size_t level);
void storeOnLevelParts(std::ofstream& os, size_t level);
void storeOnLevelKinematicIJs(std::ofstream& os, size_t level);
Expand All @@ -131,7 +131,7 @@ namespace MbD {
void storeOnLevelLimits(std::ofstream& os, size_t level);
void storeOnLevelGeneralConstraintSets(std::ofstream& os, size_t level);
void storeOnTimeSeries(std::ofstream& os) override;
void setFilename(std::string filename);
void setFilename(const std::string& filename);
void setDebug(bool todebug);

std::string filename = "";
Expand Down
27 changes: 11 additions & 16 deletions OndselSolver/ASMTItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ std::string MbD::ASMTItem::classname()
return answer;
}

void MbD::ASMTItem::setName(std::string str)
void MbD::ASMTItem::setName(const std::string& str)
{
name = str;
}
Expand All @@ -72,7 +72,7 @@ std::string MbD::ASMTItem::readStringOffTop(std::vector<std::string>& args)
return str;
}

FRowDsptr MbD::ASMTItem::readRowOfDoubles(std::string& line)
FRowDsptr MbD::ASMTItem::readRowOfDoubles(const std::string& line)
{
std::istringstream iss(line);
auto readRowOfDoubles = std::make_shared<FullRow<double>>();
Expand All @@ -89,7 +89,7 @@ FRowDsptr MbD::ASMTItem::readRowOfDoublesOffTop(std::vector<std::string>& lines)
return readRowOfDoubles(str);
}

FColDsptr MbD::ASMTItem::readColumnOfDoubles(std::string& line)
FColDsptr MbD::ASMTItem::readColumnOfDoubles(const std::string& line)
{
std::istringstream iss(line);
auto readColumnOfDoubles = std::make_shared<FullColumn<double>>();
Expand All @@ -106,31 +106,31 @@ FColDsptr MbD::ASMTItem::readColumnOfDoublesOffTop(std::vector<std::string>& lin
return readColumnOfDoubles(str);
}

double MbD::ASMTItem::readDouble(std::string& line)
double MbD::ASMTItem::readDouble(const std::string& line)
{
std::istringstream iss(line);
double d;
iss >> d;
return d;
}

int MbD::ASMTItem::readInt(std::string& line)
int MbD::ASMTItem::readInt(const std::string& line)
{
std::istringstream iss(line);
int i;
iss >> i;
return i;
}

size_t MbD::ASMTItem::readSize_t(std::string& line)
size_t MbD::ASMTItem::readSize_t(const std::string& line)
{
std::istringstream iss(line);
size_t i;
iss >> i;
return i;
}

bool MbD::ASMTItem::readBool(std::string& line)
bool MbD::ASMTItem::readBool(const std::string& line)
{
if (line.find("true") != std::string::npos)
{
Expand All @@ -146,7 +146,7 @@ bool MbD::ASMTItem::readBool(std::string& line)
}
}

std::string MbD::ASMTItem::readString(std::string& line)
std::string MbD::ASMTItem::readString(const std::string& line)
{
std::string str = line;
str.erase(str.begin(), std::find_if(str.begin(), str.end(), [](unsigned char ch) { return !std::isspace(ch); }));
Expand All @@ -161,7 +161,7 @@ void MbD::ASMTItem::readName(std::vector<std::string>& lines)
lines.erase(lines.begin());
}

std::string MbD::ASMTItem::fullName(std::string partialName)
std::string MbD::ASMTItem::fullName(const std::string& partialName)
{
std::string longerName = "/" + name + partialName;
if (owner == nullptr) {
Expand All @@ -172,7 +172,7 @@ std::string MbD::ASMTItem::fullName(std::string partialName)
}
}

void MbD::ASMTItem::readDoublesInto(std::string& str, std::string label, FRowDsptr& row)
void MbD::ASMTItem::readDoublesInto(std::string str, std::string label, FRowDsptr& row)
{
auto pos = str.find(label);
assert(pos != std::string::npos);
Expand Down Expand Up @@ -289,12 +289,7 @@ void MbD::ASMTItem::storeOnTimeSeries(std::ofstream&)
assert(false);
}

void MbD::ASMTItem::logString(std::string& str)
void MbD::ASMTItem::logString(const std::string& str)
{
std::cout << str << std::endl;
}

void MbD::ASMTItem::logString(const char* chars)
{
std::cout << chars << std::endl;
}
23 changes: 11 additions & 12 deletions OndselSolver/ASMTItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,22 @@ namespace MbD {
virtual void initialize();
void noop();
virtual std::string classname();
void setName(std::string str);
void setName(const std::string& str);
virtual void parseASMT(std::vector<std::string>& lines);
std::string popOffTop(std::vector<std::string>& lines);
std::string readStringOffTop(std::vector<std::string>& lines);
FRowDsptr readRowOfDoubles(std::string& line);
FRowDsptr readRowOfDoubles(const std::string& line);
FRowDsptr readRowOfDoublesOffTop(std::vector<std::string>& lines);
FColDsptr readColumnOfDoubles(std::string& line);
FColDsptr readColumnOfDoubles(const std::string& line);
FColDsptr readColumnOfDoublesOffTop(std::vector<std::string>& lines);
double readDouble(std::string& line);
int readInt(std::string& line);
size_t readSize_t(std::string& line);
bool readBool(std::string& line);
std::string readString(std::string& line);
double readDouble(const std::string& line);
int readInt(const std::string& line);
size_t readSize_t(const std::string& line);
bool readBool(const std::string& line);
std::string readString(const std::string& line);
void readName(std::vector<std::string>& lines);
virtual std::string fullName(std::string partialName);
void readDoublesInto(std::string& str, std::string label, FRowDsptr& row);
virtual std::string fullName(const std::string& partialName);
void readDoublesInto(std::string str, std::string label, FRowDsptr& row);
virtual void deleteMbD();
virtual void createMbD(std::shared_ptr<System> mbdSys, std::shared_ptr<Units> mbdUnits);
virtual void updateFromMbD();
Expand All @@ -63,8 +63,7 @@ namespace MbD {
virtual void storeOnLevelArray(std::ofstream& os, size_t level, std::vector<double> array);
virtual void storeOnLevelName(std::ofstream& os, size_t level);
virtual void storeOnTimeSeries(std::ofstream& os);
void logString(std::string& str);
void logString(const char* chars);
void logString(const std::string& str);

std::string name;
ASMTItem* owner = nullptr;
Expand Down
4 changes: 2 additions & 2 deletions OndselSolver/ASMTItemIJ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ void MbD::ASMTItemIJ::initialize()
tzs = std::make_shared<FullRow<double>>();
}

void MbD::ASMTItemIJ::setMarkerI(std::string mkrI)
void MbD::ASMTItemIJ::setMarkerI(const std::string& mkrI)
{
markerI = mkrI;
}

void MbD::ASMTItemIJ::setMarkerJ(std::string mkrJ)
void MbD::ASMTItemIJ::setMarkerJ(const std::string& mkrJ)
{
markerJ = mkrJ;
}
Expand Down
Loading

0 comments on commit 02870d9

Please sign in to comment.