Skip to content

JSON matchers: wrong result when comparing arrays of objects #83

@naushniki

Description

@naushniki

[ { "a": 1, "z": 1 }, { "a": 2, "z": 2 } ]
[ { "a": 2, "z": 2 }, { "z": 1, "a": 1 } ]

The example above is two arrays of equal objects. These arrays cannot be matched effectively using any ArrayComparisonMode.

  • Strict: Arrays are considered unequal, because the order of objects is different.
  • Unordered: Arrays are sorted using string representation of object as the sorting key. Field order in equal objects is different. Arrays are considered unequal because of that.
  • Permutation-based: The example contains only 2 objects in each array to be human readable. Unfortunately, permutation based comparison cannot be used on arrays containing 10 or more elements, because number of possible permutations is n! (n factorial).

Proposed solution: optimize sorting in "unordered" comparison mode, so that string representations of two equal objects are equal strings.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions