mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-06 17:58:05 +02:00
* Move to Central Package Management. Allows us to store NuGet package versions all in one place. Yay! * Update NuGet packages and fix code for changes. Notable: Changes to ILVerify. Npgsql doesn't need hacks for inet anymore, now we need hacks to make the old code work with this new reality. NUnit's analyzers are already complaining and I didn't even update it to 4.x yet. TerraFX changed to GetLastSystemError so error handling had to be changed. Buncha APIs have more NRT annotations. * Remove dotnet-eng NuGet package source. I genuinely don't know what this was for, and Central Package Management starts throwing warnings about it, so YEET. * Fix double loading of assemblies due to ALC shenanigans. Due to how the "sideloading" code for the ModLoader was set up, it would first try to load Microsoft.Extensions.Primitives from next to the content dll. But we already have that library in Robust! Chaos ensues. We now try to forcibly prioritize loading from the default ALC first to avoid this. * Remove Robust.Physics project. Never used. * Remove erroneous NVorbis reference. Should be VorbisPizza and otherwise wasn't used. * Sandbox fixes * Remove unused unit test package references. Castle.Core and NUnit.ConsoleRunner. * Update NUnit to 4.0.1 This requires replacing all the old assertion methods because they removed them 🥲 * Mute CA1416 (platform check) errors TerraFX started annotating APIs with this and I can't be arsed to entertain this analyzer so out it goes. * Fine ya cranky, no more CPM for Robust.Client.Injectors * Changelog * Oh so that's what dotnet-eng was used for. Yeah ok that makes sense. * Central package management for remaining 2 robust projects * Ok that was a bad idea let's just use NUnit 3 on the analyzer test project * Oh right forgot to remove this one * Update to a newer version of RemoteExecutor * Disable RemoteExecutor test https://github.com/dotnet/arcade/issues/8483 Yeah this package is not well maintained and clearly we can't rely on it. * Fix immutable list serialization
235 lines
7.5 KiB
C#
235 lines
7.5 KiB
C#
using System;
|
|
using System.Linq;
|
|
using System.Numerics;
|
|
using NUnit.Framework;
|
|
using Robust.Shared.Maths;
|
|
using Robust.Shared.Physics;
|
|
|
|
namespace Robust.UnitTesting.Shared.Physics
|
|
{
|
|
|
|
[TestFixture]
|
|
[TestOf(typeof(DynamicTree<>))]
|
|
public sealed class DynamicTree_Test
|
|
{
|
|
|
|
private static Box2[] aabbs1 =
|
|
{
|
|
((Box2) default).Enlarged(1), //2x2 square
|
|
((Box2) default).Enlarged(2), //4x4 square
|
|
new(-3, 3, -3, 3), // point off to the bottom left
|
|
new(-3, -3, -3, -3), // point off to the top left
|
|
new(3, 3, 3, 3), // point off to the bottom right
|
|
new(3, -3, 3, -3), // point off to the top right
|
|
((Box2) default).Enlarged(1), //2x2 square
|
|
((Box2) default).Enlarged(2), //4x4 square
|
|
((Box2) default).Enlarged(1), //2x2 square
|
|
((Box2) default).Enlarged(2), //4x4 square
|
|
((Box2) default).Enlarged(1), //2x2 square
|
|
((Box2) default).Enlarged(2), //4x4 square
|
|
((Box2) default).Enlarged(1), //2x2 square
|
|
((Box2) default).Enlarged(2), //4x4 square
|
|
((Box2) default).Enlarged(3), //6x6 square
|
|
new(-3, 3, -3, 3), // point off to the bottom left
|
|
new(-3, -3, -3, -3), // point off to the top left
|
|
new(3, 3, 3, 3), // point off to the bottom right
|
|
new(3, -3, 3, -3), // point off to the top right
|
|
};
|
|
|
|
private static Box2[] aabbs2 =
|
|
{
|
|
((Box2) default).Enlarged(3), //6x6 square
|
|
((Box2) default).Enlarged(1), //2x2 square
|
|
((Box2) default).Enlarged(2), //4x4 square
|
|
new(-3, 3, -3, 3), // point off to the bottom left
|
|
new(-3, -3, -3, -3), // point off to the top left
|
|
new(3, 3, 3, 3), // point off to the bottom right
|
|
new(3, -3, 3, -3), // point off to the top right
|
|
new(-3, 3, -3, 3), // point off to the bottom left
|
|
new(-3, -3, -3, -3), // point off to the top left
|
|
new(3, 3, 3, 3), // point off to the bottom right
|
|
new(3, -3, 3, -3), // point off to the top right
|
|
new(-3, 3, -3, 3), // point off to the bottom left
|
|
new(-3, -3, -3, -3), // point off to the top left
|
|
new(3, 3, 3, 3), // point off to the bottom right
|
|
new(3, -3, 3, -3), // point off to the top right
|
|
((Box2) default).Enlarged(2), //4x4 square
|
|
((Box2) default).Enlarged(1), //2x2 square
|
|
((Box2) default).Enlarged(2), //4x4 square
|
|
((Box2) default).Enlarged(1), //2x2 square
|
|
};
|
|
|
|
[Test]
|
|
public void AddAndGrow()
|
|
{
|
|
var dt = new DynamicTree<int>((in int x) => aabbs1[x], capacity: 16, growthFunc: x => x += 2);
|
|
|
|
var initCap = dt.Capacity;
|
|
|
|
Assert.That(initCap, Is.EqualTo(16));
|
|
|
|
Assert.Multiple(() =>
|
|
{
|
|
for (var i = 0; i < aabbs1.Length; ++i)
|
|
{
|
|
Assert.That(dt.Add(i), $"Add {i}");
|
|
}
|
|
});
|
|
|
|
Assert.That(dt.Capacity, Is.AtLeast(initCap));
|
|
}
|
|
|
|
[Test]
|
|
public void AddDuplicates()
|
|
{
|
|
var dt = new DynamicTree<int>((in int x) => aabbs1[x], capacity: 16, growthFunc: x => x += 2);
|
|
|
|
Assert.Multiple(() =>
|
|
{
|
|
for (var i = 0; i < aabbs1.Length; ++i)
|
|
{
|
|
Assert.That(dt.Add(i), $"Add {i}");
|
|
}
|
|
});
|
|
|
|
Assert.Multiple(() =>
|
|
{
|
|
for (var i = 0; i < aabbs1.Length; ++i)
|
|
{
|
|
Assert.That(dt.Add(i), Is.False, $"Add Dupe {i}");
|
|
}
|
|
});
|
|
}
|
|
|
|
[Test]
|
|
public void RemoveMissingWhileEmpty()
|
|
{
|
|
var dt = new DynamicTree<int>((in int x) => aabbs1[x], capacity: 16, growthFunc: x => x += 2);
|
|
|
|
Assert.Multiple(() =>
|
|
{
|
|
for (var i = 0; i < aabbs1.Length; ++i)
|
|
{
|
|
Assert.That(dt.Remove(i), Is.False, $"Remove {i}");
|
|
}
|
|
});
|
|
}
|
|
|
|
[Test]
|
|
public void UpdateMissingWhileEmpty()
|
|
{
|
|
var dt = new DynamicTree<int>((in int x) => aabbs1[x], capacity: 16, growthFunc: x => x += 2);
|
|
|
|
Assert.Multiple(() =>
|
|
{
|
|
for (var i = 0; i < aabbs1.Length; ++i)
|
|
{
|
|
Assert.That(dt.Update(i), Is.False, $"Update {i}");
|
|
}
|
|
});
|
|
}
|
|
|
|
[Test]
|
|
public void RemoveMissingNotEmpty()
|
|
{
|
|
var dt = new DynamicTree<int>((in int x) => aabbs1[x], capacity: 16, growthFunc: x => x += 2);
|
|
|
|
Assert.Multiple(() =>
|
|
{
|
|
for (var i = 0; i < aabbs1.Length; ++i)
|
|
{
|
|
Assert.That(dt.Add(i), $"Add {i}");
|
|
}
|
|
});
|
|
|
|
Assert.Multiple(() =>
|
|
{
|
|
for (var i = aabbs1.Length; i < aabbs1.Length + aabbs2.Length; ++i)
|
|
{
|
|
Assert.That(dt.Remove(i), Is.False, $"Remove {i}");
|
|
}
|
|
});
|
|
}
|
|
|
|
[Test]
|
|
public void UpdateMissingNotEmpty()
|
|
{
|
|
var dt = new DynamicTree<int>((in int x) => aabbs1[x], capacity: 16, growthFunc: x => x += 2);
|
|
|
|
Assert.Multiple(() =>
|
|
{
|
|
for (var i = 0; i < aabbs1.Length; ++i)
|
|
{
|
|
Assert.That(dt.Add(i), $"Add {i}");
|
|
}
|
|
});
|
|
|
|
Assert.Multiple(() => {
|
|
for (var i = aabbs1.Length; i < aabbs1.Length + aabbs2.Length; ++i)
|
|
{
|
|
Assert.That(dt.Update(i), Is.False, $"Update {i}");
|
|
}
|
|
});
|
|
}
|
|
|
|
[Test]
|
|
public void AddThenRemove()
|
|
{
|
|
var aabbs = aabbs1;
|
|
var dt = new DynamicTree<int>((in int x) => aabbs[x], capacity: 16, growthFunc: x => x += 2);
|
|
|
|
Assert.Multiple(() =>
|
|
{
|
|
for (var i = 0; i < aabbs.Length; ++i)
|
|
{
|
|
Assert.That(dt.Add(i), $"Add {i}");
|
|
}
|
|
});
|
|
aabbs = aabbs2;
|
|
|
|
Assert.Multiple(() =>
|
|
{
|
|
for (var i = 0; i < aabbs.Length; ++i)
|
|
{
|
|
Assert.That(dt.Remove(i), $"Remove {i}");
|
|
}
|
|
});
|
|
}
|
|
|
|
[Test]
|
|
public void AddAndQuery() {
|
|
var dt = new DynamicTree<int>((in int x) => aabbs1[x], capacity: 16, growthFunc: x => x += 2);
|
|
|
|
Assert.Multiple(() =>
|
|
{
|
|
for (var i = 0; i < aabbs1.Length; ++i)
|
|
{
|
|
Assert.That(dt.Add(i), $"Add {i}");
|
|
}
|
|
});
|
|
|
|
var point = new Vector2(0, 0);
|
|
|
|
var containers = Enumerable.Range(0, aabbs1.Length)
|
|
.Where(x => aabbs1[x].Contains(point))
|
|
.OrderBy(x => x).ToArray();
|
|
|
|
var results = dt.QueryPoint(point)
|
|
.OrderBy(x => x).ToArray();
|
|
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(results.Length, Is.EqualTo(containers.Length), "Length");
|
|
var l = Math.Min(containers.Length, results.Length);
|
|
for (var i = 0; i < l; ++i)
|
|
{
|
|
Assert.That(results[i], Is.EqualTo(containers[i]));
|
|
}
|
|
});
|
|
}
|
|
|
|
// TODO: other Box2, Ray, Point query method tests
|
|
}
|
|
|
|
}
|