C# Unit Testing in C# Test Driven Development TDD

Frantyk Andrii
Frantyk Andrii
35,423 Points

Unit testing C# => TDD Challenge Task 4 of 4 What I have to do on this?

I don't know about this!

Calculator.cs
using System;

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,9);
    } 

}

1 Answer

Steven Parker
Steven Parker
170,475 Points

It looks like you have a typo.

Although you have it in both files. Instead of "Subtract", you wrote "Substract" (with an extra "s").