Added Unit Tests
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,5 +1,5 @@
|
|||||||
Elwig/obj/
|
obj/
|
||||||
Elwig/bin/
|
bin/
|
||||||
*.user
|
*.user
|
||||||
.vs
|
.vs
|
||||||
.idea
|
.idea
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio Version 17
|
# Visual Studio Version 17
|
||||||
VisualStudioVersion = 17.3.32929.385
|
VisualStudioVersion = 17.3.32929.385
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Elwig", "Elwig\Elwig.csproj", "{00868460-16F6-4B48-AA9B-998F6263693B}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Elwig", "Elwig\Elwig.csproj", "{00868460-16F6-4B48-AA9B-998F6263693B}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "Tests\Tests.csproj", "{AF4B84F8-08E6-409C-9E94-D7D990469597}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@ -15,6 +16,10 @@ Global
|
|||||||
{00868460-16F6-4B48-AA9B-998F6263693B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{00868460-16F6-4B48-AA9B-998F6263693B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{00868460-16F6-4B48-AA9B-998F6263693B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{00868460-16F6-4B48-AA9B-998F6263693B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{00868460-16F6-4B48-AA9B-998F6263693B}.Release|Any CPU.Build.0 = Release|Any CPU
|
{00868460-16F6-4B48-AA9B-998F6263693B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{AF4B84F8-08E6-409C-9E94-D7D990469597}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{AF4B84F8-08E6-409C-9E94-D7D990469597}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{AF4B84F8-08E6-409C-9E94-D7D990469597}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{AF4B84F8-08E6-409C-9E94-D7D990469597}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
@ -108,17 +108,17 @@ namespace Elwig.Helpers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static double OeToKmw(double oe) {
|
public static double OeToKmw(double oe) {
|
||||||
return Math.Round((-4.54 + Math.Sqrt(4.54 * 4.54 - 4 * 0.022 * -oe)) / 2 * 0.022, 1);
|
return Math.Round((-4.54 + Math.Sqrt(4.54 * 4.54 - 4 * 0.022 * -oe)) / (2 * 0.022), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static decimal DecFromDb(long value, byte precision) {
|
public static decimal DecFromDb(long value, byte precision) {
|
||||||
bool neg = value < 0;
|
bool neg = value < 0;
|
||||||
if (neg) value = -value;
|
if (neg) value = -value;
|
||||||
return new decimal((int)(value & 0xFFFFFFFF), (int)((value >> 32) & 0x7FFFFFFF), 0, neg, precision);
|
return new((int)(value & 0xFFFFFFFF), (int)((value >> 32) & 0x7FFFFFFF), 0, neg, precision);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long DecToDb(decimal value, byte precision) {
|
public static long DecToDb(decimal value, byte precision) {
|
||||||
return (long)decimal.Round(value * precision, 0);
|
return (long)decimal.Round(value * (decimal)Math.Pow(10, precision), 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
46
Tests/HelpersUtilsTest.cs
Normal file
46
Tests/HelpersUtilsTest.cs
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
using Elwig.Helpers;
|
||||||
|
|
||||||
|
namespace Tests {
|
||||||
|
[TestClass]
|
||||||
|
public class HelpersUtilsTest {
|
||||||
|
|
||||||
|
private static readonly double[,] Gradation = new double[,] {
|
||||||
|
{ 14.0, 68.0 },
|
||||||
|
{ 15.0, 73.0 },
|
||||||
|
{ 17.1, 84.0 },
|
||||||
|
{ 19.0, 94.0 },
|
||||||
|
{ 21.0, 105.0 },
|
||||||
|
{ 25.0, 127.0 },
|
||||||
|
{ 27.1, 139.0 },
|
||||||
|
{ 30.0, 156.0 },
|
||||||
|
};
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void Test_KmwToOe() {
|
||||||
|
for (int i = 0; i < Gradation.GetLength(0); i++) {
|
||||||
|
Assert.AreEqual(Gradation[i, 1], Utils.KmwToOe(Gradation[i, 0]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void Test_OeToKmw() {
|
||||||
|
for (int i = 0; i < Gradation.GetLength(0); i++) {
|
||||||
|
Assert.AreEqual(Gradation[i, 0], Utils.OeToKmw(Gradation[i, 1]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void Test_DecFromDb() {
|
||||||
|
Assert.AreEqual(10.67M, Utils.DecFromDb(10670, 3));
|
||||||
|
Assert.AreEqual(-100.9999M, Utils.DecFromDb(-1009999, 4));
|
||||||
|
Assert.AreEqual(0.01M, Utils.DecFromDb(1, 2));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void Test_DecToDb() {
|
||||||
|
Assert.AreEqual(21948, Utils.DecToDb(219.48M, 2));
|
||||||
|
Assert.AreEqual(-12345, Utils.DecToDb(-1.2345M, 4));
|
||||||
|
Assert.AreEqual(99190, Utils.DecToDb(99190, 0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
23
Tests/Tests.csproj
Normal file
23
Tests/Tests.csproj
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net7.0-windows</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
|
||||||
|
<IsPackable>false</IsPackable>
|
||||||
|
<IsTestProject>true</IsTestProject>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
|
||||||
|
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
|
||||||
|
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
|
||||||
|
<PackageReference Include="coverlet.collector" Version="3.1.2" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Elwig\Elwig.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
1
Tests/Usings.cs
Normal file
1
Tests/Usings.cs
Normal file
@ -0,0 +1 @@
|
|||||||
|
global using Microsoft.VisualStudio.TestTools.UnitTesting;
|
Reference in New Issue
Block a user