Fix trailing zeros regex, add unit tests

This commit is contained in:
Tyfon
2024-04-30 16:34:07 -07:00
parent 17cea8e958
commit 107d598b7e
5 changed files with 87 additions and 5 deletions

View File

@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\UIFixes.csproj" />
</ItemGroup>
<ItemGroup>
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" />
</ItemGroup>
</Project>

34
UIFixes.Test/UnitTests.cs Normal file
View File

@@ -0,0 +1,34 @@
namespace UIFixes.Test
{
[TestClass]
public class UnitTests
{
[TestMethod]
public void RemoveTrailingZeroTest()
{
var testCases = new Dictionary<string, string>
{
{ "10", "10" },
{ "400", "400" },
{ "4.01", "4.01" },
{ "5.060", "5.06" },
{ "3.000", "3" },
{ "2.0000001000", "2.0000001" },
{ "0.5", "0.5" },
{ "0.05", "0.05" },
{ "0.50", "0.5" },
{ "400sec", "400sec" },
{ "del. 2sec", "del. 2sec" },
{ "Hello.world", "Hello.world" },
{ "2Fast20Furious0", "2Fast20Furious0" },
{ "1.0.2", "1.0.2" }
};
foreach (var testCase in testCases)
{
string result = ItemPanelPatches.RemoveTrailingZeros(testCase.Key);
Assert.AreEqual(result, testCase.Value);
}
}
}
}