Description
In our schema, we know that description
, expected
, and property
are fixed, but the inputs to each test case depend on the problem!
That means we can't know ahead of time what key(s) constitute the inputs; we have to examine the JSON in order to do so.
According to those test generators listed at exercism/discussions#155 the current solutions to this problem take on one of two forms:
- Look for any key that isn't
description
,expected
,property
, orcomments
. That key (or those keys) must be the input, by process of elimination. - Per-exercise configuration or code describing what keys hold the input for each exercise.
Well, what if we could do better?
Let's look at https://github.com/exercism/problem-specifications/blob/master/exercises/change/canonical-data.json where each case has two inputs: coins
and target
. Let's say that instead a case looks like:
{
"description": "single coin change",
"property": "findFewestCoins",
"input": {
"coins": [1, 5, 10, 25, 100],
"target": 25
},
"expected": [25]
}
As you can see, the key input
contains an object whose keys and values represent the inputs.
And what about https://github.com/exercism/problem-specifications/blob/master/exercises/leap/canonical-data.json where each case has only one input? One might consider two possible ways to do this:
The first way is actually how the JSON is already: The key input
contains a scalar, the one and only input.
{
"description": "year not divisible by 4: common year",
"property": "leapYear",
"input": 2015,
"expected": false
}
The second way we might consider is that it will also be an object, for consistency. So then:
{
"description": "year not divisible by 4: common year",
"property": "leapYear",
"input": {
"year": 2015
},
"expected": false
}
One could consider making that a one-liner: "input": {"year": 2015}
) if vertical space savings are desired.
This has the advantage of consistency, of course: input
always contains an object, but the file also becomes more verbose.
Were one of the two forms of this proposal to be implemented, would this benefit you and/or your track? Would it instead cause harm?
Alternative proposals to solve the problem of "we don't know the names of the keys that hold the input(s) ahead of time"?