Results 1 to 5 of 5

Thread: combinational test case generator

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2007
    Posts
    16

    Question 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.
    Last edited by jcmxwl; Aug 23rd, 2007 at 06:11 AM.

    Rekcah Team

  2. #2
    Fanatic Member twanvl's Avatar
    Join Date
    Dec 2001
    Posts
    771

    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.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jan 2007
    Posts
    16

    Re: combinational test case generator

    can i have a general algorithm so that the user is able to choose how many set?

    Rekcah Team

  4. #4
    Fanatic Member x-ice's Avatar
    Join Date
    Mar 2004
    Location
    UK
    Posts
    671

    Re: combinational test case generator

    No, we aren't going to write your code for you. Do it yourself.

  5. #5
    Fanatic Member twanvl's Avatar
    Join Date
    Dec 2001
    Posts
    771

    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.

Posting Permissions

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



Click Here to Expand Forum to Full Width