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

Can we make containsAll fail when the expected argument is an empty list? #359

Closed
matthid opened this issue Nov 1, 2019 · 9 comments
Closed
Labels
easy Bugs or features that are easy to solve for a beginner. enhancement question

Comments

@matthid
Copy link

matthid commented Nov 1, 2019

In fsprojects/FAKE#2424 one of the problems was that the arguments are mixed and an error slipped through:
image

We could make it fail with a message that an empty list doesn't make sense here and ask if the arguments are potentially mixed up.

@haf
Copy link
Owner

haf commented Nov 1, 2019

We could warn with the expecto logger, but I'm not much for failing with exceptions for passing valid input into the expect function.

@haf haf added easy Bugs or features that are easy to solve for a beginner. enhancement question labels Nov 1, 2019
@matthid
Copy link
Author

matthid commented Nov 1, 2019

I know what you mean. My thinking is that when expected is an empty list the assert is basically a noop and the expected value should be static test data. So what is the scenario for this. I cannot think of a case where this is useful

@haf
Copy link
Owner

haf commented Nov 2, 2019

I can imagine testing a property of the co-domains of two functions, that for some input both return [], like: Expect.containsAll [] [] "equivalence"

@SteveGilham
Copy link

SteveGilham commented Nov 2, 2019

Given that this was an argument ordering problem at base -- and unit testing frameworks are divided over which of actual and expected comes first, rather than following a universal convention -- a better approach might be along the lines of offering an alternative set of APIs with a record like this as input

type Match<'a> =  // or some better name
  { 
      Actual : 'a
      Expected : 'a
  }

that feeds explicitly named values into the assertion.

@haf
Copy link
Owner

haf commented Apr 4, 2020

@SteveGilham Yes that might be a third option (we have both ordering variants, in open Expecto and open Expecto.Flip respectively); I think matchers generally could be a great way to encapsulate what has been asserted, but I would want more bang for the buck if I were to add that API, than your example API has.

I'm closing this since it's not that actionable for me. Ping me if you want to reopen, or even better, have a PR where you're fleshing out the API you would want (so we can discuss it)

@haf haf closed this as completed Apr 4, 2020
@matthid
Copy link
Author

matthid commented Apr 4, 2020

@haf given your example of both lists being empty: What about only throwing if expected is empty and actual is not (which was the case reported above)

@haf
Copy link
Owner

haf commented Apr 4, 2020

I'd be happy to have it warn in that case, as long as I can override the warning to silence it with the config. Alternatively you can introduce a configuration flag that changes the assertion logic, as long as that flag is opt-in.

I absolutely see where you're coming from, but the reason I don't agree to it is that it breaks the symmetry one expects from mathematics; that any set contains the empty set https://www.math.drexel.edu/~tolya/emptyset.pdf

@matthid
Copy link
Author

matthid commented Apr 4, 2020

but the reason I don't agree to it is that it breaks the symmetry one expects from mathematics; that any set contains the empty set

Yes, I know it is "wrong" mathematically, but I still cannot find any practical relevance for the situation I described above (IMHO the benefit is higher than the cost). Additionally, we are talking about a unit testing API here, not on a mathematical operation.

But stepping back a bit. The issue was only to show a potential pitfall and start the discussion around a potential solution. I'm pretty sure a warning wouldn't have helped us so we should leave it as-is. :)

@haf
Copy link
Owner

haf commented Apr 4, 2020

Yes, I know it is "wrong" mathematically, but I still cannot find any practical relevance for the situation I described above (IMHO the benefit is higher than the cost).

The thing is that I tend to encode mathematical properties like this with Expecto.FsCheck when I test my code, so it'll lead to breakages for me ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
easy Bugs or features that are easy to solve for a beginner. enhancement question
Projects
None yet
Development

No branches or pull requests

3 participants