Coder Social home page Coder Social logo

Statically typed equality test about fsunit HOT 3 CLOSED

tpetricek avatar tpetricek commented on August 25, 2024
Statically typed equality test

from fsunit.

Comments (3)

fsoikin avatar fsoikin commented on August 25, 2024

+1 on this.

Here is a simple repro:

let someFn x = 
   match x with 
      | 42 -> []
      | _ -> [1;x]

[<Test>]
let ``someFn should return empty list when given 42``() =
   someFn 42
   |> should equal []

The test fails and error message cryptically states that Expected: [], was: []

from fsunit.

dtchepak avatar dtchepak commented on August 25, 2024

+1. It would be useful to support statically typed matchers in other cases too. I am currently trying the following (not tested yet, please point out errors):

let inline equalWithin t x =
    let isInRange y = y <= x+t && y>= x-t
    NHamcrest.CustomMatcher<_>(sprintf "%s with a tolerance of %s" (string x) (string t), fun v -> isInRange v)

let inline should' m expected actual = Xunit.Assert.That(actual, m expected)

This has the advantage of equalWithin working on any comparable type that supports -, + (including DateTime with TimeSpan tolerance). The current equalWithin only works with objects whose string representations parse as doubles.

from fsunit.

sergey-tihon avatar sergey-tihon commented on August 25, 2024

Released in v2.2.0-beta1

from fsunit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.