-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
using Xunit; | ||
using System; | ||
using TestLibrary; | ||
namespace UnitTestProject | ||
{ | ||
public class CalculatorTests | ||
{ | ||
private readonly MyCalculator _calculator; | ||
|
||
public CalculatorTests() | ||
{ | ||
_calculator = new MyCalculator(); | ||
} | ||
|
||
[Fact] | ||
public void Add_SimpleValues_ShouldReturnCorrectSum() | ||
{ | ||
// Arrange | ||
int a = 5; | ||
int b = 3; | ||
|
||
// Act | ||
int result = _calculator.Add(a, b); | ||
|
||
// Assert | ||
Assert.Equal(8, result); | ||
} | ||
|
||
[Fact] | ||
public void Subtract_SimpleValues_ShouldReturnCorrectDifference() | ||
{ | ||
// Arrange | ||
int a = 5; | ||
int b = 3; | ||
|
||
// Act | ||
int result = _calculator.Subtract(a, b); | ||
|
||
// Assert | ||
Assert.Equal(2, result); | ||
} | ||
|
||
[Fact] | ||
public void Multiply_SimpleValues_ShouldReturnCorrectProduct() | ||
{ | ||
// Arrange | ||
int a = 5; | ||
int b = 3; | ||
|
||
// Act | ||
int result = _calculator.Multiply(a, b); | ||
|
||
// Assert | ||
Assert.Equal(15, result); | ||
} | ||
|
||
[Fact] | ||
public void Divide_SimpleValues_ShouldReturnCorrectQuotient() | ||
{ | ||
// Arrange | ||
int a = 6; | ||
int b = 3; | ||
|
||
// Act | ||
double result = _calculator.Divide(a, b); | ||
|
||
// Assert | ||
Assert.Equal(2.0, result, 1); | ||
} | ||
|
||
[Fact] | ||
public void Divide_ByZero_ShouldThrowDivideByZeroException() | ||
{ | ||
// Arrange | ||
int a = 6; | ||
int b = 0; | ||
|
||
// Act & Assert | ||
Assert.Throws<DivideByZeroException>(() => _calculator.Divide(a, b)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters