Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/MandMCounter.Tests/Controllers/PeanutMandMControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class PeanutMandMControllerTests
#region "Testing units"

[TestMethod]
public void ControllerCountPeanutMandMsInAUSCupTest()
public void ControllerCountPeanutMandMsInAmericanCupTest()
{
//Arrange
string unit = "Cup";
Expand All @@ -22,15 +22,15 @@ public void ControllerCountPeanutMandMsInAUSCupTest()
float result = controller.GetDataForUnit(unit, quantity);

//Assert
Assert.IsTrue(System.Math.Round(result, 0) == 181f);
Assert.AreEqual(181f, System.Math.Round(result, 0));
}

#endregion

#region " Testing volume in a rectangle"

[TestMethod]
public void ControllerCountPeanutMandMsInA1CubicCMTest()
public void ControllerCountPeanutMandMsInA1000CubicCMTest()
{
//Arrange
string unit = "cm";
Expand All @@ -43,7 +43,7 @@ public void ControllerCountPeanutMandMsInA1CubicCMTest()
float result = controller.GetDataForRectangle(unit, height, width, length);

//Assert
Assert.IsTrue((int)System.Math.Round(result, 0) == (int)764f);
Assert.AreEqual(764, (int)System.Math.Round(result, 0));
}

#endregion
Expand All @@ -63,7 +63,7 @@ public void ControllerCountPeanutMandMsInACylinderWithCMTest()
float result = controller.GetDataForCylinder(unit, height, radius);

//Assert
Assert.IsTrue(System.Math.Round(result, 0) == 600f);
Assert.AreEqual(600f, System.Math.Round(result, 0));
}

#endregion
Expand Down
32 changes: 23 additions & 9 deletions src/MandMCounter.Tests/Controllers/SkittleControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ namespace MandMCounter.Tests.Controllers
[TestClass]
public class SkittleControllerTests
{
private SkittleCounterController _controller;

[TestInitialize]
public void Setup()
{
_controller = new SkittleCounterController();
}

#region "Testing units"

[TestMethod]
Expand All @@ -16,13 +24,15 @@ public void ControllerCountSkittlesInAUSCupTest()
//Arrange
string unit = "Cup";
float quantity = 1f;
const float expectedSkittles = 212f;
const float tolerance = 0.0001f;

//Act
SkittleCounterController controller = new SkittleCounterController();
float result = controller.GetDataForUnit(unit, quantity);
//SkittleCounterController controller = new SkittleCounterController();
float result = _controller.GetDataForUnit(unit, quantity);

//Assert
Assert.IsTrue(System.Math.Abs(System.Math.Round(result, 0) - 212f) < 0.0001f);
Assert.AreEqual(expectedSkittles, System.Math.Round(result, 0), tolerance);
}

#endregion
Expand All @@ -39,11 +49,13 @@ public void ControllerCountSkittlesInA1CubicCMTest()
float length = 10;

//Act
SkittleCounterController controller = new SkittleCounterController();
float result = controller.GetDataForRectangle(unit, height, width, length);
//SkittleCounterController controller = new SkittleCounterController();
float result = _controller.GetDataForRectangle(unit, height, width, length);

//Assert
Assert.IsTrue(System.Math.Abs(System.Math.Round(result, 0) - 896f) < 0.0001f);
const float expected = 896f;
const float delta = 0.0001f;
Assert.AreEqual(expected, System.Math.Round(result, 0), delta);
}

#endregion
Expand All @@ -59,11 +71,13 @@ public void ControllerCountSkittlesInACylinderWithCMTest()
float radius = 5;

//Act
SkittleCounterController controller = new SkittleCounterController();
float result = controller.GetDataForCylinder(unit, height, radius);
//SkittleCounterController controller = new SkittleCounterController();
float result = _controller.GetDataForCylinder(unit, height, radius);

//Assert
Assert.IsTrue(System.Math.Abs(System.Math.Round(result, 0) - 704f) < 0.0001f);
const float expected = 704f;
const float delta = 0.0001f;
Assert.AreEqual(expected, System.Math.Round(result, 0), delta);
}

