6
\$\begingroup\$

I write a question. To make it easier for the answerers to test their answers, it is obvious that I should provide at least one test case and the expected output -- otherwise it may be difficult for the answerers to know if their solution is correct or not. I usually only include one.

Is it considered best practice on PPCG to include two or more sample test cases?

\$\endgroup\$
8
\$\begingroup\$

The right number of test cases depends largely on your problem.

In most challenges, ideally, the set of test cases should together cover all relevant edge cases. If there are no edge cases (i.e. all inputs are to be processed identically), then one or two test cases will suffice. Otherwise, you should probably provide more.

Of course, if the challenge is more of a puzzle nature, then you might not want to give the game away by providing too many examples.

Likewise, for optimisation challenges you should provide a few examples to show what valid solutions look like, but you don't need to show what optimal solutions look like.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .