Skip to content

Improve failure output for Set comparison #924

Closed

Description

@masooh

When two sets are compared I would like to see the mutual exclusive values in the output. See new lines 'excl: ...'

Condition not satisfied:

oneSet == anotherSet
|      |  |
|      |  [3, 6, 4, 5]
|      |  excl: [6]
|      false
[4, 3, 1, 5, 2]
excl: [1,2]

Used sample feature:

def "sets are equal"() {
    given:
    Set oneSet = [4,3,1,5,1,4,2]
    Set anotherSet = [3,6,4,3,5]

    expect:
    oneSet == anotherSet
}

Activity

  1. masooh commented on Sep 28, 2018

    @masooh
    Author

    Here's another approach for rendering the differences (like in String comparison):

    oneSet == anotherSet
    |      |  |
    |      |  [3, 6, 4, 5]
    |      false
    |      3 differences (2 only in actual, 1 only in expected)
    |      [(1),(2),3,4,5,(-)]
    |      [(-),(-),3,4,5,(6)]
    [4, 3, 1, 5, 2]
    

    This would require to sort the sets for rendering.

  2. leonard84 commented on Sep 28, 2018

    @leonard84
    Member

    Interesting suggestion, another possibility could be:

    oneSet == anotherSet
    |      |  |
    |      |  [3, 6, 4, 5]
    |      false
    |      3 differences (2 missing, 1 extra)
    |      missing: 1, 2
    |      extra: 6
    [4, 3, 1, 5, 2]
    

    The relevant code is located here org.spockframework.runtime.ExpressionInfoValueRenderer#doRenderValue.

  3. tylerbenson commented on Sep 28, 2018

    @tylerbenson

    💯 This would be awesome! Could potentially be useful for other types of collections too (lists and maps).

  4. added a commit that references this issue on Sep 29, 2018
    48f72c8
  5. leonard84 commented on Sep 29, 2018

    @leonard84
    Member

    @tylerbenson lists and maps will are more difficult, since order or values are relevant as well.

  6. self-assigned this
    on Sep 29, 2018
  7. added a commit that references this issue on Sep 29, 2018
    db0fd70
  8. added this to the 1.3 milestone on Sep 29, 2018
  9. added a commit that references this issue on Oct 9, 2018
    c797781
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions