From cbf9c74c065194dd4ac2d350bbd580a09a575848 Mon Sep 17 00:00:00 2001 From: Ayman Habib Date: Fri, 27 Sep 2024 09:32:12 -0700 Subject: [PATCH] Fix matlab tests (#3886) * update API to latest per 4.5.1 * use randi rather than randsample that was moved to a different toolbox * Add tolerance to floating point comparisons after applying a transformation --- .../tests/testConnectorsInputsOutputs.m | 4 +-- Bindings/Java/Matlab/tests/testOsimC3D.m | 25 ++++++++++--------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/Bindings/Java/Matlab/tests/testConnectorsInputsOutputs.m b/Bindings/Java/Matlab/tests/testConnectorsInputsOutputs.m index 8061e53604..07a5b21a6e 100644 --- a/Bindings/Java/Matlab/tests/testConnectorsInputsOutputs.m +++ b/Bindings/Java/Matlab/tests/testConnectorsInputsOutputs.m @@ -13,8 +13,8 @@ source = TableSource(); source.setName('source'); table = TimeSeriesTable(); -labels = StdVectorString(4); -labels.set(0, 'c1'); labels.set(1, 'c2'); labels.set(2, 'c3'); labels.set(3, 'c4'); +labels = StdVectorString(); +labels.add('c1'); labels.add('c2'); labels.add('c3'); labels.add('c4'); table.setColumnLabels(labels); row = RowVector(4, 1.0); table.appendRow(0.0, row); diff --git a/Bindings/Java/Matlab/tests/testOsimC3D.m b/Bindings/Java/Matlab/tests/testOsimC3D.m index 8efd3547dd..7f118cb115 100644 --- a/Bindings/Java/Matlab/tests/testOsimC3D.m +++ b/Bindings/Java/Matlab/tests/testOsimC3D.m @@ -48,8 +48,8 @@ % col numbers. % Test Marker Rotations -randomRows = randsample(markers.getNumRows(),10)-1; -randomCols = randsample(markers.getNumColumns(),10)-1; +randomRows = randi(markers.getNumRows(),10)-1; +randomCols = randi(markers.getNumColumns(),10)-1; for i = 1 : 10 % Get the values in the original and rotated marker tables loc = osimVec3ToArray(markers.getRowAtIndex(randomRows(i)).get(randomCols(i))); @@ -68,8 +68,8 @@ end % Test Force Rotations -randomRows = randsample(forces.getNumRows(),6)-1; -randomCols = randsample(forces.getNumColumns(),6)-1; +randomRows = randi(forces.getNumRows(),6)-1; +randomCols = randi(forces.getNumColumns(),6)-1; for i = 1 : 6 % Get the values in the original and rotated marker tables val = osimVec3ToArray(forces.getRowAtIndex(randomRows(i)).get(randomCols(i))); @@ -93,7 +93,7 @@ % Forces should remain unchanged, point and moments should be in meters % (divided by 1000) -randomRows = randsample(forces.getNumRows(),101)-1; +randomRows = randi(forces.getNumRows(),101)-1; for i = 0 : forces_m.getNumColumns() - 1 col = forces_rotated.getDependentColumnAtIndex(i); @@ -106,17 +106,18 @@ d = col.get(randomRows(u)); d_m = col_m.get(randomRows(u)); - assert(d.get(0)==d_m.get(0),'Force Data has been incorrectly altered'); - assert(d.get(1)==d_m.get(1),'Force Data has been incorrectly altered') - assert(d.get(2)==d_m.get(2),'Force Data has been incorrectly altered') + assert(abs(d.get(0)-d_m.get(0))<.001,'Force Data has been incorrectly altered'); + assert(abs(d.get(1)-d_m.get(1))<.001,'Force Data has been incorrectly altered'); + assert(abs(d.get(2)-d_m.get(2))<.001,'Force Data has been incorrectly altered'); + else % Get the values d = col.get(randomRows(u)); d_m = col_m.get(randomRows(u)); - - assert(d.get(0)/1000==d_m.get(0),'Point or Moment Data has been incorrectly altered'); - assert(d.get(1)/1000==d_m.get(1),'Point or Moment Data has been incorrectly altered'); - assert(d.get(2)/1000==d_m.get(2),'Point or Moment Data has been incorrectly altered'); + assert(abs(d.get(0)/1000-d_m.get(0))<.001,'Point or Moment Data has been incorrectly altered'); + assert(abs(d.get(1)/1000-d_m.get(1))<.001,'Point or Moment Data has been incorrectly altered'); + assert(abs(d.get(2)/1000-d_m.get(2))<.001,'Point or Moment Data has been incorrectly altered'); + end end end