BIG BOI FORMATTING
This commit is contained in:
@@ -6,16 +6,6 @@ namespace UnitTests.Mock;
|
||||
|
||||
public class MockLogger<T> : ISptLogger<T>
|
||||
{
|
||||
public void LogWithColor(
|
||||
string data,
|
||||
Exception? ex = null,
|
||||
LogTextColor? textColor = null,
|
||||
LogBackgroundColor? backgroundColor = null
|
||||
)
|
||||
{
|
||||
Console.WriteLine(data);
|
||||
}
|
||||
|
||||
public void LogWithColor(string data, LogTextColor? textColor = null, LogBackgroundColor? backgroundColor = null, Exception? ex = null)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
@@ -61,6 +51,16 @@ public class MockLogger<T> : ISptLogger<T>
|
||||
return true;
|
||||
}
|
||||
|
||||
public void LogWithColor(
|
||||
string data,
|
||||
Exception? ex = null,
|
||||
LogTextColor? textColor = null,
|
||||
LogBackgroundColor? backgroundColor = null
|
||||
)
|
||||
{
|
||||
Console.WriteLine(data);
|
||||
}
|
||||
|
||||
public void WriteToLogFile(object body)
|
||||
{
|
||||
Console.WriteLine(body);
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using Core.Models.Spt.Server;
|
||||
using Core.Models.Spt.Templates;
|
||||
using Core.Utils;
|
||||
using UnitTests.Mock;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using Core.Utils;
|
||||
using Core.Utils.Cloners;
|
||||
using System.Net.Mail;
|
||||
using UnitTests.Mock;
|
||||
|
||||
namespace UnitTests.Tests.Utils;
|
||||
|
||||
@@ -11,7 +11,10 @@ public class JsonUtilTests
|
||||
[TestMethod]
|
||||
public void SerializeAndDeserialize_WithDictionaryOfETFEnum_ExpectCorrectParsing()
|
||||
{
|
||||
var value = new Dictionary<QuestStatusEnum, int> { { QuestStatusEnum.AvailableForStart, 1 } };
|
||||
var value = new Dictionary<QuestStatusEnum, int>
|
||||
{
|
||||
{ QuestStatusEnum.AvailableForStart, 1 }
|
||||
};
|
||||
var result = _jsonUtil.Deserialize<Dictionary<QuestStatusEnum, int>>(_jsonUtil.Serialize(value));
|
||||
Assert.AreEqual(value.Count, result?.Count);
|
||||
Assert.AreEqual(value.First().Key, result?.First().Key);
|
||||
|
||||
@@ -10,7 +10,12 @@ public class MathUtilTests
|
||||
[TestMethod]
|
||||
public void ListSumTest()
|
||||
{
|
||||
var test = new List<double> { 1.1f, 2.1f, 3.3f };
|
||||
var test = new List<double>
|
||||
{
|
||||
1.1f,
|
||||
2.1f,
|
||||
3.3f
|
||||
};
|
||||
const double expected = 6.5f;
|
||||
|
||||
var actual = _mathUtil.ListSum(test);
|
||||
@@ -25,40 +30,88 @@ public class MathUtilTests
|
||||
[TestMethod]
|
||||
public void ListCumSumTest()
|
||||
{
|
||||
var test = new List<double> { 1f, 2f, 3f, 4f };
|
||||
var expected = new List<double> { 1f, 3f, 6f, 10f };
|
||||
var test = new List<double>
|
||||
{
|
||||
1f,
|
||||
2f,
|
||||
3f,
|
||||
4f
|
||||
};
|
||||
var expected = new List<double>
|
||||
{
|
||||
1f,
|
||||
3f,
|
||||
6f,
|
||||
10f
|
||||
};
|
||||
|
||||
var actual = _mathUtil.ListCumSum(test);
|
||||
|
||||
for (var i = 0; i < actual.Count; i++)
|
||||
{
|
||||
if (Math.Abs(expected[i] - actual[i]) > 0.00001f)
|
||||
{
|
||||
Assert.Fail($"ListCumSum() Expected: {string.Join(", ", expected)}, Actual: {string.Join(", ", actual)}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ListProductTest()
|
||||
{
|
||||
var test = new List<double> { 1f, 2f, 3f, 4f };
|
||||
var expected = new List<double> { 2f, 4f, 6f, 8f };
|
||||
var test = new List<double>
|
||||
{
|
||||
1f,
|
||||
2f,
|
||||
3f,
|
||||
4f
|
||||
};
|
||||
var expected = new List<double>
|
||||
{
|
||||
2f,
|
||||
4f,
|
||||
6f,
|
||||
8f
|
||||
};
|
||||
|
||||
var actual = _mathUtil.ListProduct(test, 2);
|
||||
|
||||
for (var i = 0; i < actual.Count; i++)
|
||||
{
|
||||
if (Math.Abs(expected[i] - actual[i]) > 0.00001f)
|
||||
{
|
||||
Assert.Fail($"ListProduct() Expected: {string.Join(", ", expected)}, Actual: {string.Join(", ", actual)}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ListAddTest()
|
||||
{
|
||||
var test = new List<double> { 1f, 2f, 3f, 4f };
|
||||
var expected = new List<double> { 3f, 4f, 5f, 6f };
|
||||
var test = new List<double>
|
||||
{
|
||||
1f,
|
||||
2f,
|
||||
3f,
|
||||
4f
|
||||
};
|
||||
var expected = new List<double>
|
||||
{
|
||||
3f,
|
||||
4f,
|
||||
5f,
|
||||
6f
|
||||
};
|
||||
|
||||
var actual = _mathUtil.ListAdd(test, 2);
|
||||
|
||||
for (var i = 0; i < actual.Count; i++)
|
||||
{
|
||||
if (Math.Abs(expected[i] - actual[i]) > 0.00001f)
|
||||
{
|
||||
Assert.Fail($"ListProduct() Expected: {string.Join(", ", expected)}, Actual: {string.Join(", ", actual)}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using Core.Utils;
|
||||
using Core.Utils.Cloners;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using UnitTests.Mock;
|
||||
|
||||
namespace UnitTests.Tests.Utils;
|
||||
@@ -8,7 +7,7 @@ namespace UnitTests.Tests.Utils;
|
||||
[TestClass]
|
||||
public sealed class RandomUtilTests
|
||||
{
|
||||
private RandomUtil _randomUtil = new(new MockLogger<RandomUtil>(), new JsonCloner(new JsonUtil()));
|
||||
private readonly RandomUtil _randomUtil = new(new MockLogger<RandomUtil>(), new JsonCloner(new JsonUtil()));
|
||||
|
||||
[TestMethod]
|
||||
public void GetIntTest()
|
||||
@@ -18,7 +17,10 @@ public sealed class RandomUtilTests
|
||||
{
|
||||
var result = _randomUtil.GetInt(0, 10);
|
||||
|
||||
if (result < 0 || result > 10) Assert.Fail($"GetInt(0, 10) out of range. Expected range [0, 10] but was {result}.");
|
||||
if (result < 0 || result > 10)
|
||||
{
|
||||
Assert.Fail($"GetInt(0, 10) out of range. Expected range [0, 10] but was {result}.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +32,10 @@ public sealed class RandomUtilTests
|
||||
{
|
||||
var result = _randomUtil.GetInt(1, 10, true);
|
||||
|
||||
if (result < 1 || result > 9) Assert.Fail($"GetInt(10) out of range. Expected range [1, 9] but was {result}.");
|
||||
if (result < 1 || result > 9)
|
||||
{
|
||||
Assert.Fail($"GetInt(10) out of range. Expected range [1, 9] but was {result}.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +47,10 @@ public sealed class RandomUtilTests
|
||||
{
|
||||
var result = _randomUtil.GetDouble(0D, 10D);
|
||||
|
||||
if (result is < 0d or >= 10d) Assert.Fail($"GetDouble(0d, 10d) out of range. Expected range [0.0d, 9.999d] but was {result}.");
|
||||
if (result is < 0d or >= 10d)
|
||||
{
|
||||
Assert.Fail($"GetDouble(0d, 10d) out of range. Expected range [0.0d, 9.999d] but was {result}.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,14 +119,20 @@ public sealed class RandomUtilTests
|
||||
{
|
||||
var result = _randomUtil.RandInt(0, 10);
|
||||
|
||||
if (result < 0 || result > 9) Assert.Fail($"RandInt(0, 10) out of range. Expected range [0, 9] but was {result}.");
|
||||
if (result < 0 || result > 9)
|
||||
{
|
||||
Assert.Fail($"RandInt(0, 10) out of range. Expected range [0, 9] but was {result}.");
|
||||
}
|
||||
}
|
||||
|
||||
for (var i = 0; i < 100; i++)
|
||||
{
|
||||
var result = _randomUtil.RandInt(10);
|
||||
|
||||
if (result < 0 || result > 9) Assert.Fail($"RandInt(10, null) out of range. Expected range [0, 9] but was {result}.");
|
||||
if (result < 0 || result > 9)
|
||||
{
|
||||
Assert.Fail($"RandInt(10, null) out of range. Expected range [0, 9] but was {result}.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,29 +143,48 @@ public sealed class RandomUtilTests
|
||||
{
|
||||
var result = _randomUtil.RandNum(0, 10, 15);
|
||||
|
||||
if (result < 0 || result >= 10) Assert.Fail($"RandNum(0, 10) out of range. Expected range [0, 9.999d] but was {result}.");
|
||||
if (result < 0 || result >= 10)
|
||||
{
|
||||
Assert.Fail($"RandNum(0, 10) out of range. Expected range [0, 9.999d] but was {result}.");
|
||||
}
|
||||
|
||||
if (_randomUtil.GetNumberPrecision(result) > RandomUtil.MaxSignificantDigits)
|
||||
{
|
||||
Assert.Fail($"RandNum(0, 10) precision of {result} exceeds the allowable precision ({RandomUtil.MaxSignificantDigits}) for the given values.");
|
||||
}
|
||||
}
|
||||
|
||||
for (var i = 0; i < 10000; i++)
|
||||
{
|
||||
var result = _randomUtil.RandNum(10);
|
||||
|
||||
if (result < 0 || result >= 10) Assert.Fail($"RandNum(10) out of range. Expected range [0, 9.999d] but was {result}.");
|
||||
if (result < 0 || result >= 10)
|
||||
{
|
||||
Assert.Fail($"RandNum(10) out of range. Expected range [0, 9.999d] but was {result}.");
|
||||
}
|
||||
|
||||
if (_randomUtil.GetNumberPrecision(result) > RandomUtil.MaxSignificantDigits)
|
||||
{
|
||||
Assert.Fail($"RandNum(10) precision of {result} exceeds the allowable precision ({RandomUtil.MaxSignificantDigits}) for the given values.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ShuffleTest()
|
||||
{
|
||||
var testList = new List<int>()
|
||||
var testList = new List<int>
|
||||
{
|
||||
1, 2, 3, 4, 5, 6, 7, 8, 9, 10
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
4,
|
||||
5,
|
||||
6,
|
||||
7,
|
||||
8,
|
||||
9,
|
||||
10
|
||||
};
|
||||
|
||||
var orig = new List<int>(testList);
|
||||
|
||||
+25
-25
@@ -1,34 +1,34 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1"/>
|
||||
<PackageReference Include="MSTest" Version="3.6.1"/>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1"/>
|
||||
<PackageReference Include="MSTest" Version="3.6.1"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting"/>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Libraries\Core\Core.csproj" />
|
||||
<ProjectReference Include="..\Libraries\SptDependencyInjection\SptDependencyInjection.csproj" />
|
||||
<ProjectReference Include="..\SptCommon\SptCommon.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Libraries\Core\Core.csproj"/>
|
||||
<ProjectReference Include="..\Libraries\SptDependencyInjection\SptDependencyInjection.csproj"/>
|
||||
<ProjectReference Include="..\SptCommon\SptCommon.csproj"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="TestAssets\**">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="TestAssets\**">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Remove="Tests\Mock\MockSptLogger.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Remove="Tests\Mock\MockSptLogger.cs"/>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user