So every once in a while I stumble upon an instance of this problem:
- I have a list of entities of type A
- I want to filter out some of the entities, with a predicate P returning a boolean for each A-instance a in the list
I try to test the predicate by building some ”positives” and some ”negatives”. But often I get the nagging feeling either the positives or the negatives form such a huge space of possibilities, that it becomes a pain to create instances of even a small subset of the variations.
For example, if I have some base-type/interface Base and the elements of the list are subtypes of this type, S1, S2, …, SN and the filter is supposed to let through only elements of type S1 and S2 but not Sk, k>=3. Also instances of S1 and S2 have to have some certain properties fullfilling some criteria to pass. You can imagine the combinatorial explosion of instances I have to try out in the test code, even to test a subset of all possibilities.
Add to that that some of the Si subtypes have 2 or 3 constructor parameters, and we’re in the jungle.
My current approach is
”test one to three positives, and one to three negatives. Ignore the nagging feeling”.
How do you approach this example?