v1.0.7.0 (Full Release)
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
using Barotrauma.Utils;
|
||||
using FluentAssertions;
|
||||
using FsCheck;
|
||||
using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using Xunit;
|
||||
namespace TestProject;
|
||||
|
||||
public class CoordinateSpace2DTests
|
||||
{
|
||||
class CustomGenerators
|
||||
{
|
||||
public static Arbitrary<Vector2> Vector2Generator()
|
||||
{
|
||||
const int intRange = 1 << 22;
|
||||
const float intToFloat = 1 << 19;
|
||||
|
||||
return Arb.From(
|
||||
from int x in Gen.Choose(-intRange, intRange)
|
||||
from int y in Gen.Choose(-intRange, intRange)
|
||||
select new Vector2(x / intToFloat, y / intToFloat));
|
||||
}
|
||||
}
|
||||
|
||||
public CoordinateSpace2DTests()
|
||||
{
|
||||
Arb.Register<CustomGenerators>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestLocalToCanonical()
|
||||
{
|
||||
void testCase(Tuple<Vector2, Vector2, Vector2, Vector2> args)
|
||||
{
|
||||
var (vector, origin, i, j) = args;
|
||||
|
||||
if (Vector2.DistanceSquared(i, j) <= 0.01f) { return; }
|
||||
|
||||
var space = new CoordinateSpace2D
|
||||
{
|
||||
Origin = origin,
|
||||
I = i,
|
||||
J = j
|
||||
};
|
||||
|
||||
Assert.True(Vector2.DistanceSquared(
|
||||
Vector2.Transform(vector, space.LocalToCanonical),
|
||||
origin + vector.X * i + vector.Y * j) < 0.01f);
|
||||
}
|
||||
|
||||
Prop.ForAll(
|
||||
Arb.Generate<Tuple<Vector2, Vector2, Vector2, Vector2>>().ToArbitrary(),
|
||||
testCase).QuickCheckThrowOnFailure();
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
|
||||
@@ -10,7 +10,7 @@ using Xunit;
|
||||
|
||||
namespace TestProject;
|
||||
|
||||
public class INetSerializableStructImplementationChecks
|
||||
public sealed class INetSerializableStructImplementationChecks
|
||||
{
|
||||
private delegate bool TryFindBehaviorDelegate(Type type, out NetSerializableProperties.IReadWriteBehavior behavior);
|
||||
|
||||
@@ -49,7 +49,7 @@ public class INetSerializableStructImplementationChecks
|
||||
viableArguments.AddRange(new[]
|
||||
{
|
||||
typeof(Vector2),
|
||||
typeof(Point),
|
||||
typeof(float),
|
||||
typeof(int)
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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,75 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using Barotrauma;
|
||||
using FluentAssertions;
|
||||
using FsCheck;
|
||||
using Xunit;
|
||||
|
||||
namespace TestProject;
|
||||
|
||||
public sealed class SerializableDateTimeTests
|
||||
{
|
||||
private class CustomGenerators
|
||||
{
|
||||
private const short MinutesPerDay = 24 * 60;
|
||||
private const int SecondsPerDay = MinutesPerDay * 60;
|
||||
|
||||
public static Arbitrary<SerializableDateTime> SerializableDateTimeGenerator()
|
||||
{
|
||||
return Arb.From(
|
||||
from int dateTimeDay in Gen.Choose(0, (int)(DateTime.MaxValue.Ticks / TimeSpan.TicksPerDay))
|
||||
from int dateTimeSeconds in Gen.Choose(0, SecondsPerDay)
|
||||
from int timeZoneMinutes in Gen.Choose(-MinutesPerDay / 2, MinutesPerDay / 2)
|
||||
select new SerializableDateTime(
|
||||
DateTime.MinValue + TimeSpan.FromDays(dateTimeDay) + TimeSpan.FromSeconds(dateTimeSeconds),
|
||||
new SerializableTimeZone(TimeSpan.FromMinutes(timeZoneMinutes))));
|
||||
}
|
||||
}
|
||||
|
||||
public SerializableDateTimeTests()
|
||||
{
|
||||
Arb.Register<TestProject.CustomGenerators>();
|
||||
Arb.Register<CustomGenerators>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EqualityTest()
|
||||
{
|
||||
Prop.ForAll<SerializableDateTime>(EqualityCheck).QuickCheckThrowOnFailure();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void 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, 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)
|
||||
{
|
||||
var str = original.ToString();
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -10,8 +10,8 @@ namespace TestProject
|
||||
{
|
||||
public static Arbitrary<Vector2> Vector2Generator()
|
||||
{
|
||||
return Arb.From(from int x in Arb.Generate<int>()
|
||||
from int y in Arb.Generate<int>()
|
||||
return Arb.From(from float x in Arb.Generate<float>().Where(f => !float.IsNaN(f) && !float.IsInfinity(f))
|
||||
from float y in Arb.Generate<float>().Where(f => !float.IsNaN(f) && !float.IsInfinity(f))
|
||||
select new Vector2(x, y));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user