Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Error Message for Gauge when checking Lists for an Element #101

Open
thedodobird2 opened this issue Jul 23, 2019 · 1 comment
Open

Comments

@thedodobird2
Copy link
Collaborator

thedodobird2 commented Jul 23, 2019

When a JsonGauge checks a list of elements for a certain element using containsElementFitting, but doesn't fit any (for multiple reasons), the error message isn't very helpful.
For example: The name attribute is only correct for one element in the list BUT another attribute of that 'correct' element does not match. This puts it on the same level and your gauge will just say it couldn't find a matching element. Even though there is one that is quite like it.

Proposal:

  • Find the elements with the most correct matches
  • Put these elements in a list
  • Output these "most similar elements" into the error message

Imagine the JSON array would be

{
  "universities": [
    {
      "name": "Universität Leiden",
      "begin": 1948,
      "end": 1956
    },
    {
      "name": "Mathematisch Centrum Amsterdam",
      "begin": 1951,
      "end": 1959
    },
    {
      "name": "Technische Universiteit Eindhoven",
      "begin": 1962,
      "end": 1984
    },
    {
      "name": "University of Texas at Austin",
      "begin": 1984,
      "end": 1999
    }
  ]
}

And the following test would be used

"The universities array"  should "contain an element with the expected values" in {
    universities containsElementFitting values of
      """{
        | "name": "Technische Universiteit Eindhoven",
        | "begin": 1962,
        | "end": 2084
        | }""".stripMargin
  }

Then it would fail with

[{"name":"Universität Leiden","begin":1948,"end":1956},{"name":"Mathematisch Centrum Amsterdam","begin":1951,"end":1959},{"name":"Technische Universiteit Eindhoven","begin":1962,"end":1984},{"name":"University of Texas at Austin","begin":1984,"end":1999}] did not contain an element, which matched the gauge definition {
 "name": "Technische Universiteit Eindhoven",
 "begin": 1962,
 "end": 2084
 }

But preferably it would be

[{"name":"Universität Leiden","begin":1948,"end":1956},{"name":"Mathematisch Centrum Amsterdam","begin":1951,"end":1959},{"name":"Technische Universiteit Eindhoven","begin":1962,"end":1984},{"name":"University of Texas at Austin","begin":1984,"end":1999}] 
did not contain an element, which matched the gauge definition {
 "name": "Technische Universiteit Eindhoven",
 "begin": 1962,
 "end": 2084
 }
the closest matches where [
 {"name":"Technische Universiteit Eindhoven","begin":1962,"end":1984}
 Expected :2084 in 'end'
 Actual   :1984
]
@DaniRey
Copy link
Collaborator

DaniRey commented Jul 10, 2020

This would be an improvement, unfortunately it requires a complete rewrite.

A) The objects in the array might have more then one level. A missing element on top-level more important then on a deeper level. Therefore we would have to switch from a depth-first to a breath-first search.
B) As soon as there is a misfit an error is thrown, the search is aborted. Gathering errors adds complexity and leads to worse performance. On JSON arrays of reasonable size this shouldn't be an issue, nevertheless it might be one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants