Unstable 1.8.4.0
This commit is contained in:
@@ -0,0 +1,129 @@
|
||||
extern alias Client;
|
||||
extern alias Server;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading;
|
||||
using FsCheck;
|
||||
using Server::Barotrauma;
|
||||
using Server::Barotrauma.Networking;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
using DeliveryMethod = Barotrauma.Networking.DeliveryMethod;
|
||||
using Option = Barotrauma.Option;
|
||||
using PeerDisconnectPacket = Client::Barotrauma.Networking.PeerDisconnectPacket;
|
||||
using Random = System.Random;
|
||||
using WriteOnlyMessage = Client::Barotrauma.Networking.WriteOnlyMessage;
|
||||
|
||||
|
||||
namespace TestProject;
|
||||
|
||||
public class ClientServerTests : IDisposable
|
||||
{
|
||||
private readonly ITestOutputHelper testOutputHelper;
|
||||
|
||||
private readonly GameMain serverGame;
|
||||
private GameServer? currentServer;
|
||||
private readonly string generatedPassword;
|
||||
|
||||
private const string ServerName = "UnitTestServer";
|
||||
|
||||
public ClientServerTests(ITestOutputHelper testOutputHelper)
|
||||
{
|
||||
this.testOutputHelper = testOutputHelper;
|
||||
|
||||
serverGame = new GameMain(Array.Empty<string>());
|
||||
serverGame.Init();
|
||||
var random = new Random();
|
||||
generatedPassword = new string(Enumerable.Range(0, 24).Select(_ => (char)random.Next(minValue: 'A', maxValue: 'z')).ToArray());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestLidgren()
|
||||
{
|
||||
var server = CreateServer();
|
||||
var client = CreateClient(server);
|
||||
Prop.ForAll<byte[]>(data =>
|
||||
{
|
||||
var msg = new WriteOnlyMessage();
|
||||
foreach (byte b in data)
|
||||
{
|
||||
msg.WriteByte(b);
|
||||
}
|
||||
client.ClientPeer.Send(msg, DeliveryMethod.Reliable);
|
||||
string logBytes = ToolBox.BytesToHexString(data);
|
||||
if (logBytes.Length > 10) { logBytes = logBytes[..10] + "..."; }
|
||||
testOutputHelper.WriteLine($"Sent {data.Length} byte(s) to server: {logBytes}");
|
||||
client.Update();
|
||||
UpdateServer(server);
|
||||
|
||||
// some data will make the client disconnect,
|
||||
// for example, if the generated data lands on a disconnect packet
|
||||
// so don't treat this as a failure, just reconnect
|
||||
if (!client.IsConnected)
|
||||
{
|
||||
client = CreateClient(server);
|
||||
}
|
||||
}).VerboseCheckThrowOnFailure();
|
||||
|
||||
Thread.Sleep(1000);
|
||||
client.ClientPeer.Close(PeerDisconnectPacket.Custom("Test complete"));
|
||||
}
|
||||
|
||||
private HeadlessNetworkClient CreateClient(GameServer server)
|
||||
{
|
||||
var client = new HeadlessNetworkClient(IPAddress.Loopback, server.Port, generatedPassword, testOutputHelper);
|
||||
|
||||
while (!client.IsConnected)
|
||||
{
|
||||
client.Update();
|
||||
UpdateServer(server);
|
||||
Thread.Sleep(17);
|
||||
}
|
||||
|
||||
return client;
|
||||
}
|
||||
|
||||
private GameServer CreateServer()
|
||||
{
|
||||
if (currentServer != null)
|
||||
{
|
||||
serverGame.CloseServer();
|
||||
}
|
||||
|
||||
currentServer = new GameServer(
|
||||
name: ServerName,
|
||||
port: NetConfig.DefaultPort,
|
||||
queryPort: NetConfig.DefaultQueryPort,
|
||||
maxPlayers: 1,
|
||||
password: generatedPassword,
|
||||
isPublic: false,
|
||||
attemptUPnP: false,
|
||||
ownerKey: Option.None,
|
||||
ownerEndpoint: Option.None);
|
||||
|
||||
GameMain.Server = currentServer;
|
||||
currentServer.StartServer(registerToServerList: false);
|
||||
return currentServer;
|
||||
}
|
||||
|
||||
private void UpdateServer(GameServer server)
|
||||
{
|
||||
server.Update((float)Timing.Step);
|
||||
Timing.TotalTime += Timing.Step;
|
||||
}
|
||||
|
||||
~ClientServerTests()
|
||||
{
|
||||
OnTestsFinished();
|
||||
}
|
||||
|
||||
private void OnTestsFinished()
|
||||
=> serverGame.CloseServer();
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
OnTestsFinished();
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
extern alias Client;
|
||||
using System.Net;
|
||||
using Client::Barotrauma;
|
||||
using Client::Barotrauma.Networking;
|
||||
using Xunit.Abstractions;
|
||||
using Option = Barotrauma.Option;
|
||||
using TaskPool = Barotrauma.TaskPool;
|
||||
|
||||
namespace TestProject
|
||||
{
|
||||
/// <summary>
|
||||
/// We don't join a server with fully initialized client since it's not needed,
|
||||
/// and we only want to test if the server crashes or not.
|
||||
/// </summary>
|
||||
public class HeadlessNetworkClient
|
||||
{
|
||||
internal readonly ClientPeer ClientPeer;
|
||||
public bool IsConnected { get; private set; }
|
||||
|
||||
private readonly ITestOutputHelper testOutputHelper;
|
||||
|
||||
public HeadlessNetworkClient(IPAddress address, int port, string password, ITestOutputHelper testOutputHelper)
|
||||
{
|
||||
var callbacks = new ClientPeer.Callbacks(
|
||||
OnMessageReceived,
|
||||
Disconnect,
|
||||
InitializationComplete);
|
||||
|
||||
ClientPeer = new LidgrenClientPeer(new LidgrenEndpoint(address, port), callbacks, Option.None);
|
||||
ClientPeer.Start();
|
||||
TaskPool.Update(); // Start() adds a task to the TaskPool, so we need to update it to continue
|
||||
IsConnected = false;
|
||||
this.testOutputHelper = testOutputHelper;
|
||||
ClientPeer.AutomaticallyAttemptedPassword = password;
|
||||
}
|
||||
|
||||
private void InitializationComplete()
|
||||
{
|
||||
IsConnected = true;
|
||||
testOutputHelper.WriteLine("Headless client successfully connected to server");
|
||||
}
|
||||
|
||||
private void Disconnect(PeerDisconnectPacket packet)
|
||||
{
|
||||
testOutputHelper.WriteLine($"Headless client was disconnected with reason: {packet.DisconnectReason} ({packet.AdditionalInformation})");
|
||||
IsConnected = false;
|
||||
}
|
||||
|
||||
private void OnMessageReceived(IReadMessage msg)
|
||||
{
|
||||
ClientPacketHeader header = (ClientPacketHeader)msg.ReadByte();
|
||||
testOutputHelper.WriteLine($"Headless client received message: {header}");
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
ClientPeer.Update((float)Timing.Step);
|
||||
TaskPool.Update();
|
||||
Timing.TotalTime += Timing.Step;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
using Barotrauma;
|
||||
extern alias Client;
|
||||
using FluentAssertions;
|
||||
using FsCheck;
|
||||
using Xunit;
|
||||
using static Barotrauma.ItemPrefab;
|
||||
|
||||
using Level = Client::Barotrauma.Level;
|
||||
using CommonnessInfo = Client::Barotrauma.ItemPrefab.CommonnessInfo;
|
||||
|
||||
namespace TestProject
|
||||
{
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
using Barotrauma.Utils;
|
||||
using FluentAssertions;
|
||||
extern alias Client;
|
||||
using FsCheck;
|
||||
using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using Xunit;
|
||||
|
||||
using CoordinateSpace2D = Client::Barotrauma.Utils.CoordinateSpace2D;
|
||||
namespace TestProject;
|
||||
|
||||
public class CoordinateSpace2DTests
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
#nullable enable
|
||||
extern alias Client;
|
||||
using System.Net;
|
||||
using Barotrauma;
|
||||
using Xunit;
|
||||
using Barotrauma.Networking;
|
||||
using FluentAssertions;
|
||||
|
||||
using Endpoint = Client::Barotrauma.Networking.Endpoint;
|
||||
using LidgrenEndpoint = Client::Barotrauma.Networking.LidgrenEndpoint;
|
||||
using SteamP2PEndpoint = Client::Barotrauma.Networking.SteamP2PEndpoint;
|
||||
|
||||
namespace TestProject;
|
||||
|
||||
public class EndpointParseTests
|
||||
@@ -18,7 +23,7 @@ public class EndpointParseTests
|
||||
Option<Endpoint>.Some(new LidgrenEndpoint(IPAddress.Loopback, 27015)),
|
||||
options => options.RespectingRuntimeTypes());
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void TestLidgrenEndpointHostName()
|
||||
{
|
||||
@@ -28,7 +33,7 @@ public class EndpointParseTests
|
||||
Option<Endpoint>.Some(new LidgrenEndpoint(IPAddress.Loopback, 27015)),
|
||||
options => options.RespectingRuntimeTypes());
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void TestLidgrenAddress()
|
||||
{
|
||||
@@ -38,7 +43,7 @@ public class EndpointParseTests
|
||||
Option<Address>.Some(new LidgrenAddress(IPAddress.Loopback)),
|
||||
options => options.RespectingRuntimeTypes());
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void TestSteamP2PEndpoint()
|
||||
{
|
||||
@@ -48,7 +53,7 @@ public class EndpointParseTests
|
||||
Option<Endpoint>.Some(new SteamP2PEndpoint(new SteamId(76561198977850505))),
|
||||
options => options.RespectingRuntimeTypes());
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void TestSteamP2PAddress()
|
||||
{
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
using Barotrauma;
|
||||
extern alias Client;
|
||||
|
||||
using Barotrauma;
|
||||
using FluentAssertions;
|
||||
using Barotrauma.Extensions;
|
||||
using FluentAssertions;
|
||||
using Xunit;
|
||||
using Client::Barotrauma;
|
||||
|
||||
namespace TestProject;
|
||||
|
||||
@@ -11,53 +13,10 @@ public class EnumTests
|
||||
[Fact]
|
||||
public void TestFlags()
|
||||
{
|
||||
TestMissionType();
|
||||
TestLevelPositionType();
|
||||
TestAlignmentType();
|
||||
}
|
||||
|
||||
private static void TestMissionType()
|
||||
{
|
||||
const MissionType beacon = MissionType.Beacon;
|
||||
beacon.HasFlag(MissionType.Cargo).Should().BeFalse();
|
||||
beacon.HasAnyFlag(MissionType.Cargo).Should().BeFalse();
|
||||
|
||||
beacon.HasFlag(MissionType.Beacon).Should().BeTrue();
|
||||
beacon.HasAnyFlag(MissionType.Beacon).Should().BeTrue();
|
||||
|
||||
const MissionType beaconOrCargo = MissionType.Beacon | MissionType.Cargo;
|
||||
beaconOrCargo.HasFlag(MissionType.Monster).Should().BeFalse();
|
||||
beaconOrCargo.HasAnyFlag(MissionType.Monster).Should().BeFalse();
|
||||
MissionType testEnum = MissionType.Beacon;
|
||||
testEnum.HasFlag(MissionType.Cargo).Should().BeFalse();
|
||||
testEnum.HasAnyFlag(MissionType.Cargo).Should().BeFalse();
|
||||
|
||||
beaconOrCargo.HasFlag(MissionType.Beacon).Should().BeTrue();
|
||||
beaconOrCargo.HasAnyFlag(MissionType.Beacon).Should().BeTrue();
|
||||
testEnum.HasFlag(MissionType.Beacon).Should().BeTrue();
|
||||
testEnum.HasAnyFlag(MissionType.Beacon).Should().BeTrue();
|
||||
|
||||
beaconOrCargo.HasFlag(MissionType.Cargo).Should().BeTrue();
|
||||
beaconOrCargo.HasAnyFlag(MissionType.Cargo).Should().BeTrue();
|
||||
|
||||
const MissionType all = MissionType.All;
|
||||
all.HasFlag(MissionType.All).Should().BeTrue();
|
||||
all.HasAnyFlag(MissionType.All).Should().BeTrue();
|
||||
|
||||
all.HasFlag(MissionType.Beacon).Should().BeTrue();
|
||||
all.HasAnyFlag(MissionType.Beacon).Should().BeTrue();
|
||||
|
||||
all.HasFlag(MissionType.Beacon | MissionType.Salvage).Should().BeTrue();
|
||||
all.HasAnyFlag(MissionType.Beacon | MissionType.Salvage).Should().BeTrue();
|
||||
|
||||
const MissionType manyTypes = MissionType.Beacon | MissionType.Monster;
|
||||
beaconOrCargo.HasFlag(manyTypes).Should().BeFalse();
|
||||
beaconOrCargo.HasAnyFlag(manyTypes).Should().BeTrue();
|
||||
|
||||
beaconOrCargo.HasFlag(MissionType.All).Should().BeFalse();
|
||||
beaconOrCargo.HasAnyFlag(MissionType.All).Should().BeTrue();
|
||||
}
|
||||
|
||||
private static void TestLevelPositionType()
|
||||
{
|
||||
Level.PositionType abyss = Level.PositionType.Abyss;
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Barotrauma;
|
||||
using Barotrauma.Items.Components;
|
||||
extern alias Client;
|
||||
using Client::Barotrauma.Items.Components;
|
||||
using FluentAssertions;
|
||||
using FsCheck;
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#nullable enable
|
||||
|
||||
extern alias Client;
|
||||
using System;
|
||||
using Xunit;
|
||||
using Barotrauma;
|
||||
@@ -7,6 +8,8 @@ using FluentAssertions;
|
||||
using FsCheck;
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
using ToolBox = Client::Barotrauma.ToolBox;
|
||||
|
||||
namespace TestProject;
|
||||
|
||||
public sealed class GenericToolBoxTests
|
||||
@@ -38,6 +41,7 @@ public sealed class GenericToolBoxTests
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public GenericToolBoxTests()
|
||||
{
|
||||
Arb.Register<TestProject.CustomGenerators>();
|
||||
@@ -66,13 +70,13 @@ public sealed class GenericToolBoxTests
|
||||
|
||||
// Should be the bottom right corner of the rectangle
|
||||
Test(rect1, point1, expectedClosest: new Vector2(5, 5));
|
||||
|
||||
|
||||
RectangleF rect2 = new(0, 0, 5, 5);
|
||||
Vector2 point2 = new(2, 10);
|
||||
|
||||
// Should be the bottom edge of the rectangle at x = 2 since the point is between the bottom left and bottom right corners
|
||||
Test(rect2, point2, expectedClosest: new Vector2(2, 5));
|
||||
|
||||
|
||||
RectangleF rect3 = new(0, 0, 5, 5);
|
||||
Vector2 point3 = new(-10, -3);
|
||||
|
||||
@@ -84,7 +88,7 @@ public sealed class GenericToolBoxTests
|
||||
|
||||
// Should be the point itself since it's inside the rectangle
|
||||
Test(rect4, point4, expectedClosest: point4);
|
||||
|
||||
|
||||
RectangleF rect5 = new(0, 0, 100, 100);
|
||||
Vector2 point5 = new(55, 102);
|
||||
|
||||
@@ -97,4 +101,46 @@ public sealed class GenericToolBoxTests
|
||||
closest.Should().BeEquivalentTo(expectedClosest);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NoHashCollisionsOnRandomStrings()
|
||||
{
|
||||
Prop.ForAll<DifferentIdentifierPair>(static pair =>
|
||||
{
|
||||
int int1 = ToolBox.StringToInt(pair.First.Value);
|
||||
int int2 = ToolBox.StringToInt(pair.Second.Value);
|
||||
|
||||
(int1 != int2).Should().BeTrue("Different strings should generate a different integer hash.");
|
||||
}).VerboseCheckThrowOnFailure();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NoHashCollisionsOnLongStrings()
|
||||
{
|
||||
string longString = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
|
||||
(ToolBox.StringToInt(longString) != ToolBox.StringToInt(longString + "a")).Should().BeTrue("Different strings should generate a different integer hash.");
|
||||
(ToolBox.StringToInt(longString) != ToolBox.StringToInt("a" + longString)).Should().BeTrue("Different strings should generate a different integer hash.");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ConsistentHashes()
|
||||
{
|
||||
Prop.ForAll<DifferentIdentifierPair>(static pair =>
|
||||
{
|
||||
int int1 = ToolBox.StringToInt(pair.First.Value);
|
||||
int int2 = ToolBox.StringToInt(pair.Second.Value);
|
||||
|
||||
(int1 == ToolBox.StringToInt(pair.First.Value)).Should().BeTrue($"Inconsistent result from {ToolBox.StringToInt}: same string generated a different integer hash.");
|
||||
(int2 == ToolBox.StringToInt(pair.Second.Value)).Should().BeTrue($"Inconsistent result from {ToolBox.StringToInt}: same string generated a different integer hash.");
|
||||
}).VerboseCheckThrowOnFailure();
|
||||
|
||||
string str1 = "2349r8hasfekjnasgjdf";
|
||||
(ToolBox.StringToInt(str1) == 612306457).Should().BeTrue($"The integer hash of a the string {str1} does not match the expected value. This may not be an issue if the hashing algorithm has been intentionally changed.");
|
||||
|
||||
string str2 = "";
|
||||
(ToolBox.StringToInt(str2) == 757602046).Should().BeTrue($"The integer hash of a the string {str2} does not match the expected value. This may not be an issue if the hashing algorithm has been intentionally changed.");
|
||||
|
||||
string str3 = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
|
||||
(ToolBox.StringToInt(str3) == -587425788).Should().BeTrue($"The integer hash of a the string {str3} does not match the expected value. This may not be an issue if the hashing algorithm has been intentionally changed.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
using System;
|
||||
extern alias Client;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Barotrauma;
|
||||
using Barotrauma.Extensions;
|
||||
using Client::Barotrauma;
|
||||
using Client::Barotrauma.Extensions;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Xunit;
|
||||
|
||||
|
||||
@@ -1,16 +1,24 @@
|
||||
#nullable enable
|
||||
|
||||
extern alias Client;
|
||||
using System;
|
||||
using System.Collections.Immutable;
|
||||
using Barotrauma;
|
||||
using Barotrauma.Networking;
|
||||
using FluentAssertions;
|
||||
using FsCheck;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Xunit;
|
||||
|
||||
using NetworkSerialize = Client::Barotrauma.NetworkSerialize;
|
||||
using INetSerializableStruct = Client::Barotrauma.INetSerializableStruct;
|
||||
using ReadWriteMessage = Client::Barotrauma.Networking.ReadWriteMessage;
|
||||
using ReadOnlyBitField = Client::Barotrauma.ReadOnlyBitField;
|
||||
using WriteOnlyBitField = Client::Barotrauma.WriteOnlyBitField;
|
||||
|
||||
namespace TestProject
|
||||
{
|
||||
extern alias Server;
|
||||
|
||||
// ReSharper disable UnusedMember.Local NotAccessedField.Local UnusedMember.Global
|
||||
public sealed class INetSerializableStructTests
|
||||
{
|
||||
@@ -199,7 +207,7 @@ namespace TestProject
|
||||
|
||||
private struct TestRangedStruct : INetSerializableStruct
|
||||
{
|
||||
[NetworkSerialize(MinValueInt = -100, MaxValueInt = 100)]
|
||||
[Client::Barotrauma.NetworkSerialize(MinValueInt = -100, MaxValueInt = 100)]
|
||||
public int IntValue;
|
||||
|
||||
[NetworkSerialize(MinValueFloat = -100, MaxValueFloat = 100, NumberOfBits = 16)]
|
||||
@@ -236,13 +244,13 @@ namespace TestProject
|
||||
private static void SerializeDeserializeRanged(int intValue, float floatValue)
|
||||
{
|
||||
ReadWriteMessage msg = new ReadWriteMessage();
|
||||
TestRangedStruct writeStruct = new TestRangedStruct
|
||||
INetSerializableStruct writeStruct = new TestRangedStruct
|
||||
{
|
||||
IntValue = intValue,
|
||||
FloatValue = floatValue
|
||||
};
|
||||
|
||||
msg.WriteNetSerializableStruct(writeStruct);
|
||||
writeStruct.Write(msg);
|
||||
msg.BitPosition = 0;
|
||||
|
||||
TestRangedStruct readStruct = INetSerializableStruct.Read<TestRangedStruct>(msg);
|
||||
@@ -255,7 +263,7 @@ namespace TestProject
|
||||
{
|
||||
ReadWriteMessage msg = new ReadWriteMessage();
|
||||
|
||||
msg.WriteNetSerializableStruct(toWrite);
|
||||
toWrite.Write(msg);
|
||||
msg.BitPosition = 0;
|
||||
|
||||
T read = INetSerializableStruct.Read<T>(msg);
|
||||
@@ -283,19 +291,21 @@ namespace TestProject
|
||||
private static void SerializeDeserializeNullableTuple<T, U>(T arg1, U arg2)
|
||||
{
|
||||
ReadWriteMessage msg = new ReadWriteMessage();
|
||||
TupleNullableStruct<T, U> writeStruct = new TupleNullableStruct<T, U>
|
||||
INetSerializableStruct writeStruct = new TupleNullableStruct<T, U>
|
||||
{
|
||||
One = arg1,
|
||||
Two = arg2
|
||||
};
|
||||
|
||||
msg.WriteNetSerializableStruct(writeStruct);
|
||||
writeStruct.Write(msg);
|
||||
msg.BitPosition = 0;
|
||||
|
||||
TupleNullableStruct<T, U> readStruct = INetSerializableStruct.Read<TupleNullableStruct<T, U>>(msg);
|
||||
|
||||
readStruct.Should().BeEquivalentTo(writeStruct, options => options
|
||||
.ComparingByMembers<TupleNullableStruct<T, U>>()
|
||||
.RespectingRuntimeTypes()
|
||||
.ComparingByMembers<string>()
|
||||
.ComparingByMembers(typeof(Option<>)));
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,8 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\BarotraumaClient\LinuxClient.csproj" />
|
||||
<ProjectReference Include="..\BarotraumaClient\LinuxClient.csproj" Aliases="Client" />
|
||||
<ProjectReference Include="..\BarotraumaServer\LinuxServer.csproj" Aliases="Server"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -25,7 +25,8 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\BarotraumaClient\MacClient.csproj" />
|
||||
<ProjectReference Include="..\BarotraumaClient\MacClient.csproj" Aliases="Client" />
|
||||
<ProjectReference Include="..\BarotraumaServer\MacServer.csproj" Aliases="Server"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -62,6 +62,62 @@ public class MathUtilsTests
|
||||
{
|
||||
return MathUtils.NearlyEqual(MathUtils.GetShortestAngle(MathHelper.ToRadians(deg1), MathHelper.ToRadians(deg2)), MathHelper.ToRadians(angle));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestUpscaleVector2Array()
|
||||
{
|
||||
Vector2[,] inputArray = new Vector2[,]
|
||||
{
|
||||
{ new Vector2(0, 0), new Vector2(10, 10) },
|
||||
{ new Vector2(20, 20), new Vector2(30, 30) }
|
||||
};
|
||||
|
||||
int newWidth = 4;
|
||||
int newHeight = 4;
|
||||
|
||||
Vector2[,] result = MathUtils.ResizeVector2Array(inputArray, newWidth, newHeight);
|
||||
|
||||
MathUtils.NearlyEqual(new Vector2(0, 0), result[0, 0]).Should().BeTrue();
|
||||
MathUtils.NearlyEqual(new Vector2(30, 30), result[3, 3]).Should().BeTrue();
|
||||
MathUtils.NearlyEqual(new Vector2(20, 20), result[2, 2]).Should().BeTrue();
|
||||
MathUtils.NearlyEqual(new Vector2(26.666666f, 26.666666f), result[3, 2]).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestDownScaleVector2Array()
|
||||
{
|
||||
Vector2[,] inputArray = new Vector2[,]
|
||||
{
|
||||
{ new Vector2(0, 0), new Vector2(10, 10), new Vector2(20, 20) },
|
||||
{ new Vector2(30, 30), new Vector2(40, 40), new Vector2(50, 50) },
|
||||
{ new Vector2(60, 60), new Vector2(70, 70), new Vector2(80, 80) }
|
||||
};
|
||||
|
||||
int newWidth = 2;
|
||||
int newHeight = 2;
|
||||
|
||||
Vector2[,] result = MathUtils.ResizeVector2Array(inputArray, newWidth, newHeight);
|
||||
|
||||
MathUtils.NearlyEqual(new Vector2(0, 0), result[0, 0]).Should().BeTrue();
|
||||
MathUtils.NearlyEqual(new Vector2(80, 80), result[1, 1]).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestNoChangesToVector2Array()
|
||||
{
|
||||
Vector2[,] inputArray = new Vector2[,]
|
||||
{
|
||||
{ new Vector2(0, 0), new Vector2(10, 10) },
|
||||
{ new Vector2(20, 20), new Vector2(30, 30) }
|
||||
};
|
||||
|
||||
int newWidth = 2;
|
||||
int newHeight = 2;
|
||||
|
||||
Vector2[,] result = MathUtils.ResizeVector2Array(inputArray, newWidth, newHeight);
|
||||
|
||||
MathUtils.NearlyEqual(new Vector2(0, 0), result[0, 0]).Should().BeTrue();
|
||||
MathUtils.NearlyEqual(new Vector2(30, 30), result[1, 1]).Should().BeTrue();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
using System;
|
||||
using Barotrauma.Networking;
|
||||
using FluentAssertions;
|
||||
extern alias Client;
|
||||
using System;
|
||||
using Client::Barotrauma.Networking;
|
||||
using FsCheck;
|
||||
using Xunit;
|
||||
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
using Barotrauma;
|
||||
extern alias Client;
|
||||
using Client::Barotrauma;
|
||||
using FluentAssertions;
|
||||
using FsCheck;
|
||||
using System;
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace TestProject;
|
||||
|
||||
public sealed class PropertyConditionalTests
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using Barotrauma;
|
||||
extern alias Client;
|
||||
using System;
|
||||
using Client::Barotrauma;
|
||||
using FluentAssertions;
|
||||
using FsCheck;
|
||||
using Xunit;
|
||||
|
||||
@@ -25,7 +25,8 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\BarotraumaClient\WindowsClient.csproj" />
|
||||
<ProjectReference Include="..\BarotraumaClient\WindowsClient.csproj" Aliases="Client" />
|
||||
<ProjectReference Include="..\BarotraumaServer\WindowsServer.csproj" Aliases="Server"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user