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 given three lengths that form a valid triangle, I would have specific cases, negative / small / large numbers, values close-to being overflowed, etc.; what is more, main aim is to generate combinations of these values, with or without repetition, in order to get a set of test data.


As a note: I actually know the answer to this, but it might be helpful for others, and a challenge for people here! --will post my answer later on.

  • Abacus github a combinatorics library for Node.JS, Python, PHP, Actionscript (ps i'm the author) – Nikos M. Mar 5 '15 at 23:04



/** [combination c n p x]
    int i,r,k = 0;
        do {
            k = k + r;
        } while(k < x);
        k = k - r;


  • What does choose() do? Does that basically return n-c[i] choose p-(i+1)1? – mkb Feb 28 '12 at 4:01
  • @mkb Of course. – nlucaroni Feb 28 '12 at 16:18
  • I'm sorry, I don't follow the choose behavior. It sounds like it's defined as self reflexive - choose does choose. Could you tell me what it does in simpler terms? – CuppM May 18 '15 at 18:55
  • 1
    "self-reflexive" is an incorrect term for this. It's called "recursive" and it's a fundamental part of computer science. The "choose" function in question is C(N,K), en.wikipedia.org/wiki/Binomial_coefficient . – nlucaroni May 19 '15 at 14:14
  • 2
    It should be noted, that x is 1 based, not 0 based as one would expect. – Andrew Savinykh Jun 7 '15 at 10:28


import itertools




You can also tweak something with combinations as well :

print list(itertools.combinations('123', 2))

And if order matters, there are permutations :

print list(itertools.permutations([1,2,3,4], 2))




Interesting question!



# xpermutations from http://code.activestate.com/recipes/190465
from xpermutations import *

    print c





Here's a sample of classes of input values

  • invalid triangles with at least one negative value
  • invalid triangles where the sum of two sides equals the third
  • input values that are non-numeric





Your Answer

