yamlmatlab icon indicating copy to clipboard operation
yamlmatlab copied to clipboard

cellarray of struct donesn't correctly check fields to precede in makematrices of ReadYaml

Open babaq opened this issue 9 years ago • 2 comments

I have a yaml file like this:

condtestpath: ConditionTest_V1_358_conditiontest_1.yaml condtest: CONDSTATE:

  • - PREICI: 20.2806
    • COND: 128.3246
    • SUFICI: 632.8663
  • - PREICI: 733.4108
    • COND: 833.4752
    • SUFICI: 1333.7605
  • - PREICI: 1451.4685
    • COND: 1566.3031
    • SUFICI: 2083.5186
  • - PREICI: 2198.9955
    • COND: 2300.4615
    • SUFICI: 2801.3268
  • - PREICI: 2916.3761
    • COND: 3032.1373
    • SUFICI: 3532.1772
  • - PREICI: 3644.487
    • COND: 3746.5744
    • SUFICI: 4249.5801
  • - PREICI: 4366.9403
    • COND: 4480.8218
    • SUFICI: 4982.1106
  • - PREICI: 5099.0864
    • COND: 5214.5976
    • SUFICI: 5716.7272

after readyamlraw, in makematrices in function result = iscompatible(obj1, obj2) import yaml.*; result = isequal(class(obj1), class(obj2)); end

it's always return true because it doesn't check if obj1 and obj2 have the same number of fields and if those fields have the same names, so it will precede to try to make a matrices out of the cell array of struct which may not have the same number of fields/names

the quickest way to avoid such thing is to add fields checking, I could make a small PR if you like.

babaq avatar May 23 '16 20:05 babaq

Yes that would be nice. Can you also write a unittest?

ewiger avatar May 24 '16 12:05 ewiger

i looked at my hack again, and not sure if it deserve a unittest.

Basically, i just replace a line of code and make it more strict as to whether to tried to build a matrix out of a array of struct, so my data wouldn't pass the check and leave it to me to further process.

function result = iscompatible(obj1, obj2)
import yaml.*;
% result = isequal(class(obj1), class(obj2));
result = isequal( fieldnames(obj1),fieldnames(obj2));
end

I am not sure this modification altered any other function behavior that the code originally means. but if you are sure the modification is valid, i could try to write a test with my data (I have to admit i seldom write unit test, bad habit, i know :).

Also, i run the selftest_yamlmatlab and it showed this:

::SELFTEST REPORT::

Selftest report from:21-Jun-2016 12:00:41

test_ReadYaml

test_ReadYaml:

Passed

test_RY_FloatingPoints:

Failed, Crash

test_RY_Import:

Failed, Crash

test_RY_ImportDef:

Failed, Crash

test_RY_ImportNonex:

Failed, Crash

test_RY_Indentation:

Failed, Crash

test_RY_Inheritance:

Failed, Crash

test_RY_InheritanceLoop:

Failed, Crash

test_RY_InheritanceMultiple:

Failed, Crash

test_RY_Matrices:

Failed, Crash

test_RY_SequenceMapping:

Failed, Crash

test_RY_Simple:

Failed, Crash

test_RY_Time:

Failed, Crash

test_RY_TimeVariants:

Failed, Crash

test_RY_Whitespaces:

Failed, Crash

test_RY_usecase_01:

Failed, Crash

test_WriteYaml

test_WriteYaml:

Passed

test_WY_ComplexStructure:

Failed, Crash

test_WY_FloatingPoints:

Failed, Crash

test_WY_Indentation:

Failed, Crash

test_WY_Matrices:

Failed, Crash

test_WY_SequenceMapping:

Failed, Crash

test_WY_Simple:

Failed, Crash

test_WY_Time:

Failed, Crash

test_WY_usecase_01:

Failed, Crash

babaq avatar Jun 21 '16 19:06 babaq