Build 1.1.4.0
This commit is contained in:
@@ -14,8 +14,7 @@ public class EndpointParseTests
|
||||
{
|
||||
Endpoint.Parse("127.0.0.1:27015")
|
||||
.Should()
|
||||
.BeOfType<Some<Endpoint>>()
|
||||
.And.BeEquivalentTo(
|
||||
.BeEquivalentTo(
|
||||
Option<Endpoint>.Some(new LidgrenEndpoint(IPAddress.Loopback, 27015)),
|
||||
options => options.RespectingRuntimeTypes());
|
||||
}
|
||||
@@ -25,8 +24,7 @@ public class EndpointParseTests
|
||||
{
|
||||
Endpoint.Parse("localhost:27015")
|
||||
.Should()
|
||||
.BeOfType<Some<Endpoint>>()
|
||||
.And.BeEquivalentTo(
|
||||
.BeEquivalentTo(
|
||||
Option<Endpoint>.Some(new LidgrenEndpoint(IPAddress.Loopback, 27015)),
|
||||
options => options.RespectingRuntimeTypes());
|
||||
}
|
||||
@@ -36,8 +34,7 @@ public class EndpointParseTests
|
||||
{
|
||||
Address.Parse("127.0.0.1")
|
||||
.Should()
|
||||
.BeOfType<Some<Address>>()
|
||||
.And.BeEquivalentTo(
|
||||
.BeEquivalentTo(
|
||||
Option<Address>.Some(new LidgrenAddress(IPAddress.Loopback)),
|
||||
options => options.RespectingRuntimeTypes());
|
||||
}
|
||||
@@ -47,8 +44,7 @@ public class EndpointParseTests
|
||||
{
|
||||
Endpoint.Parse("STEAM_1:1:508792388")
|
||||
.Should()
|
||||
.BeOfType<Some<Endpoint>>()
|
||||
.And.BeEquivalentTo(
|
||||
.BeEquivalentTo(
|
||||
Option<Endpoint>.Some(new SteamP2PEndpoint(new SteamId(76561198977850505))),
|
||||
options => options.RespectingRuntimeTypes());
|
||||
}
|
||||
@@ -58,8 +54,7 @@ public class EndpointParseTests
|
||||
{
|
||||
Address.Parse("STEAM_1:1:508792388")
|
||||
.Should()
|
||||
.BeOfType<Some<Address>>()
|
||||
.And.BeEquivalentTo(
|
||||
.BeEquivalentTo(
|
||||
Option<Address>.Some(new SteamP2PAddress(new SteamId(76561198977850505))),
|
||||
options => options.RespectingRuntimeTypes());
|
||||
new SteamId(76561198977850505).StringRepresentation.Should().BeEquivalentTo("STEAM_1:1:508792388");
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
using Barotrauma;
|
||||
using FluentAssertions;
|
||||
using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using Xunit;
|
||||
|
||||
namespace TestProject;
|
||||
|
||||
public class MathUtilsTests
|
||||
{
|
||||
[Fact]
|
||||
public void TestNearlyEquals()
|
||||
{
|
||||
MathUtils.NearlyEqual(0.0f, 0.0f).Should().BeTrue();
|
||||
MathUtils.NearlyEqual(-float.Epsilon, float.Epsilon).Should().BeTrue();
|
||||
MathUtils.NearlyEqual(0.1f + 0.2f, 0.3f).Should().BeTrue();
|
||||
MathUtils.NearlyEqual(-1.0f, 1.0f).Should().BeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestWrapAngle()
|
||||
{
|
||||
MathUtils.NearlyEqual(MathUtils.WrapAnglePi(0.0f), 0.0f).Should().BeTrue();
|
||||
|
||||
CheckWrapAnglePiNearlyEqual(0, 0).Should().BeTrue();
|
||||
CheckWrapAnglePiNearlyEqual(-90, -90).Should().BeTrue();
|
||||
CheckWrapAnglePiNearlyEqual(-90, 90).Should().BeFalse();
|
||||
CheckWrapAnglePiNearlyEqual(-180, 180).Should().BeTrue();
|
||||
CheckWrapAnglePiNearlyEqual(-190.0f, 170.0f).Should().BeTrue();
|
||||
CheckWrapAnglePiNearlyEqual(-360, 0).Should().BeTrue();
|
||||
CheckWrapAnglePiNearlyEqual(360, 0).Should().BeTrue();
|
||||
|
||||
bool CheckWrapAnglePiNearlyEqual(float wrappedDeg, float deg)
|
||||
{
|
||||
float wrappedRad = MathUtils.WrapAnglePi(MathHelper.ToRadians(wrappedDeg));
|
||||
float rad = MathHelper.ToRadians(deg);
|
||||
return MathUtils.NearlyEqual(wrappedRad, rad) || MathUtils.NearlyEqual(Math.Abs(wrappedRad - rad), MathHelper.TwoPi);
|
||||
}
|
||||
|
||||
CheckWrapAngleTwoPiNearlyEqual(0, 0).Should().BeTrue();
|
||||
CheckWrapAngleTwoPiNearlyEqual(90, 90).Should().BeTrue();
|
||||
CheckWrapAngleTwoPiNearlyEqual(-90, 270).Should().BeTrue();
|
||||
CheckWrapAngleTwoPiNearlyEqual(180, 180).Should().BeTrue();
|
||||
CheckWrapAngleTwoPiNearlyEqual(360 * 5, 0).Should().BeTrue();
|
||||
CheckWrapAngleTwoPiNearlyEqual(-360, 0).Should().BeTrue();
|
||||
|
||||
bool CheckWrapAngleTwoPiNearlyEqual(float wrappedDeg, float deg)
|
||||
{
|
||||
float wrappedRad = MathUtils.WrapAngleTwoPi(MathHelper.ToRadians(wrappedDeg));
|
||||
float rad = MathHelper.ToRadians(deg);
|
||||
return MathUtils.NearlyEqual(wrappedRad, rad) || MathUtils.NearlyEqual(Math.Abs(wrappedRad - rad), MathHelper.TwoPi);
|
||||
}
|
||||
|
||||
CheckShortestAngleNearlyEqual(0.0f, 0.0f, 0.0f).Should().BeTrue();
|
||||
CheckShortestAngleNearlyEqual(0.0f, 90.0f, 90.0f).Should().BeTrue();
|
||||
CheckShortestAngleNearlyEqual(0.0f, 360.0f, 0.0f).Should().BeTrue();
|
||||
CheckShortestAngleNearlyEqual(0.0f, -365.0f, -5.0f).Should().BeTrue();
|
||||
CheckShortestAngleNearlyEqual(180.0f, -180.0f, 0.0f).Should().BeTrue();
|
||||
CheckShortestAngleNearlyEqual(-355.0f, 5.0f, 10.0f);
|
||||
|
||||
bool CheckShortestAngleNearlyEqual(float deg1, float deg2, float angle)
|
||||
{
|
||||
return MathUtils.NearlyEqual(MathUtils.GetShortestAngle(MathHelper.ToRadians(deg1), MathHelper.ToRadians(deg2)), MathHelper.ToRadians(angle));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
using Barotrauma;
|
||||
using FluentAssertions;
|
||||
using FsCheck;
|
||||
using System;
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
namespace TestProject;
|
||||
|
||||
public sealed class PropertyConditionalTests
|
||||
{
|
||||
private readonly record struct OperatorStr(string Str);
|
||||
private readonly record struct ConditionStr(string Str);
|
||||
|
||||
private class CustomGenerators
|
||||
{
|
||||
public static Arbitrary<OperatorStr> OperatorStrGeneratorOverride()
|
||||
{
|
||||
return Gen.Choose(0, operators.Length-1)
|
||||
.Select(i => operators[i])
|
||||
.ToArbitrary();
|
||||
}
|
||||
|
||||
public static Arbitrary<ConditionStr> ConditionStrGeneratorOverride()
|
||||
{
|
||||
return Arb.Generate<string>()
|
||||
.Where(s => s != null && !s.Any(char.IsWhiteSpace) && !s.Contains(','))
|
||||
.Select(s => new ConditionStr(s)).ToArbitrary();
|
||||
}
|
||||
}
|
||||
|
||||
public PropertyConditionalTests()
|
||||
{
|
||||
Arb.Register<TestProject.CustomGenerators>();
|
||||
Arb.Register<CustomGenerators>();
|
||||
}
|
||||
|
||||
static ImmutableArray<OperatorStr> operators
|
||||
= new[]
|
||||
{
|
||||
"eq", "neq", "gt",
|
||||
"gte", "lt", "lte"
|
||||
}.Select(s => new OperatorStr(s)).ToImmutableArray();
|
||||
|
||||
[Fact]
|
||||
public void TestExtractComparisonOperatorFromConditionString()
|
||||
{
|
||||
Prop.ForAll(
|
||||
Arb.Generate<OperatorStr>().ToArbitrary(),
|
||||
Arb.Generate<ConditionStr>().ToArbitrary(),
|
||||
ExtractComparisonOperatorFromConditionStringCase)
|
||||
.QuickCheckThrowOnFailure();
|
||||
}
|
||||
|
||||
private static void ExtractComparisonOperatorFromConditionStringCase(OperatorStr operatorStr, ConditionStr conditionStr)
|
||||
{
|
||||
var op = PropertyConditional.GetComparisonOperatorType(operatorStr.Str);
|
||||
|
||||
var (op2, condStr) = PropertyConditional.ExtractComparisonOperatorFromConditionString(operatorStr.Str + " " + conditionStr.Str);
|
||||
op2.Should().Be(op);
|
||||
condStr.Should().Be(conditionStr.Str);
|
||||
|
||||
var (op3, condStr2) = PropertyConditional.ExtractComparisonOperatorFromConditionString(conditionStr.Str);
|
||||
op3.Should().Be(PropertyConditional.ComparisonOperatorType.Equals);
|
||||
condStr2.Should().Be(conditionStr.Str);
|
||||
}
|
||||
}
|
||||
@@ -37,22 +37,26 @@ public sealed class SerializableDateTimeTests
|
||||
{
|
||||
Prop.ForAll<SerializableDateTime>(EqualityCheck).QuickCheckThrowOnFailure();
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void ParseTest()
|
||||
{
|
||||
var parseTest = "9369Y 09M 06D 03HR 43MIN 09SEC UTC+8:49";
|
||||
SerializableDateTime.Parse(parseTest);
|
||||
Prop.ForAll<SerializableDateTime>(ParseCheck).QuickCheckThrowOnFailure();
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void ToLocalTest()
|
||||
{
|
||||
Prop.ForAll<SerializableDateTime>(ToLocalCheck).QuickCheckThrowOnFailure();
|
||||
}
|
||||
|
||||
private static void EqualityCheck(SerializableDateTime original)
|
||||
{
|
||||
var local = original.ToLocal();
|
||||
var utc = original.ToUtc();
|
||||
original.Should().BeEquivalentTo(local);
|
||||
original.Should().BeEquivalentTo(utc);
|
||||
local.Should().BeEquivalentTo(utc);
|
||||
original.Should().BeEquivalentTo(local, because: "original must equal local");
|
||||
original.Should().BeEquivalentTo(utc, because: "original must equal utc");
|
||||
local.Should().BeEquivalentTo(utc, because: "local must equal utc");
|
||||
}
|
||||
|
||||
private static void ParseCheck(SerializableDateTime original)
|
||||
@@ -61,4 +65,11 @@ public sealed class SerializableDateTimeTests
|
||||
SerializableDateTime.Parse(str).TryUnwrap(out var parsedTime).Should().BeTrue();
|
||||
parsedTime.Should().BeEquivalentTo(original);
|
||||
}
|
||||
|
||||
private static void ToLocalCheck(SerializableDateTime original)
|
||||
{
|
||||
var localNow = SerializableDateTime.LocalNow;
|
||||
var convertedDateTime = original.ToLocal();
|
||||
localNow.TimeZone.Should().BeEquivalentTo(convertedDateTime.TimeZone);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user