Skip to content
This repository has been archived by the owner on Oct 9, 2019. It is now read-only.

No easy way to compare lists (or other datasets) in a manner other than exact equals #208

Open
JonathanFraser opened this issue Sep 7, 2017 · 4 comments

Comments

@JonathanFraser
Copy link

JonathanFraser commented Sep 7, 2017

As the title says, take for example the case where I would like to compare a List Float or similar case. There is no method to reduce: List Expectation -> Expectation or customListEquals: (a -> a -> Expectation) -> List a -> List a -> Expectation

@rtfeldman
Copy link
Member

@JonathanFraser can you show us some code (or pseudocode) of what you'd like to be able to do?

@JonathanFraser
Copy link
Author

Specifically I was implementing some numeric code (DFT), this type of transform operates in a matrix multiplication type fashion. Moreover, it uses complex numbers so I need a custom data type to capture the pair. The type signature of the function in question is:
dft: List Complex -> List Complex
There is a corresponding inverse (idft) with the same signature and I need to validate the property
dft x |> idft == x but in the floating point sense as opposed to the exact equals sense.

I would like to be able to compare the two lists with a custom operator, something like:
complexCompare: Complex -> Complex -> Expectation

(\x -> 
  dft x 
   |> idft
   |> customListCompare complexCompare x
)

or something similar that allows for the same properties testing but with a datastructure that won't obey exact equality.

@jwoudenberg
Copy link
Collaborator

jwoudenberg commented Sep 9, 2017

It sounds to me like you want a functions of the sort existing in this module: https://github.com/NoRedInk/elm-formatted-text/blob/master/tests/EqualCheck.elm

Granted, the functions there's not a EqualCheck a -> EqualCheck (List a) in there, but it would be easy to imagine it can be added.

I've also been in the position where I felt I needed to build a custom equality function to go along with a custom type I created, for writing tests around that type. I'm not a hundred percent sure yet the approach taken in the module linked above is the best, but it might be nice to experiment with it, perhaps build a library for specifically that purpose.

@pbiggar
Copy link

pbiggar commented Oct 23, 2017

I have this problem too. I have two lists and want to check that one is a subset of the other (with some slight domain-specific complexity as well). I have a predicate I can use to test the subset part, but I lack the ability to make an Expectation with the two inputs. Right now I'm doing:

  if (Util.containsOrdered expected ops)
  then Expect.pass
  else Expect.equal expected ops
       |> Expect.onFail "not equal: these should be containsOrdered"

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants