I am filled with solutions

Weekly essays on testability, testing and being a tester.

Working with Permuations and Combinations

Something tests end up doing a lot of is working with permutations and combinations. For those of you who didn't have the benefit of a good statistics class in college (or some gambling experience after) doing the math can be a hassle. Generating all the possibilities can also be a bit of a puzzle (it's like counting in a mixed base number system sometimes).

I have found myself needing to generate lists of permutations (list1 x list2 x list3 in all combinations) and combinations (all the ways you can get dealt 5 cards from a 52 card deck) once in a while. While doing API testing I realized it would be handy to code up some generic generators that I could re-use anytime I wanted.

http://www.codeplex.com/permutationTools has the libraries I created for this purpose.

The math to calculate the number of permutations and combinations is built in. The logic to step through the lists and get a minimal set, or a full permutation list is encapsulate inside with an easy "foreach" handle.

Lately I have been using these to automatically generate thousands of test cases for methods I want to give a solid workout to. This kind of testing can be daunting to create by hand. Just a handful of parameters can put you into the thousands of test cases. You can create a central method that accepts various input and drive it at run time with the tools, or you can turn the process inside out and create a program to write tests.

I do the later because it fits into my test harness and reporting system better. If I run 10,000 tests and one permutation fails I want the report to say 99.99% pass. If you run all the permutations as one test you get 100% fail. That's not really an indication of the product quality.

You have to be careful not to write impenetrable test code when using techniques like this. Make sure your BVT and Basic acceptance test cases are hand written and clear before you generate 10,000 cases that rely on tricky logic.

 

Published Saturday, October 25, 2008 1:45 AM by SaintD

Comments

No Comments
Anonymous comments are disabled

About SaintD

Dustin Andrews has been testing software at Microsoft since 2001. He currently programs primary in C# and has loved it ever since he learned it had a good regex class. He came from the industry where he has been an ISP unix admin, Perl and SQL developer, dev lead, help desk technician and manager. He has also waited tables, worked many long nights as a convenience store clerk disinfected shoes in a bowling alley and done other jobs he has blocked out of his memory. He is currently in the Unlimited Potential Group as a Server Test Lead.

© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Microsoft
Page view tracker