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

add-similarity-to-contain (#53) #3939

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

AlexCue987
Copy link
Member

add search for similarity to contain for example:

         "print a similar key when no exact match" {
            val message = shouldThrow<AssertionError> {
               mapOf(sweetGreenApple to 1, sweetRedApple to 2) should contain(sweetGreenPear, 1)
            }.message
            message shouldContain """
               | expected: Fruit(name=apple, color=green, taste=sweet),
               |  but was: Fruit(name=pear, color=green, taste=sweet),
               |  The following fields did not match:
               |    "name" expected: <"apple">, but was: <"pear">
            """.trimMargin()
         }
         "print entries with same value" {
            val message = shouldThrow<AssertionError> {
               mapOf(sweetGreenApple to 1, sweetRedApple to 2) should contain(sweetGreenPear, 1)
            }.message
            message shouldContain """
               |Same value found for the following entries: [Fruit(name=apple, color=green, taste=sweet)=1]
            """.trimMargin()
         }
         "print entries with similar values" {
            val message = shouldThrow<AssertionError> {
               mapOf(1 to sweetGreenApple, 2 to sweetRedApple) should contain(3, sweetGreenPear)
            }.message
            message shouldContain """
               | expected: Fruit(name=apple, color=green, taste=sweet),
               |  but was: Fruit(name=pear, color=green, taste=sweet),
               |  The following fields did not match:
               |    "name" expected: <"apple">, but was: <"pear">
            """.trimMargin()
         }

@Kantis
Copy link
Member

Kantis commented May 9, 2024

I feel it's kind of ambiguous what we're looking at in the failure messages. Was it the wrong key or value?

Perhaps we should produce a similarity-score for each Map.Entry and just print the closest one, taking both key and value into consideration?

@AlexCue987
Copy link
Member Author

I feel it's kind of ambiguous what we're looking at in the failure messages. Was it the wrong key or value?

Perhaps we should produce a similarity-score for each Map.Entry and just print the closest one, taking both key and value into consideration?

I like the idea of finding the most similar Map.Entry, and I'll do that, and output it first. But I perceive good value in printing other distinct cases that may be helpful, such as "there is a very similar value with a completely different key".

@AlexCue987
Copy link
Member Author

I feel it's kind of ambiguous what we're looking at in the failure messages. Was it the wrong key or value?

Perhaps we should produce a similarity-score for each Map.Entry and just print the closest one, taking both key and value into consideration?

At this time I know how to take "both key and value into consideration" only when they both are data classes. But for the cases when only the key or only the value is a data class, IMO we should keep the existing logic.

So let's merge this as is, and add support for taking "both key and value into consideration" later on. Sounds like a good plan?

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

Successfully merging this pull request may close these issues.

None yet

2 participants