Replace Location table with packed 64-bit int (#679)

* Replace Location table with packed 64 bit int

* Remove double Include and fix Slot documentation

* Fix compilation errors from merge

* Fix namespaces and add expected values to unit tests
This commit is contained in:
Josh 2023-02-21 14:53:38 -06:00 committed by GitHub
commit 35ea2682b9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
30 changed files with 996 additions and 930 deletions

View file

@ -0,0 +1,81 @@
using System.IO;
using System.Xml.Serialization;
using LBPUnion.ProjectLighthouse.Types.Entities.Level;
using LBPUnion.ProjectLighthouse.Types.Entities.Profile;
using LBPUnion.ProjectLighthouse.Types.Misc;
using Xunit;
namespace LBPUnion.ProjectLighthouse.Tests;
public class LocationTests
{
[Fact]
public void ShouldSetAndReadUserLocation()
{
Location expected = new()
{
X = 1000,
Y = 5000,
};
User user = new()
{
Location = new Location
{
X = expected.X,
Y = expected.Y,
},
};
Assert.True(user.Location.X == expected.X);
Assert.True(user.Location.Y == expected.Y);
Assert.True(user.LocationPacked == 4_294_967_301_000);
}
[Fact]
public void ShouldSetAndReadSlotLocation()
{
Location expected = new()
{
X = 1000,
Y = 5000,
};
Slot slot = new()
{
Location = new Location
{
X = expected.X,
Y = expected.Y,
},
};
Assert.True(slot.Location.X == expected.X);
Assert.True(slot.Location.Y == expected.Y);
Assert.True(slot.LocationPacked == 4_294_967_301_000);
}
[Fact]
public void ShouldReadLocationAfterDeserialization()
{
XmlSerializer deserializer = new(typeof(Slot));
const string slotData = "<slot><name>test</name><resource>test</resource><location><x>4000</x><y>9000</y></location></slot>";
Slot? deserialized = (Slot?)deserializer.Deserialize(new StringReader(slotData));
Assert.True(deserialized != null);
Assert.True(deserialized.Name == "test");
Assert.True(deserialized.Location.X == 4000);
Assert.True(deserialized.Location.Y == 9000);
Assert.True(deserialized.LocationPacked == 17_179_869_193_000);
}
[Fact]
public void ShouldDeserializeEmptyLocation()
{
XmlSerializer deserializer = new(typeof(Slot));
const string slotData = "<slot><name>test</name></slot>";
Slot? deserialized = (Slot?)deserializer.Deserialize(new StringReader(slotData));
Assert.True(deserialized != null);
Assert.True(deserialized.Name == "test");
Assert.True(deserialized.Location.X == 0);
Assert.True(deserialized.Location.Y == 0);
Assert.True(deserialized.LocationPacked == 0);
}
}