assertthat icon indicating copy to clipboard operation
assertthat copied to clipboard

fix: long strings were claimed equal

Open johanna-herrmann opened this issue 2 years ago • 0 comments

What bug was fixed? When comparing strings, where the product of the string lengths exceed 10000, they are comapred as char arrays using the compareArraysLinearly function. This was leading to the strings beeing claimed equal, despite they aren't. Example: assert.that('A'.repeat(200)).is.equalTo('B'.repeat(200)); should break the test, cause the strings aren't equal, but they are claimed to be equal and the test keeps "green".

cause in lib/comparisons/forArrays/compareArrays.ts:53 there is a check if diff.cost is 0, but the segment costs weren't summed up, before, so they're always 0.

fix sum up the diff.cost (sum of all segment.cost values) before. (see lines 53 .. 55)

tested locally

  • ran npx roboter test
  • repruduced the change locally in node_modules/assertthat inside of my project and ran my tests again.
    • assert.that('A'.repeat(200)).is.equalTo('B'.repeat(200)); breaks the test, like expected
    • assert.that('A'.repeat(200)).is.equalTo('A'.repeat(200)); keeps test "green"

johanna-herrmann avatar Dec 02 '23 16:12 johanna-herrmann