Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Comparison of odml objects #265

@rickskyy

Description

@rickskyy

I was testing RDFReader and ran into the problem with comparing odml objects. The thing is after building an odml document from an RDF graph the initial order of values, properties and sections become lost. That is why I cannot simply check if the processed document after conversion is equal to initial one. (See tests in test_parser.py)

For example:

Although the lists [<Section TheStarship[starship] (1)>, <Section TheCrew[crew] (4)>] and [<Section TheCrew[crew] (4)>, <Section TheStarship[starship] (1)>] contains same objects, the lists object itself are not equal. The same case happens with all attributes of base odml classes that have list values.

From conceptual view do the lists from above example are considered equal if its consist of an equal set of elements? If so can I add code to __eq__ method of baseobject(_baseobj) class to process the described cases?

The most straightforward way:

  1. If the attribute value is the instance of a list compare the length, return false if different.
  2. Compare each element from the first to each element from the second and track the number the same objects which should be equal to the number of elements in each list.

I implemented this method and all tests have passed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions