Merge remote-tracking branch 'upstream/master' into develop
This commit is contained in:
@@ -0,0 +1,111 @@
|
||||
using Barotrauma;
|
||||
using FluentAssertions;
|
||||
using Barotrauma.Extensions;
|
||||
using FluentAssertions;
|
||||
using Xunit;
|
||||
|
||||
namespace TestProject;
|
||||
|
||||
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;
|
||||
abyss.HasFlag(Level.PositionType.Ruin).Should().BeFalse();
|
||||
abyss.HasAnyFlag(Level.PositionType.Ruin).Should().BeFalse();
|
||||
|
||||
abyss.HasFlag(Level.PositionType.Abyss).Should().BeTrue();
|
||||
abyss.HasAnyFlag(Level.PositionType.Abyss).Should().BeTrue();
|
||||
|
||||
abyss = Level.PositionType.Abyss | Level.PositionType.Ruin;
|
||||
abyss.HasFlag(Level.PositionType.Cave).Should().BeFalse();
|
||||
abyss.HasAnyFlag(Level.PositionType.Cave).Should().BeFalse();
|
||||
|
||||
abyss.HasFlag(Level.PositionType.Abyss).Should().BeTrue();
|
||||
abyss.HasAnyFlag(Level.PositionType.Abyss).Should().BeTrue();
|
||||
|
||||
abyss.HasFlag(Level.PositionType.Ruin).Should().BeTrue();
|
||||
abyss.HasAnyFlag(Level.PositionType.Ruin).Should().BeTrue();
|
||||
|
||||
const Level.PositionType abyssOrOutpost = Level.PositionType.Abyss | Level.PositionType.Outpost;
|
||||
abyss.HasFlag(abyssOrOutpost).Should().BeFalse();
|
||||
abyss.HasAnyFlag(abyssOrOutpost).Should().BeTrue();
|
||||
|
||||
(Level.PositionType.Abyss.AddFlag(Level.PositionType.Outpost) == abyssOrOutpost).Should().BeTrue();
|
||||
(abyssOrOutpost.RemoveFlag(Level.PositionType.Outpost) == Level.PositionType.Abyss).Should().BeTrue();
|
||||
}
|
||||
|
||||
private static void TestAlignmentType()
|
||||
{
|
||||
const Alignment left = Alignment.Left;
|
||||
left.HasFlag(Alignment.Left).Should().BeTrue();
|
||||
left.HasAnyFlag(Alignment.Left).Should().BeTrue();
|
||||
|
||||
left.HasFlag(Alignment.Center).Should().BeFalse();
|
||||
left.HasAnyFlag(Alignment.Center).Should().BeFalse();
|
||||
|
||||
left.HasFlag(Alignment.TopLeft).Should().BeFalse();
|
||||
left.HasAnyFlag(Alignment.TopLeft).Should().BeTrue();
|
||||
|
||||
const Alignment leftOrCenter = Alignment.Left | Alignment.Center;
|
||||
left.HasFlag(leftOrCenter).Should().BeFalse();
|
||||
left.HasAnyFlag(leftOrCenter).Should().BeTrue();
|
||||
|
||||
const Alignment topLeft = Alignment.TopLeft;
|
||||
topLeft.HasFlag(left).Should().BeTrue();
|
||||
topLeft.HasAnyFlag(left).Should().BeTrue();
|
||||
|
||||
topLeft.HasFlag(leftOrCenter).Should().BeFalse();
|
||||
topLeft.HasAnyFlag(leftOrCenter).Should().BeTrue();
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ using Xunit;
|
||||
using Barotrauma;
|
||||
using FluentAssertions;
|
||||
using FsCheck;
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
namespace TestProject;
|
||||
|
||||
@@ -56,4 +57,44 @@ public sealed class GenericToolBoxTests
|
||||
ToolBox.StatIdentifierMatches(pair.First, pair.Second).Should().BeFalse();
|
||||
}).VerboseCheckThrowOnFailure();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PointOnRectClosestToPoint()
|
||||
{
|
||||
RectangleF rect1 = new(0, 0, 5, 5);
|
||||
Vector2 point1 = new(10, 10);
|
||||
|
||||
// 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);
|
||||
|
||||
// Should be the top left corner of the rectangle
|
||||
Test(rect3, point3, expectedClosest: new Vector2(0, 0));
|
||||
|
||||
RectangleF rect4 = new(0, 0, 100, 100);
|
||||
Vector2 point4 = new(55, 52);
|
||||
|
||||
// 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);
|
||||
|
||||
// Should be the top edge of the rectangle at y = 100 since the point is between the top left and top right corners
|
||||
Test(rect5, point5, expectedClosest: new Vector2(55, 100));
|
||||
|
||||
void Test(RectangleF rect, Vector2 point, Vector2 expectedClosest)
|
||||
{
|
||||
var closest = ToolBox.GetClosestPointOnRectangle(rect, point);
|
||||
closest.Should().BeEquivalentTo(expectedClosest);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user