
Thanks: 0
Likes: 0
Dislikes: 0

Calculate Permutations
I'm not really sure what forum to put this one in but it's pretty much unit level stuff. Basically I'm wondering if anyone knows how to write a Java program that would do permutations for functional test cases or unit test cases if we have them labeled in a simple fashion, like A1, B1, C1. I'm not worried about which test cases are relevant with each other but rather the permutations. This is really only to be used for variable combinations, not just test cases. (I just thought I might be able to squeeze that in too!) But we've got a series of variables that I'm writing test cases on (mainly for unit testing I guess) and I want to see permutations of those but do this automatically. Am I making any sense?


Re: Calculate Permutations
Try James Bachs Allpairs program.

GUI automation is GUI automation. It is not testing.

Senior Member
Re: Calculate Permutations
I also like the Allpairs program that wooks mentions. However, it is written in Perl script and you specifically asked for Java. There are different ways you could get what you need. Here is one of the simplest that I can think of:
Note: The "LESSTHAN" references should, of course, be a < character. The reason I did not do that in the code was because some versions of UBB will not allow what it perceives to be an HTML opening tag within parentheses.
The idea is to replace testString="a b c d e f" with whatever you want. Notice that I did not really optimize this code for disregarding the spaces, which you should do if you want to use it for test cases. It still gives accurate results but in a cumbersome way. Also note that you can use this to find simple permutations of a word (or combinations of letters within a word). Also note that you should not do something like "A1 B1 C1 D1 E1 F1" with this because the letters and the numbers will each be treated as possible permuters. Again, you could change around the code if you wanted to.
When doing things like this rather than just relying on programs, we can also look at the algorithms so we understand why things work. So that means you could consider that the number of combinations of K objects chosen from a set of N objects is equal to N!/K!(NK)!, while the number of permutations is N!/(NK)! (I trust that the notion of factorials is understood.)

Posting Permissions
 You may not post new threads
 You may not post replies
 You may not post attachments
 You may not edit your posts

Forum Rules
