Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make assert-same-values show what's different #48

Open
dmcassel opened this issue Dec 5, 2018 · 5 comments
Open

Make assert-same-values show what's different #48

dmcassel opened this issue Dec 5, 2018 · 5 comments
Labels
enhancement New feature or request

Comments

@dmcassel
Copy link
Collaborator

dmcassel commented Dec 5, 2018

The assert-same-values function tells you when the expected doesn't match the actual and shows both sequences. It would be much more helpful if it showed what was different between them.

@dmcassel dmcassel added the enhancement New feature or request label Dec 5, 2018
rhdunn added a commit to rhdunn/marklogic-unit-test that referenced this issue Jan 8, 2019
This adds an assert-throws-message function that tests the
error:message of an error that works in the same way as
assert-throws-message.

This is useful for testing the message that gets reported by
an assert helper function for when that function provides
additional information.
rhdunn added a commit to rhdunn/marklogic-unit-test that referenced this issue Jan 8, 2019
This creates a new assert-equal-message function to provide
a custom error message to the "Assert Equal failed" message
reported by assert-equal.
rhdunn added a commit to rhdunn/marklogic-unit-test that referenced this issue Jan 8, 2019
This provides a way of comparing two ordered sequences that
reports details of how the sequences differ, allowing the
user to locate the cause of the failure.
rhdunn added a commit to rhdunn/marklogic-unit-test that referenced this issue Jan 8, 2019
This changes assert-same-values to use the new assert-equal-seq
function to report the specific item that differs, or item count
if the sequences are of different sizes and all items upto the
count difference are equal.
@rjrudin
Copy link
Contributor

rjrudin commented Aug 9, 2023

May do this in 1.4.0 if there's an easy way to do something useful. Otherwise will close.

@rjrudin rjrudin added this to the 1.4.0 milestone Aug 9, 2023
@jamesagardner
Copy link
Contributor

jamesagardner commented Aug 9, 2023 via email

@dmcassel
Copy link
Collaborator Author

dmcassel commented Aug 9, 2023

I can offer a first pass but don't have time for extensive testing right now:

xquery version "1.0-ml";

(:
 : $seq1 and $seq2 are assumed to be in order, as done https://github.com/marklogic-community/marklogic-unit-test/blob/master/marklogic-unit-test-modules/src/main/ml-modules/root/test/test-helper.xqy#L523-L530. 
:)
declare function local:find-diffs($seq1, $seq2, $diffs) {
  if (fn:empty($seq1) and fn:empty($seq2)) then
    $diffs
  else if (fn:empty($seq1)) then (
    $diffs => map:with("only-in-2", ($diffs => map:get("only-in-2"), $seq2))
  )
  else if (fn:empty($seq2)) then (
    $diffs => map:with("only-in-1", ($diffs => map:get("only-in-1"), $seq1))
  )
  else if (fn:deep-equal(fn:head($seq1), fn:head($seq2))) then
    local:find-diffs(fn:tail($seq1), fn:tail($seq2), $diffs)
  else if (fn:head($seq1) lt fn:head($seq2)) then
    local:find-diffs(fn:tail($seq1), $seq2, $diffs => map:with("only-in-1", ($diffs => map:get("only-in-1"), fn:head($seq1))))
  else
    local:find-diffs($seq1, fn:tail($seq2), $diffs => map:with("only-in-2", ($diffs => map:get("only-in-2"), fn:head($seq2))))
};

let $seq1 := ('a', 'b', 'd')
let $seq2 := ('b', 'c', 'e')
return 
  local:find-diffs($seq1, $seq2, map:map())

This returns

<map:map xmlns:map="http://marklogic.com/xdmp/map" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <map:entry key="only-in-2">
    <map:value xsi:type="xs:string">c</map:value>
    <map:value xsi:type="xs:string">e</map:value>
  </map:entry>
  <map:entry key="only-in-1">
    <map:value xsi:type="xs:string">a</map:value>
    <map:value xsi:type="xs:string">d</map:value>
  </map:entry>
</map:map>

@rjrudin
Copy link
Contributor

rjrudin commented Aug 11, 2023

DEVEXP-555

@rjrudin rjrudin removed this from the 1.4.0 milestone Sep 8, 2023
@rjrudin
Copy link
Contributor

rjrudin commented Sep 8, 2023

Holding off on this as we'd like to try implementing assert-same-values with a real quality check first instead of having to sort.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants