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

Takes only the second value of a tuple #34

Closed
jmuukka opened this issue Feb 23, 2019 · 2 comments
Closed

Takes only the second value of a tuple #34

jmuukka opened this issue Feb 23, 2019 · 2 comments

Comments

@jmuukka
Copy link

jmuukka commented Feb 23, 2019

I have following case which did not work as I expected.

module CalculatorStepDefinition

open NUnit.Framework
open TickSpec

let [<Given>] ``I have two numbers`` () =
    3, 5

let [<When>] ``They are added together`` numbers =
    Calculator.add (fst numbers) (snd numbers)

let [<Then>] ``the result is calculated correctly`` (result:int) =
    Assert.AreEqual(3 + 5, result)

module Calculator

let add a b = a + b

The result is 10 and when I debugged I really see that numbers tuple contains 5 and 5.

Expected behavior is to take the tuple and pass it on as tuple with correct values.

@michalkovy
Copy link
Contributor

It is behavior by design. If you return a tuple then it reads it as you returned multiple values and it tries to saves them all (it is needed for more complex examples)

The second number replaces the first because the types are the same (int).

The tuple isn't saved as whole. However, when you ask for a tuple of two ints it is able to construct it because you have an int in the dependency container - so it constructs tuple of two 5.

You can use e.g. record instead.

@michalkovy
Copy link
Contributor

Or, if you want to use tuple, you can "name" it by using a discriminated union:

module CalculatorStepDefinition

open NUnit.Framework
open TickSpec

type D = D of int*int

let [<Given>] ``I have two numbers`` () =
    D (3, 5)

let [<When>] ``They are added together`` (D (f, s)) =
    Calculator.add f s

let [<Then>] ``the result is calculated correctly`` (result:int) =
    Assert.AreEqual(3 + 5, result)

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

No branches or pull requests

3 participants