#endregion
Expand Down
22 changes: 7 additions & 15 deletions src/MandMCounter.Tests/MandMTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void CountMandMsInAUSTableSpoonTest()
{
//Arrange
string unit = "Tablespoon";
float quantity = 1;
float quantity = 1f;

//Act
float result = Calculator.CountMandMs(unit, quantity);
Expand All @@ -115,7 +115,7 @@ public void CountMandMsInAUSTeaSpoonTest()
{
//Arrange
string unit = "Teaspoon";
float quantity = 1;
float quantity = 1f;

//Act
float result = Calculator.CountMandMs(unit, quantity);
Expand All @@ -127,20 +127,12 @@ public void CountMandMsInAUSTeaSpoonTest()
[TestMethod]
public void CountMandMsInANullUnitTest()
{
try
{
//Arrange
string unit = null;
float quantity = 1;
//Arrange
string unit = null;
float quantity = 1f;

//Act
Calculator.CountMandMs(unit, quantity);
}
catch (Exception ex)
{
//Assert
Assert.IsTrue(ex != null);
}
//Act & Assert
Assert.Throws<Exception>(() => Calculator.CountMandMs(unit, quantity));
}

[TestMethod]
Expand Down
71 changes: 25 additions & 46 deletions src/MandMCounter.Tests/PeanutMandMTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
float result = Calculator.CountPeanutMandMs(unit, quantity);

//Assert
Assert.IsTrue(System.Math.Round(result, 0) == 45f);

Check warning on line 71 in src/MandMCounter.Tests/PeanutMandMTests.cs

View workflow job for this annotation

GitHub Actions / Build .NET

Use 'Assert.AreEqual' instead of 'Assert.IsTrue' (https://learn.microsoft.com/dotnet/core/testing/mstest-analyzers/mstest0037)

Check warning on line 71 in src/MandMCounter.Tests/PeanutMandMTests.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Use 'Assert.AreEqual' instead of 'Assert.IsTrue' (https://learn.microsoft.com/dotnet/core/testing/mstest-analyzers/mstest0037)
}

[TestMethod]
Expand All @@ -83,7 +83,7 @@
float result = Calculator.CountPeanutMandMs(unit, quantity);

//Assert
Assert.IsTrue(System.Math.Round(result, 0) == 11f);

Check warning on line 86 in src/MandMCounter.Tests/PeanutMandMTests.cs

View workflow job for this annotation

GitHub Actions / Build .NET

Use 'Assert.AreEqual' instead of 'Assert.IsTrue' (https://learn.microsoft.com/dotnet/core/testing/mstest-analyzers/mstest0037)
}

[TestMethod]
Expand All @@ -98,27 +98,18 @@
float result = Calculator.CountPeanutMandMs(unit, quantity);

//Assert
Assert.IsTrue(System.Math.Round(result, 0) == 4f);

Check warning on line 101 in src/MandMCounter.Tests/PeanutMandMTests.cs

View workflow job for this annotation

GitHub Actions / Build .NET

Use 'Assert.AreEqual' instead of 'Assert.IsTrue' (https://learn.microsoft.com/dotnet/core/testing/mstest-analyzers/mstest0037)

Check warning on line 101 in src/MandMCounter.Tests/PeanutMandMTests.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Use 'Assert.AreEqual' instead of 'Assert.IsTrue' (https://learn.microsoft.com/dotnet/core/testing/mstest-analyzers/mstest0037)
}

[TestMethod]
public void CountPeanutMandMsInANullUnitTest()
{
try
{
//Arrange
string unit = null;
float quantity = 1;

//Act

Calculator.CountPeanutMandMs(unit, quantity);
}
catch (Exception ex)
{
//Assert
Assert.IsTrue(ex != null);
}
//Arrange
string unit = null;
float quantity = 1;

//Act & Assert
Assert.Throws<Exception>(() => Calculator.CountPeanutMandMs(unit, quantity));
}

[TestMethod]
Expand Down Expand Up @@ -178,23 +169,17 @@
[TestMethod]
public void CountPeanutMandMsInA1CubicNullUnitTest()
{
try
{
//Arrange
string unit = null;
float height = 1;
float width = 1;
float length = 1;

//Act

float result = Calculator.CountPeanutMandMs(unit, height, width, length);
}
catch (Exception ex)
//Arrange
string unit = null;
float height = 1;
float width = 1;
float length = 1;

//Act & Assert
Assert.Throws<Exception>(() =>
{
//Assert
Assert.IsTrue(ex != null);
}
Calculator.CountPeanutMandMs(unit, height, width, length);
});
}

#endregion
Expand Down Expand Up @@ -236,22 +221,16 @@
[TestMethod]
public void CountPeanutMandMsInACylinderWithNullUnitTest()
{
try
{
//Arrange
string unit = null;
float height = 10;
float radius = 5;

//Act

float result = Calculator.CountPeanutMandMs(unit, height, radius);
}
catch (Exception ex)
//Arrange
string unit = null;
float height = 10;
float radius = 5;

//Act & Assert
Assert.Throws<Exception>(() =>
{
//Assert
Assert.IsTrue(ex != null);
}
Calculator.CountPeanutMandMs(unit, height, radius);
});
}

#endregion
Expand Down
65 changes: 17 additions & 48 deletions src/MandMCounter.Tests/SkittleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
float result = Calculator.CountSkittles(unit, quantity);

//Assert
Assert.IsTrue(System.Math.Round(result, 0) == 3393f);

Check warning on line 25 in src/MandMCounter.Tests/SkittleTests.cs

View workflow job for this annotation

GitHub Actions / Build .NET

Use 'Assert.AreEqual' instead of 'Assert.IsTrue' (https://learn.microsoft.com/dotnet/core/testing/mstest-analyzers/mstest0037)

Check warning on line 25 in src/MandMCounter.Tests/SkittleTests.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Use 'Assert.AreEqual' instead of 'Assert.IsTrue' (https://learn.microsoft.com/dotnet/core/testing/mstest-analyzers/mstest0037)
}

[TestMethod]
Expand All @@ -37,7 +37,7 @@
float result = Calculator.CountSkittles(unit, quantity);

//Assert
Assert.IsTrue(System.Math.Round(result, 0) == 848f);

Check warning on line 40 in src/MandMCounter.Tests/SkittleTests.cs

View workflow job for this annotation

GitHub Actions / Build .NET

Use 'Assert.AreEqual' instead of 'Assert.IsTrue' (https://learn.microsoft.com/dotnet/core/testing/mstest-analyzers/mstest0037)

Check warning on line 40 in src/MandMCounter.Tests/SkittleTests.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Use 'Assert.AreEqual' instead of 'Assert.IsTrue' (https://learn.microsoft.com/dotnet/core/testing/mstest-analyzers/mstest0037)
}

[TestMethod]
Expand All @@ -52,7 +52,7 @@
float result = Calculator.CountSkittles(unit, quantity);

//Assert
Assert.IsTrue(System.Math.Round(result, 0) == 212f);

Check warning on line 55 in src/MandMCounter.Tests/SkittleTests.cs

View workflow job for this annotation

GitHub Actions / Build .NET

Use 'Assert.AreEqual' instead of 'Assert.IsTrue' (https://learn.microsoft.com/dotnet/core/testing/mstest-analyzers/mstest0037)

Check warning on line 55 in src/MandMCounter.Tests/SkittleTests.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Use 'Assert.AreEqual' instead of 'Assert.IsTrue' (https://learn.microsoft.com/dotnet/core/testing/mstest-analyzers/mstest0037)
}


Expand All @@ -68,7 +68,7 @@
float result = Calculator.CountSkittles(unit, quantity);

//Assert
Assert.IsTrue(System.Math.Round(result, 0) == 53f);

Check warning on line 71 in src/MandMCounter.Tests/SkittleTests.cs

View workflow job for this annotation

GitHub Actions / Build .NET

Use 'Assert.AreEqual' instead of 'Assert.IsTrue' (https://learn.microsoft.com/dotnet/core/testing/mstest-analyzers/mstest0037)
}

[TestMethod]
Expand Down Expand Up @@ -104,21 +104,12 @@
[TestMethod]
public void CountSkittlesInANullUnitTest()
{
try
{
//Arrange
string unit = null;
float quantity = 1;

//Act

Calculator.CountSkittles(unit, quantity);
}
catch (Exception ex)
{
//Assert
Assert.IsTrue(ex != null);
}
//Arrange
string unit = null;
float quantity = 1;

//Act & Assert
Assert.Throws<Exception>(() => Calculator.CountSkittles(unit, quantity));
}

[TestMethod]
Expand Down Expand Up @@ -178,23 +169,12 @@
[TestMethod]
public void CountSkittlesInA1CubicNullUnitTest()
{
try
{
//Arrange
string unit = null;
float height = 1;
float width = 1;
float length = 1;

//Act

float result = Calculator.CountSkittles(unit, height, width, length);
}
catch (Exception ex)
{
//Assert
Assert.IsTrue(ex != null);
}
string unit = null;
float height = 1;
float width = 1;
float length = 1;

Assert.Throws<Exception>(() => Calculator.CountSkittles(unit, height, width, length));
}

#endregion
Expand Down Expand Up @@ -236,22 +216,11 @@
[TestMethod]
public void CountSkittlesInACylinderWithNullUnitTest()
{
try
{
//Arrange
string unit = null;
float height = 10;
float radius = 5;

//Act

float result = Calculator.CountSkittles(unit, height, radius);
}
catch (Exception ex)
{
//Assert
Assert.IsTrue(ex != null);
}
string unit = null;
float height = 10;
float radius = 5;

Assert.Throws<Exception>(() => Calculator.CountSkittles(unit, height, radius));
}

#endregion
Expand Down
Loading