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

Map containsOnly with pairs #68

Closed
robstoll opened this issue Jan 20, 2019 · 1 comment · Fixed by #726
Closed

Map containsOnly with pairs #68

robstoll opened this issue Jan 20, 2019 · 1 comment · Fixed by #726
Assignees
Labels
help wanted needs votes otherwise it will be ignored
Milestone

Comments

@robstoll
Copy link
Owner

robstoll commented Jan 20, 2019

Platform (JVM, JS and/or Android): all

Code related feature

assert(mapOf("a" to 1, "b" to 2)).containsOnly("b" to 2, "a" to 1)

Where InAnyOrder is implicit for Maps as they are usually unordered

Currently we can do the following to achieve the same

assert(mapOf("a" to 1, "b" to 2)).asEntries().contains.inAnyOrder.only.entries(
  { isKeyValue("b", 2) }, 
  { isKeyValue("a", 1) }
)

Clearly the shortcut is easier to write and read.
Moreover, the reporting could be improved. With asEntries()... it looks as follows (contains c to 2 and b to 1):

assert: {a=1, b=2}        (java.util.LinkedHashMap <873610597>)
◆ contains only, in any order: 
  ✘ an entry which: 
      » ▶ key:        <1497845528>
          ◾ to be: "c"        <1710989308>
      » ▶ value:        (kotlin.Int <1047087935>)
          ◾ to be: 2        (kotlin.Int <464887938>)
  ✘ an entry which: 
      » ▶ key:        <1497845528>
          ◾ to be: "d"        <1710989308>
      » ▶ value:        (kotlin.Int <1047087935>)
          ◾ to be: 2        (kotlin.Int <464887938>)
  ✘ an entry which: 
      » ▶ key:        <1497845528>
          ◾ to be: "b"        <2020152163>
      » ▶ value:        (kotlin.Int <1047087935>)
          ◾ to be: 1        (kotlin.Int <1047087935>)
  ✘ ▶ size: 2
      ◾ to be: 3
  ❗❗ following entries were mismatched: 
     ⚬ a=1        (java.util.LinkedHashMap.Entry <1104443373>)
     ⚬ b=2        (java.util.LinkedHashMap.Entry <898694235>)

comparing it to Map.contains:

assert: {a=1, b=2}        (java.util.LinkedHashMap <503938393>)
◆ contains, in any order: 
  ⚬ ▶ entry "c": ❗❗ key does not exist
        » to be: 2        (kotlin.Int <970865974>)
  ⚬ ▶ entry "d": ❗❗ key does not exist
        » to be: 2        (kotlin.Int <970865974>)
  ⚬ ▶ entry "b": 2        (kotlin.Int <970865974>)
      ◾ to be: 1        (kotlin.Int <1827171553>)

I would imagine a reporting like the following:

◆ ▶ size: 2
    ◾ to be: 3
◆ contains only, in any order: 
  ✘ entry "c": ❗❗ key does not exist
       » to be: 2        (kotlin.Int <970865974>)
  ✘ entry "d": ❗❗ key does not exist
       » to be: 2        (kotlin.Int <970865974>)
  ✘ entry "b": 2
       » to be: 1        (kotlin.Int <1827171553>)
 ❗❗ following entries were not matched by key at all: 
     ⚬ entry "a": 1       (kotlin.Int <970345974>)

Please react with 👍 if you would like to see this feature implemented in Atrium, the more upvotes the more likely I will implement it myself -- feel free to sponsor me, that would be a motivation too.
You are of course welcome to work on this issue. Write I'll work on it as comment so that we can assign the task to you.

@robstoll robstoll changed the title Map containsInAnyOrderOnly Map containsInAnyOrderOnly with pairs Jan 25, 2019
@robstoll robstoll added the needs votes otherwise it will be ignored label Oct 26, 2019
@robstoll robstoll self-assigned this Nov 19, 2020
@robstoll robstoll added this to the 0.15.0 milestone Nov 19, 2020
@robstoll robstoll changed the title Map containsInAnyOrderOnly with pairs Map containsOnly with pairs Dec 21, 2020
@robstoll
Copy link
Owner Author

@StragaSevera. Let us know in case you miss something about this feature (pinging you as you voted for this issue).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted needs votes otherwise it will be ignored
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant