Giter VIP home page Giter VIP logo

Comments (7)

arthernan avatar arthernan commented on July 2, 2024 3

AssertEquality result (9.0, 27.0) will let users continue

from fsharpkoans.

bryanhunter avatar bryanhunter commented on July 2, 2024

Yes. In addition to equality problems there are output formatting problems with the responses from NUnit. In the lab meeting at NashDotNet several folks did this:

    [<Koan>]
    let TheTruthBehindMultipleReturnValues() =
        let squareAndCube x =
            (x ** 2.0, x ** 3.0)

        let result = squareAndCube 3.0

        AssertEquality result (9,27)

...and were confused by this response:

  Expected: <(9, 27)>
  But was:  <(9, 27)>

Several assumed this was some F# spookiness they would never understand. They were relieved when they learned it was a Koan/NUnit problem.

from fsharpkoans.

ChrisMarinos avatar ChrisMarinos commented on July 2, 2024

Yeah, I get some of the most questions about that koan. The test runner should be changed as this issue describes, but I haven't changed the koan itself because it leads to good discussion and learning when I guide groups through the koans.

from fsharpkoans.

Winsto avatar Winsto commented on July 2, 2024

Firstly thank you for the time and effort put into these koans; Phil Trelford suggested I look here when I asked about learning F#.

I ended up on this very page as I have hit this very snag with the assert on the tuple. For now I've just done the following to pass the test/koan, but try to keep with the spirit of that koan in understanding the tuple return type: -

    //AssertEquality result  (9, 27) Hmm can't seem to get this to work, but...

    AssertEquality 9 (fst result)
    AssertEquality 27 (snd result)

Hopefully this helps someone else hitting the same snag.

from fsharpkoans.

ChrisMarinos avatar ChrisMarinos commented on July 2, 2024

The problem has to do with the way AssertEquality defines the idea of being equal. More specifically, it has to do with NUnit's equality semantics, since that's what AssertEquality calls under the hood.

NUnit equality is different than F# equality. For example, 1 does not equal 1.0 in F# (because one is an int and one is a float). However, the NUnit comparer knows how to compare ints and floats, so it would say that they are equal and pass the koan. Unfortunately, NUnit does NOT know how to compare F# Tuples, so it reverts back to the tuple's idea of equality which says that a tuple of int_int does NOT equal a tuple of float_float. That's why your first example fails, but your correction passes.

The way to fix this in the koans would be to write a custom version of equality that gives the proper comparison semantics for every koan. That includes making sure things like sequence equality, tuple equality, and record type equality work in a way that makes sense for every koan. The nice part about the NUnit behavior is that it simplifies the early stages of learning, but it becomes confusing as things differ more and more from F# equality. In this case, it's especially confusing.

In short, it would require a little bit of effort to fix the AssertEquality function to have a consistent idea of equality across all F# types. The more difficult piece is revisiting every koan to make sure there's a good experience for everyone. If I get some time, I'll take a look at fixing it, but until then, I like to leave this as is because it brings up a good conversation about equality semantics.

from fsharpkoans.

Winsto avatar Winsto commented on July 2, 2024

Chris,

My apologies for the long delay in my reply; I have not signed into this account an a while. I haven't looked at FSharp in a while; it is purely out of interest/intellectual curiosity at the moment and I fit in dabbling with it when I can :0)

I can see the validity of your point about the discussion being raised; once I realised the problem was in the nunit side there was no real issue.

Thanks for your prompt reply though and once again thanks for the time and effort put into the koans in the first place. It is a good way to learn!

from fsharpkoans.

dsyme avatar dsyme commented on July 2, 2024

Fixed in #51

from fsharpkoans.

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.