combinational test case generator
Do u have any idea to list out all the combination of several set.
For example:
set A={a,b,c}
set B={e,f}
set C= {g,h,i}
All the combination would be:
aeg,aeh,aei,afg,afh,afi,beg,beh,bei,bfg,bfh,bfi,veg,ceh,cei,cfg,cfh,cfi
what is the algorithm to generate all the combination? Thank you very much.
I am using C programming.
Re: combinational test case generator
Something like:
Code:
for (int i = 0 ; i < #of-items-in-A ; ++i) {
for (int j = 0 ; j < #of-items-in-B ; ++j) {
for (int k = 0 ; k < #of-items-in-C ; ++k) {
printf("Combination: {%s,%s,%s}", A[i], B[j], C[k]);
}
}
}
should work, depending on what the sets are exactly.
Re: combinational test case generator
can i have a general algorithm so that the user is able to choose how many set?
Re: combinational test case generator
No, we aren't going to write your code for you. Do it yourself.
Re: combinational test case generator
The trick is to use recursion.
Say you have n arrays A of items, numbered 0 to n-1.
Now you write a function 'combinations(i)' that generates all combinations of the arrays i to n-1.
Clearly, if i == n, you are done, from zero sets you can pick exactly one combination.
Now if i < n, you iterate over all the elements in array A[i]. This gives you another part of the combination. Now call combinations(i+1) to get all combinations of the remaining arrays.
Finally combinations(0) gives all the combinations of all arrays.