As a job of a tester, one of my concerns is to always ensure complete test coverage. This can get hard since sometimes the number of possible combinations are really a lot. Lets take an example for instance. A good ol' example of making tea
To make tea you could use black tea, green tea or white tea. (3 variables)
You could use milk or water (2 variables)
you could use sugar or honey or none (3 variables)
You could have it iced or hot (2 variables)
As you can see, now if i want to test all the possible ways to make tea (assuming there is a hypothetical software which allows creation of a variety of teas), then i have to test: 3x2x3x2 combinations = 36, because there are indeed 36 unique ways to make tea
What algorithm is best in such a case. I can see a nested for loop being best. Am I right?
It can be a bit programming language-dependent... but you're basically looking for the cartesian product of the set of arguments.
for example, in Python
import itertools
for args in itertools.product(
['black tea','green tea','white tea'],
['milk','water'],
['sugar','honey','none'],
['iced','hot']
):
drink_tea(*args)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With