# How can I get useful diff messeges when comparing tuples?

**URL:** https://discourse.julialang.org/t/how-can-i-get-useful-diff-messeges-when-comparing-tuples/57709
**Category:** New to Julia
**Tags:** testing
**Created:** [March 22, 2021, 1:03pm UTC](https://discourse.julialang.org/t/how-can-i-get-useful-diff-messeges-when-comparing-tuples/57709 "2021-03-22T13:03:18Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![justinsgray](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/justinsgray/32/23171_2.png) [@justinsgray](https://discourse.julialang.org/u/justinsgray)
#### Post date: [March 22, 2021, 1:03pm UTC](https://discourse.julialang.org/t/how-can-i-get-useful-diff-messeges-when-comparing-tuples/57709/1 "2021-03-22T13:03:18Z")

</div>

Im just spooling up with Julia, and Im having difficulty getting useful diff-msgs on some of the tests I am writing, when using ExtendedTestSet. The problem seems to be related to the type of vectors/tuples i am comparing. Sometimes I can get a diff, othertimes I get nothing!

I think the problem is that there is not a diff function defined for the types I am trying to compare, but I am unsure how to define one.

How can I make my own diff methods, and structure my own output for them?

Here is a simple example:

```julia
using Test
using TestSetExtensions

@testset ExtendedTestSet "unit test for inside_ranges" begin

    # not useful diff msg
    @test (2,3) == (3,4)

    # sort of useful diff msg
    @test [2,3] == [3,4]
    
end

```

gives:

```julia
=====================================================

unit test for inside_ranges: **Test Failed**

Expression: (2, 3) == (3, 4)

Diff:

nothing
=====================================================

=====================================================
unit test for inside_ranges: **Test Failed**

Expression: [2, 3] == [3, 4]

Diff:

[2, 3, 4]
=====================================================

```

---

<div class="post-metadata">

### Author: ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)
#### Post date: [March 22, 2021, 1:13pm UTC](https://discourse.julialang.org/t/how-can-i-get-useful-diff-messeges-when-comparing-tuples/57709/2 "2021-03-22T13:13:14Z")

</div>

If you broadcast the comparison, i. e. `(2,3) .== (3,4)` you get:

```julia
  Expression evaluated to non-Boolean
  Expression: (2, 3) .== (3, 4)
       Value: (false, false)

```

Or you can get the same error message you get with arrays converting the tuples into arrays:

```julia
@test [(2,3)...] == [(3,4)...]

```

---

<div class="post-metadata">

### Author: ![justinsgray](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/justinsgray/32/23171_2.png) [@justinsgray](https://discourse.julialang.org/u/justinsgray)
#### Post date: [March 22, 2021, 1:18pm UTC](https://discourse.julialang.org/t/how-can-i-get-useful-diff-messeges-when-comparing-tuples/57709/3 "2021-03-22T13:18:43Z")

</div>

Thanks. Thats helpful. I’d still like to code my own diff though. Is it possible to do that?

---

<div class="post-metadata">

### Author: ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)
#### Post date: [March 22, 2021, 1:34pm UTC](https://discourse.julialang.org/t/how-can-i-get-useful-diff-messeges-when-comparing-tuples/57709/4 "2021-03-22T13:34:58Z")

</div>

Probably you can, you should check how to do that in the documentation of `TestSetExtensions`. What you certainly can is define your own function to compare tuples, like, for instance:

```julia
julia> function diff_tuple(x,y)
          diff = Tuple[]
          for i in eachindex(x)
            if x[i] != y[i]
              push!(diff,((i,x[i]=>y[i])))
            end
          end
          if length(diff) == 0
            return true
          end
          return diff
       end
diff_tuple (generic function with 1 method)

julia> @test diff_tuple((2,3),(2,3))
Test Passed

julia> @test diff_tuple((2,3),(3,4))
Error During Test at REPL[65]:1
  Expression evaluated to non-Boolean
  Expression: diff_tuple((2, 3), (3, 4))
       Value: Tuple[(1, 2 => 3), (2, 3 => 4)]

```

The error message here indicates which elements changed, at which position, and from what to what.

Edit: It didn’t seem to me that the package was written to be really extendable. An inner change was needed. I have added a pull request here in which the tuples are expanded into vectors and the error message is printed as such:

> **[Comparing ssfrr:master...lmiq:patch-1 · ssfrr/TestSetExtensions.jl](https://github.com/ssfrr/TestSetExtensions.jl/compare/master...lmiq:patch-1)**
>
> Extensions to Julia's Base.Test. Contribute to ssfrr/TestSetExtensions.jl development by creating an account on GitHub.

Not very elegant, but better than printing `nothing`.
