This is the third and final fixture of a suite that make up the AllPairsExample. Like with AllFiles, we expand wildcard characters in path specifications to get lists of tests. And, like in AllCombinations, we enumerate cases drawing from these lists one test at a time in sequence. But here our goal is only to test all possible pairs of test, which will require fewer cases.
Here is the same specification we used to test the CalculatorExample in AllCombinations. Try it using AllPairs.
To meet the "all pairs" requirement we need at least n X m cases, where n and m are the sizes of the two largest categories. That means with only two categories all combinations and all pairs are the same. The marvel of the all pairs algorithm is that it squeezes draws from additional categories into these same cases and possibly a few more.
The algorithm is largely JamesBach's from the source cited on the AllPairsExample page. My implementation can be summarized as follows.
The case currently being filled is called the slug. A pair will fit the slug only if the following hold.
- Fill test cases with tests drawn from a list of most wanted pairs.
- Fill one case at a time. Never reexamine a case once filled.
- Recirculate used pairs back to the list but as less wanted.
- Quit filling cases when all pairs have been used at least once.
The fixture uses these helper objects to represent the state of the algorithm.
- At least one item of a pair is of a category that is not already filled.
- The other item must match the slug in its category or must also be unfilled.
See the source.
See AllPairsAlgorithm for some tests we've written for this algorithm itself.
- Item -- A value from within a category.
- Pair -- Two Items drawn from different categories.
- Var -- A category, one per list of files.
This list of related resources is from the AustinWorkshopOnTestAutomation.