GithubHelp home page GithubHelp logo

Comments (3)

lukas-krecan avatar lukas-krecan commented on August 16, 2024

That's an interesting issue. The reason is simple. If the library takes into account the array order, it knows which elements to compare. If it ignores the order, the task is much harder. Imagine the following example

[{"key":1}, {"key":2}, {"key":3}]

If I compare it with this array

 [{"key":2}, {"key":3}, {"key":4}]

what the error message should say? That we have expected 1 but got 4? Or that we expected 3 and got 4? It's quite hard problem to decide if the order in the array has to be ignored. Moreover there can be more than one difference and the structures may be quite deep.

I have to think about it.

from jsonunit.

lukas-krecan avatar lukas-krecan commented on August 16, 2024

In general, it can not be solved. If there is only one difference, we can describe it. For [1, 2, 3, 4] vs [2, 3, 4, 5] we can say that 1!=5 (the question is, if it makes sense). But if there is more than one difference, I can't say which elements are different. In [1, 2, 3, 4] vs. [4, 5, 6, 7] I do not know if 2!=5 or 2!=6 or 2!=7.

While it can not be solved in general, in theory we can do something for your special case. We can compare the elements that are most alike. In your case compare elements with the same "iso" field. Unfortunately it has quadratic time complexity and I am not sure if it's worth it. But if you have any idea how to solve the problem, I'd like to hear it.

from jsonunit.

yruicdl avatar yruicdl commented on August 16, 2024

I agree with you, it's hard to solve this problem in general. We can do some preparation before doing compare. Anyway, thanks for explanation! I really like jsonunit, it's an awesome library :)

from jsonunit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.