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

Allow empty subset arrays #14

Open
codekandis opened this issue Feb 10, 2020 · 1 comment
Open

Allow empty subset arrays #14

codekandis opened this issue Feb 10, 2020 · 1 comment

Comments

@codekandis
Copy link

codekandis commented Feb 10, 2020

I have several integration tests where I have to test an array is a subset of another array. These tests are implemented in a generic way for a specific case. The test is fed by data providers. The mentioned subset arrays can be empty in several data sets of the data provider.

Actually your library doesn't support empty subsets and throws an exception. So I could have an conditional assert on "if subset !== empty then assertArraySubset()". But I'd prefer the possibility to test for empty subsets while the subset should always be assumed as known if it's empty or whatever values it contains by the writer of the test. So an error on an empty subset restricts the testing abilities.

Edit

This discovery makes it more a bug report over a feature request.

If I test an empty subset array against an empty array no exception will be thrown which makes its behaviour inconsequent.

@rdohms
Copy link
Owner

rdohms commented Dec 1, 2020

Original code is not mine so i'm also getting familiar with it.

I agree inconsistency is bad, so let's outline some cases:

  • empty array subset
  • empty target array
  • both empty

Deep down these are interesting cases, as empty subset will always be contained in any target array, and an empty array will never contain any subset. Empty and Empty is a weird case where it can return true/false based on which side you are looking at.

It feels to me that throwing an exception for any of these cases is a good idea, as they all look unintentional. That does indeed mean that they are not resilient to empty arrays that may happen.

What if:

  • empty subset: always true
  • empty target: always false
  • both: throw exception

Does this seem reasonable? alternative being exceptions to all cases. (have not looked into code to verify validity)

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

No branches or pull requests

2 participants