Skip to content

[WIP] Add analysis clone assign cases #2116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions Applications/Analyze/test/testAnalyzeTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@
#include <OpenSim/Analyses/OutputReporter.h>
#include <OpenSim/Auxiliary/auxiliaryTestFunctions.h>
#include <OpenSim/Auxiliary/auxiliaryTestMuscleFunctions.h>
#include <OpenSim/Analyses/osimAnalyses.h>

using namespace OpenSim;
using namespace std;

void testTutorialOne();
void testAnalyses();

// Test different default activations are respected when activation
// states are not provided.
Expand All @@ -44,6 +46,11 @@ int main()
{
SimTK::Array_<std::string> failures;

try { testAnalyses(); }
catch (const std::exception& e) {
cout << e.what() << endl; failures.push_back("testAnalyses");
}

try { testTutorialOne(); }
catch (const std::exception& e) {
cout << e.what() << endl; failures.push_back("testTutorialOne");
Expand Down Expand Up @@ -79,6 +86,46 @@ int main()
return 0;
}


void testAnalyses() {

Kinematics* temp = new Kinematics();

// Get all the Analyses
AnalysisSet availableAnalyses;
AnalysisSet::getAvailableAnalyses(availableAnalyses);

const std::string original{ "original" };
const std::string modified{ "modified" };


for (int i = 0; i < availableAnalyses.getSize(); ++i) {
Analysis* analysis = &availableAnalyses.get(i);
cout << "Testing clone and assignment of "
<< analysis->getConcreteClassName() << "." << endl;

randomize(analysis);
analysis->setName(original);
Analysis* clone = analysis->clone();

// perform an edit on the original
analysis->setName(modified);

// restore analysis to its unedited state
analysis->assign( *clone );

ASSERT(*analysis == *clone);

delete clone;

ASSERT(analysis->getName() == original);

cout << "PASSED clone and assignment for "
<< analysis->getConcreteClassName() << "." << endl;
}
}


void testTutorialOne() {
AnalyzeTool analyze1("PlotterTool.xml");
analyze1.getModel().print("testAnalyzeTutorialOne.osim");
Expand Down
23 changes: 22 additions & 1 deletion Bindings/Java/tests/TestBasics.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,33 @@ public static void testScaleToolUtils() {
ModelScaler ms = new ModelScaler();
Scale s = new Scale();
ms.addScale(s);
}
}

public static void testAnalyses() {
// Get all the Analyses
AnalysisSet availableAnalyses = new AnalysisSet();
AnalysisSet.getAvailableAnalyses(availableAnalyses);

for (int i = 0; i < availableAnalyses.getSize(); ++i) {
Analysis analysis = availableAnalyses.get(i);

OpenSimObject clone = analysis.clone();

// restore analysis to its unedited state
analysis.assign( clone );

System.out.println(analysis.dump());
System.out.println(clone.dump());
}
}


public static void main(String[] args) {
testBasics();
testMuscleList();
testToyReflexController();
testScaleToolUtils();
testAnalyses();

System.out.println("Test finished!");
// TODO to cause test to fail: System.exit(-1);
Expand Down