-
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.
Finished unit testing, updated icon.
- Loading branch information
1 parent
a6937d6
commit f08e6a3
Showing
8 changed files
with
114 additions
and
57 deletions.
There are no files selected for viewing
73 changes: 72 additions & 1 deletion
73
PostScriptumMortarCalculator.Tests/Extensions/NumericExtensionsTests.cs
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 |
---|---|---|
@@ -1,10 +1,81 @@ | ||
using System.Collections.Generic; | ||
using NUnit.Framework; | ||
using PostScriptumMortarCalculator.Extensions; | ||
using PostScriptumMortarCalculator.Models; | ||
using PostScriptumMortarCalculator.Utils; | ||
|
||
namespace PostScriptumMortarCalculator.Tests.Extensions | ||
{ | ||
[TestFixture] | ||
public class NumericExtensionsTests | ||
{ | ||
// TODO: Test numeric extensions. | ||
// TODO: More test cases. | ||
private const double c_PRECISION = 0.01d; | ||
|
||
[TestCase(10, 10, 2, 5, 5)] | ||
[TestCase(100, 50, 5, 20, 10)] | ||
public void RoundedVector2ToMetersScale_PassedValues_ReturnsCorrectResult(double vX, double vY, | ||
double pixelsPerMeter, double vShouldBeX, double vShouldBeY) | ||
{ | ||
var v = new RoundedVector2(vX, vY); | ||
var vShouldBe = new RoundedVector2(vShouldBeX, vShouldBeY); | ||
var scaledV = v.ToMetersScale(pixelsPerMeter); | ||
Assert.That(scaledV.X, Is.EqualTo(vShouldBe.X).Within(c_PRECISION)); | ||
Assert.That(scaledV.Y, Is.EqualTo(vShouldBe.Y).Within(c_PRECISION)); | ||
} | ||
|
||
[TestCase(10, 10, 2, 20, 20)] | ||
[TestCase(100, 50, 5, 500, 250)] | ||
public void RoundedVector2ToPixelScale_PassedValues_ReturnsCorrectResult(double vX, double vY, | ||
double pixelsPerMeter, double vShouldBeX, double vShouldBeY) | ||
{ | ||
var v = new RoundedVector2(vX, vY); | ||
var vShouldBe = new RoundedVector2(vShouldBeX, vShouldBeY); | ||
var scaledV = v.ToPixelScale(pixelsPerMeter); | ||
Assert.That(scaledV.X, Is.EqualTo(vShouldBe.X).Within(c_PRECISION)); | ||
Assert.That(scaledV.Y, Is.EqualTo(vShouldBe.Y).Within(c_PRECISION)); | ||
} | ||
|
||
[TestCase(0, 1000, 500, 0.5)] | ||
public void PercentageBetweenMinAndMaxDistance_PassedValues_ReturnsCorrectResult(double minRange, | ||
double maxRange, double distanceBetween, double shouldBePercentage) | ||
{ | ||
var mortarData = new MortarDataModel(string.Empty, RoundedVector2.Zero, RoundedVector2.Zero, | ||
new List<MortarDataModel.MortarRangeValue> | ||
{ | ||
new MortarDataModel.MortarRangeValue(minRange, minRange), | ||
new MortarDataModel.MortarRangeValue(maxRange, maxRange) | ||
}); | ||
var percentageBetween = mortarData.PercentageBetweenMinAndMaxDistance(distanceBetween); | ||
Assert.That(percentageBetween, Is.EqualTo(shouldBePercentage).Within(c_PRECISION)); | ||
} | ||
|
||
[TestCase(0, 1000, 1001)] | ||
public void PercentageBetweenMinAndMaxDistance_PassedIncorrectValues_ReturnsLessThanZero(double minRange, | ||
double maxRange, double distanceBetween) | ||
{ | ||
var mortarData = new MortarDataModel(string.Empty, RoundedVector2.Zero, RoundedVector2.Zero, | ||
new List<MortarDataModel.MortarRangeValue> | ||
{ | ||
new MortarDataModel.MortarRangeValue(minRange, minRange), | ||
new MortarDataModel.MortarRangeValue(maxRange, maxRange) | ||
}); | ||
var percentageBetween = mortarData.PercentageBetweenMinAndMaxDistance(distanceBetween); | ||
Assert.That(percentageBetween, Is.LessThan(0)); | ||
} | ||
|
||
[TestCase(0,100,50,0.5)] | ||
public void PercentageBetween_PassedValues_ReturnsCorrectResult(double min, double max, double value, | ||
double shouldBePercentage) | ||
{ | ||
Assert.That(value.PercentageBetween(min,max), Is.EqualTo(shouldBePercentage).Within(c_PRECISION)); | ||
} | ||
|
||
[TestCase(0,100,0.5,50)] | ||
public void LerpBetween_PassedValues_ReturnsCorrectResult(double min, double max, double percentage, | ||
double shouldBeValue) | ||
{ | ||
Assert.That(percentage.LerpBetween(min,max), Is.EqualTo(shouldBeValue).Within(c_PRECISION)); | ||
} | ||
} | ||
} |
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
35 changes: 34 additions & 1 deletion
35
PostScriptumMortarCalculator.Tests/Services/DataResourceServiceTest.cs
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 |
---|---|---|
@@ -1,10 +1,43 @@ | ||
using NUnit.Framework; | ||
using PostScriptumMortarCalculator.Services; | ||
|
||
namespace PostScriptumMortarCalculator.Tests.Services | ||
{ | ||
[TestFixture] | ||
public class DataResourceServiceTest | ||
{ | ||
// TODO: Test data service. | ||
[Test] | ||
public void Maps_GetData_ReturnsNonEmptyCollection() | ||
{ | ||
var service = new DataResourceService(); | ||
var mapData = service.GetMapData(); | ||
Assert.That(mapData, Is.Not.Null.Or.Empty); | ||
} | ||
|
||
[Test] | ||
public void Mortars_GetData_ReturnsNonEmptyCollection() | ||
{ | ||
var service = new DataResourceService(); | ||
var mortarData = service.GetMortarData(); | ||
Assert.That(mortarData, Is.Not.Null.Or.Empty); | ||
} | ||
|
||
[Test] | ||
public void Credits_GetData_ReturnsNonEmptyCollections() | ||
{ | ||
var service = new DataResourceService(); | ||
var creditsData = service.GetCreditsData(); | ||
Assert.That(creditsData.Contributors, Is.Not.Null.Or.Empty); | ||
Assert.That(creditsData.ExternalTools, Is.Not.Null.Or.Empty); | ||
} | ||
|
||
[Test] | ||
public void Help_GetData_ReturnsNonEmptyCollections() | ||
{ | ||
var service = new DataResourceService(); | ||
var helpData = service.GetHelpData(); | ||
Assert.That(helpData.Hotkeys, Is.Not.Null.Or.Empty); | ||
Assert.That(helpData.Hints, Is.Not.Null.Or.Empty); | ||
} | ||
} | ||
} |
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
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
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
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
Binary file not shown.