Transpose exercise: empty string test case

The first test is written as:

{
      "uuid": "404b7262-c050-4df0-a2a2-0cb06cd6a821",
      "description": "empty string",
      "property": "transpose",
      "input": {
        "lines": []
      },
      "expected": []
    }

and the comments state:`

"comments": [
    "JSON doesn't allow for multi-line strings, so all multi-line input is ",
    "presented here as arrays of strings. It's up to the test generator to join the ",
    "lines together with line breaks."
  ]

So it’s the intention of the exercise to have as input a string, but uses array to represent multi-line strings. However, an array line [] does not seem to represent anything since it doesn’t contain any string. In other words, there’s nothing to join since there’s no input string at all. I left this test our during the test implementation.

Shouldn’t the test be written as

{
      "uuid": "404b7262-c050-4df0-a2a2-0cb06cd6a821",
      "description": "empty string",
      "property": "transpose",
      "input": {
        "lines": [""]
      },
      "expected": [""]
    }

"". join([]) and "". join([""]) ought to both produce the same results – and empty string. So long as the results are the same, does it really matter how we represent it?

1 Like

I’m not following. What are "". join([]) and "". join([""]) supposed to do? Join a string to an empty array and join a string to an array that has an empty string? I don’t have something like that in my implementation.

My point is that if i disregard the brackets which are purely representational, i’m left with no input to feed the function.

It’s supposed to join the line data, though the separator ought to be "\n" and not "".

Trying another language, string.Join(lines, "\n") returns the desired empty string for lines = [] and for lines = [""]. The tests should be combining the lines using a newline char to get the transpose() input. So long as the result of a join() operation returns an empty string, the data is correct.

Currently, I’ve assumed an empty string inside the array, so the tests are written as [""] instead of []. This approach ensures consistency in how the tests are structured. As long as the test remains the same, I’m fine with this adjustment.

Thanks!

Are you passing an array or a string to the function?

28 languages implement transpose. I checked the first 20 tracks that showed up in a GitHub search. Five use string inputs, and the rest use an array of strings.

1 Like

It’s an array of strings. My concern is that, since every test except the empty string case uses arrays containing strings, the empty string case should also explicitly show an array with an empty string. This aligns with the description of “empty string.” However, it seems that “empty string” is referring to the joined string instead. This might be clear when reading the comment in the canonical data, but in the implemented test, it feels a bit odd. Without an empty string inside the array, it seems like something was forgotten.

Yeah. It sounds like the implementations didn’t quite implement what was intended here. The canonical data comment makes it fairly clear that the intent is to call the function with a multi line string and not with a list.

If you’re calling the function with a list, you can read “empty string” as “empty input”. I don’t think you should need a non-empty input containing an empty string for this test.

I’m guessing that some implementations don’t conform to the canonical data because a multiline string is usually presented as a single line making it much harder to visualize the before and after of transposing. But when using arrays, we can simply stack the lines. Additionally, some tracks don’t use test generators, so it’s likely easier to copy-paste the array and directly apply a join function in the test suite.

Absolutely. The test code can contain a copy paste of the list then call a join function. This should result in calling transpose with a multi line string. This should handle the empty list just fine.