1
\$\begingroup\$

Working on my latest challenge, I realized that I don't know what is the optimal way of providing/formatting the test cases. So the question is, what is the best way for a challenger to provide test cases for a challenge?

Consider that

  • the formatting should be such that if people simply copy and paste the test-case-code-block, it needs minimal handling to be used and tested.
  • it should be easy to work with as many languages as possible.
  • the format should be easy for humans reading the actual post on PPCG.

How can the total ease be maximized? Should the test cases be

n=3 -> T=1
n=4 -> T=8
n=5 -> T=35
n=6 -> T=110
n=7 -> T=287
n=8 -> T=632
n=9 -> T=1302

with little arrows in between? Or should they be

n=3, T=1
n=4, T=8
n=5, T=35
n=6, T=110
n=7, T=287
n=8, T=632
n=9, T=1302

comma separated? Or should I remove all unnecessary characters and only provide a numeric array delimited by commas, tab, space, or something like this?

3,1
4,8
5,35
6,110
7,287
8,632
9,1302

Or something else entirely?

| |
\$\endgroup\$
  • 2
    \$\begingroup\$ Dunno what's optimal (I usually do something like 3 -> 1), but definitely drop the n= and the T= - just have something like n -> T or Input -> Output at the top of the test cases \$\endgroup\$ – Stephen Sep 10 '17 at 3:47
  • 2
    \$\begingroup\$ Depends on the type of input and output. Can I suggest narrowing the scope to ask only about questions which take input as an integer or a 1D list of integers and give output as an integer or 1D list of integers? \$\endgroup\$ – Peter Taylor Sep 10 '17 at 6:07
  • 1
    \$\begingroup\$ See this answer, I think it pretty much covers everything. \$\endgroup\$ – Mr. Xcoder Sep 10 '17 at 8:38
  • \$\begingroup\$ Possible duplicate of Things to avoid when writing challenges \$\endgroup\$ – Wheat Wizard Sep 11 '17 at 3:37
3
\$\begingroup\$

It pretty much depends on the challenge

Math-related challenges

For math-related challenges, with small amounts of text for both input and output (i.e. numbers), I usually delimit them with an ASCII arrow (->), and put a header at the top showing what values I am working with (like Input -> Output):

n -> T

3 -> 1
4 -> 8
5 -> 35
6 -> 110
7 -> 287

However, if the challenge involves negative numbers as well, I would substitute -> with =>, to avoid confusion.

String-related challenges with input (and output) of variable size

When I deal with strings (or numbers with variable number of digits), I use the same format but align the arrows and use wide spacing*. For example:

Input -> Output 

abc          -> 3
abcde        -> 5
ppcg         -> 4
codegolf.SE  -> 11

*In my opinion this is the best compromise between ease of use and human readability.

ASCII-Art challenges

When the output contains multiple lines, you can have the input and output separated by newlines. Some examples:

Input
Output


3
+---+
|   |
+---+

4
+----+
|    |
|    |
+----+

.....

As a reference, this answer is very on-topic in this case.

| |
\$\endgroup\$
  • \$\begingroup\$ +1 and accepted. Exactly what I was looking for. I didn't realize that this had already been specifically addressed in that reference. \$\endgroup\$ – Fixed Point Sep 10 '17 at 19:28

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