Build 0.21.6.0

This commit is contained in:
Markus Isberg
2023-01-31 18:01:29 +02:00
parent 697ec52120
commit 25fa5a9552
145 changed files with 2317 additions and 1145 deletions
@@ -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();
}
}
@@ -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,64 @@
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()
{
var parseTest = "9369Y 09M 06D 03HR 43MIN 09SEC UTC+8:49";
SerializableDateTime.Parse(parseTest);
Prop.ForAll<SerializableDateTime>(ParseCheck).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);
}
private static void ParseCheck(SerializableDateTime original)
{
var str = original.ToString();
SerializableDateTime.Parse(str).TryUnwrap(out var parsedTime).Should().BeTrue();
parsedTime.Should().BeEquivalentTo(original);
}
}
+2 -2
View File
@@ -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));
}