How to use combinations of sets as test data

前端 未结 5 1340
陌清茗
陌清茗 2020-12-05 13:45

I would like to test a function with a tuple from a set of fringe cases and normal values. For example, while testing a function which returns true whenever giv

5条回答
  •  [愿得一人]
    2020-12-05 14:39

    Absolutely, especially dealing with lots of these permutations/combinations I can definitely see that the first pass would be an issue.

    Interesting implementation in python, though I wrote a nice one in C and Ocaml based on "Algorithm 515" (see below). He wrote his in Fortran as it was common back then for all the "Algorithm XX" papers, well, that assembly or c. I had to re-write it and make some small improvements to work with arrays not ranges of numbers. This one does random access, I'm still working on getting some nice implementations of the ones mentioned in Knuth 4th volume fascicle 2. I'll an explanation of how this works to the reader. Though if someone is curious, I wouldn't object to writing something up.

    /** [combination c n p x]
     * get the [x]th lexicographically ordered set of [p] elements in [n]
     * output is in [c], and should be sizeof(int)*[p] */
    void combination(int* c,int n,int p, int x){
        int i,r,k = 0;
        for(i=0;i

    ~"Algorithm 515: Generation of a Vector from the Lexicographical Index"; Buckles, B. P., and Lybanon, M. ACM Transactions on Mathematical Software, Vol. 3, No. 2, June 1977.

提交回复
热议问题