ModernUO/Projects/Server.Tests/Tests/Collections/OrderedHashSetTests.cs
Kamron Batman 995149ad01
fix(core): Adds ability to store null value in ordered hash set (#447)
- [X] Adds the ability to store a null value in an ordered hash set

TODO:
Optimized the OrderedHashSet. See this:
* https://github.com/dotnet/runtime/issues/10050
Looks like the OrderedDictionary that I based this structure from was not updated.
See the source for diffing:
https://github.com/dotnet/runtime/blob/master/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/HashSet.cs

Difference between a HashSet and an OrderedHashSet is updating the indexes of the entries after fixing the chain to preserve insertion order.
2021-02-03 17:57:03 -08:00

46 lines
1.3 KiB
C#

using System.Linq;
using Server.Collections;
using Xunit;
namespace Server.Tests
{
public class OrderedHashSetTests
{
[Fact]
public void TestOrderedHashSet()
{
var set = new OrderedHashSet<string>(1)
{
"random string1", "another random string1", "another random string2", "another random string3"
};
set.Remove("another random string1");
var list = set.ToList();
string[] arr = { "random string1", "another random string2", "another random string3" };
int i = 0;
foreach (var entry in list)
{
Assert.Equal(entry, arr[i++]);
}
}
[Fact]
public void TestOrderedHashWithNull()
{
var set = new OrderedHashSet<string>(1)
{
"random string1", null, "another random string2", "another random string3"
};
set.Remove("another random string1");
var list = set.ToList();
string[] arr = { "random string1", null, "another random string2", "another random string3" };
int i = 0;
foreach (var entry in list)
{
Assert.Equal(entry, arr[i++]);
}
}
}
}