9
\$\begingroup\$

What is the most recommended way to include large test cases in a question?

Small test cases can be included in the question, but large test cases might go over the character limit or take up a lot of space, making the question cluttered.

\$\endgroup\$
11
\$\begingroup\$

Questions should be self-contained whenever possible to guard against link rot. (Clicking away to other sites can also be annoying.)

A good way to keep the test cases from consuming too much vertical space is to put them all in a single code block, which will then have a max-height and a scrollbar.

However, when your test cases are so large that they exceed the character limit, you could use a Github Gist, which is unlikely to suddenly go down.

\$\endgroup\$
7
\$\begingroup\$

Elaborating on TanMath's last suggestion, it is sometimes possible to generate test data programmatically. If you know JavaScript you can write a Stack Snippet which does this, so that people don't even have to run the generating code locally or in an online interpreter, but right there on the challenge. If not, you could still provide a link to ideone or similar for the generator. But make sure that you also include the code itself in the challenge, so people can still generate test cases if the link ever goes down.

But before you do any of this, ask yourself whether you actually need huge test cases. Unless you want to enforce efficient algorithms by imposing a time limit on large inputs, it is almost always possible to cover all possible edge cases with a number of smaller test cases.

\$\endgroup\$
-3
\$\begingroup\$

Based on what I have seen, pastebin is the best option. However, some alternatives include having an HTML page with the data, or uploading onto Google drive (not a very common option, haven't seen this so far). It also can depend on the challenge. I remember seeing in one recent question that the poster had a webpage that generated and printed random testcases. So you could use a similar method.

\$\endgroup\$
  • \$\begingroup\$ Don't use Pastebin. You'll end up with a file with Windows-style newlines which will create all sorts of problems on other platforms. \$\endgroup\$ – Dennis Dec 26 '16 at 15:28

You must log in to answer this question.

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