# Thread: permutations

1. ## permutations

My brain it crampeth. And I was a math major in school! So here is what I want to do. I have 4 data elements each of which that can be in two states, set and not set. So I have 8!, or 40,320 possible combinations. I am trying to find a working app or code I can use (VB, C# or maybe Java) to make a list of the 40,320 actual permutations.

I want to automate the testing of the permutations. Does anyone know of such an animal? I REALLY don't want to recreate that wheel if it already exists. Thanks

2. ## Re: permutations

Okay... so... here's the REAL question... Why would you need to test 40,320 permutations? While you can and I'm sure the tool exists, the question I have is... why? There are permutations that are more risky than others... there are data elements that are more critical than others... Do you need to test all the permutations or can you test all off, all on, and then test the most risky combinations... that should reduce your quantity of test cases...

3. ## Re: permutations

I'm not sure what exactly you need help with. You'll basically want write a data driven test that takes in the parameters. So for every w,x,y,z, it'll know how to set the parameter. Then you can use nested for loops to loop through all the combinations.

<font class="small">Code:</font><hr /><pre>

function getExpected(w, x, y, z) {
//code to pull expected results from a data table.
}

function doDataDrivenTest(w, x, y, z, expectedResult) {
//code to set values w, x, y, z
//code to verify expected result
}

settingA[] = {setting1, setting2}
settingB[] = {setting1, setting2}
settingC[] = {setting1, setting2}
settingD[] = {setting1, setting2}

for(w in settingA) {
for(x in settingB) {
for(y in settingC) {
for(z in settingD) {
doDataDrivenTest(w, x, y, z, getExpected(w,x,y,z));
}
}
}
}

</pre><hr />

4. ## Re: permutations

Where did you get 8! permutations from?

Surely it's 2^4 = 16.

A B C D
0 0 0 0
0 0 0 1
0 0 1 0
0 0 1 1
0 1 0 0
0 1 0 1
0 1 1 0
0 1 1 1
1 0 0 0
1 0 0 1
1 0 1 0
1 0 1 1
1 1 0 0
1 1 0 1
1 1 1 0
1 1 1 1

5. ## Re: permutations

Four data elements each with an ON and OFF setting make for 8 things.

Robert, I don't really need every permutation though there really is no higher or lower risk set of permutations. The motive for an algorithm is it seemed like a problem that had been solved already. I could get a nice set. I confess there was also curiosity piqued.

6. ## Re: permutations

[ QUOTE ]
Four data elements each with an ON and OFF setting make for 8 things.

[/ QUOTE ]
Hmm, assuming you set each of the four elements either off or on, then submit them all at the same time, I agree with Tom S's analysis - 4 items/things, 2 states each.

7. ## Re: permutations

when you say 8 factorial, does that mean the order in which things are set matters?

If so, the approach I mention won't work. You still will want to make it a data driven test out of good practice, and just test key data points as the 2nd poster mentioned.

The data driven test however will need to probably take in some sort of data structure like a set of a couple arrays, or an array of sets, and contain some switching logic.

testData1 = {{a,true},{b,false}, {c,false},{d,true}};
expectedResult = 345;

doDataDrivenTest(testData1, expectedResult)

function doDataDrivenTest(testData, expectedResult) {
for( item in testData) {
switch(item[0])
case 'a':
set a = item[1];
case 'b':
set b = item[1];
case 'c':
set c = item[1];
case 'd':
set d = item[1];
}

verifyResult(expectedResult);
}

8. ## Re: permutations

Even in the case where order matters there are only 16 possible combinations.

In this example, there are not 8 things; there are 4 things with 2 states.

Thus, the total number of commbinations in this case is 2*2*2*2 = 16.

When designing tests for multiple inputs with several values that affect a single common output condition or state the best approach is using combinatorial testing. See http://www.testingmentor.com/imtesty...torial+testing

9. ## Re: permutations

[ QUOTE ]
Even in the case where order matters there are only 16 possible combinations.

[/ QUOTE ]
Hmm, are you sure?

If we are talking about 4 checkboxes and 1 "submit" action, then the order you set these checkboxes usually doesn't matter.

But what if the 4 objects behave differently, such that the order DOES matter?

If "A" represents the first object ON, and "a" represents the first object OFF, and "B","b","C","c","D","d" represent the other objects and states, then

aBcd &lt;&gt; acdB

And thus, there would be more than 16 combinations.
Right?

10. ## Re: permutations

This is a silly argument for argument's sake. Say in a perverse world where order matters. So you can have 3 states for each item, on/off/notset. And if A was set before B, is different than B set before A..

Then you have 4! (24 combinations of ordering), multipled by 3, then subtract the overlapping combinations of not set.

Not quite the 40k combinations said, but still enough to justify data driving the test.

Page 1 of 2 12 Last

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

vBulletin Optimisation provided by vB Optimise v2.6.0 Beta 4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.0.9 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Questions / Answers Form provided by vBAnswers (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominatevBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 04:14 PM.

Copyright BetaSoft Inc.