Lucid Array Differences?

Burdette Lamar - Oct 6 '18 - - Dev Community

As promised, I'm looking to add Array explication to gem minitest_lucid (documentation at GitHub).

So far, useful elucidations for Hash, Set, and Struct have been pretty straightforward, as will be the case for OpenStruct.

For Array, not so much.


Stipulated: None of this matters for small arrays, whose differences are easy to evaluate visually. More sophisticated comparisons matter only for larger arrays.

Yes, this is overkill -- until it isn't.

For a failed assertion:

  • How much information is enough?
  • More is better.
  • Too much is just about right.

I can think of some array treatments that might be useful, but the usefulness of each may depend greatly on the nature of the actual data:

  • Element-by-element comparison.
  • Diff-LCS comparison.
  • Missing elements: expected - actual.
  • Unexpected elements: actual - expected.
  • Common elements: actual & expected.
  • All elements: actual | expected.

I'll detail these first two.

Element-By-Element Comparison

In this comparison, actual[0] is compared to expected[0], actual[1] is compared to expected[1], ... actual[n] is compared to expected[n].

This comparison is ideal when:

  • The arrays are the same size.
  • Most of the elements are the same.

The comparison may still be useful when:

  • The arrays are of similar size.
  • Fewer of the elements are the same.

Diff-LCS Comparison

"Diff::LCS computes the difference between two Enumerable sequences using the McIlroy-Hunt longest common subsequence (LCS) algorithm."

The matching algorithm is good at finding sequences that match, even when they are not in the same position in the arrays.

This comparison is ideal when:

  • The arrays have multiple matching sequences.
  • The actual array has a few insertions.
  • The actual array has a few deletions.

The comparison may still be useful when:

  • The arrays have fewer matching sequences.
  • The actual array has more insertions.
  • The actual array has more deletions.

Elucidation Output Format

I began by putting the elucidation into the message of the failed assertion.

Because there may be more elucidation data rather than less, I'm experimenting with additional output in HTML, where color and links can help organize and clarify.

Finally, What Should minitest_lucid Do?

If minitest_lucid implements several of these strategies, should the default be to return the information for all? If not, what's the default? And should there be an option for the non-default?

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .