C# Unit Testing in C# Test Driven Development TDD

Jonas Gamburg
Jonas Gamburg
11,193 Points

Bummer! Assert.Equal() Failure, Expected: 0.9, Actual: 0.9 What am I doing wrong??

It says to implement the Subtractr method so that the test passes. It seems to pass just fine, but it it doesn't let me continue.

' ' 'c# Bummer! Assert.Equal() Failure, Expected: 0.9, Actual: 0.9

' ' ' c#

Calculator.cs
public class Calculator
{
    public double Result;

    public Calculator(double number)
    {
        Result = number;
    }     

    public void Add(double number)
    {
        Result += number;
    }

    public void Substract(double number)
    {
        Result -= number;
    }
}
CalculatorTests.cs
using Xunit;

public class CalculatorTests
{


    [Fact]
    public void Initialization()
    {
        var expected = 1.1;
        var target = new Calculator(1.1);
        Assert.Equal(expected, target.Result, 1);
    }

    [Fact]
    public void BasicAdd()
    {
        var target = new Calculator(1.1);
        target.Add(2.2);
        var expected = 3.3;
        Assert.Equal(expected, target.Result, 1);
    }

    [Fact]
    public void BasicSubtract()
    {
        var target = new Calculator(1.1);
        target.Substract(0.2);
        var expected = 0.9;
        Assert.Equal(expected, target.Result);
    }
}

1 Answer

Jennifer Nordell
STAFF
Jennifer Nordell
Treehouse Staff

Hi there! You're really close, but you have 2 typos and a missing argument. Twice you've misspelled "Subtract" as "Substract". Note the extraneous "s" in your version. Those are found in these lines:

// This one
 public void Substract(double number)

// And this one
target.Substract(0.2);

Also, you need to pass in the integer 1 at the end of your assertion here:

 Assert.Equal(expected, target.Result, 1);

Hope this helps! :sparkles:

edited to change the word "parameter" to "argument" to be semantically correct

Jonas Gamburg
Jonas Gamburg
11,193 Points

Thank you very much, it made all the difference! :D