Skip to content

Commit

Permalink
Merge pull request #12 from AnnulusGames/add-tests
Browse files Browse the repository at this point in the history
Add: WeightedListTests
  • Loading branch information
AnnulusGames authored Aug 20, 2024
2 parents c922652 + 6829ec1 commit fcb2eac
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/RandomExtensions/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("RandomExtensions.Tests")]
2 changes: 2 additions & 0 deletions src/RandomExtensions/Collections/WeightedList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public WeightedList()
readonly List<WeightedValue<T>> list;
readonly ValueCollection values;

internal double TotalWeight => totalWeight;

public WeightedValue<T> this[int index]
{
get => list[index];
Expand Down
38 changes: 38 additions & 0 deletions tests/RandomExtensions.Tests/WeightedListTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,44 @@ namespace RandomExtensions.Tests;

public class WeightedListTests
{
[Test]
public void Test_Add()
{
var list = new WeightedList<int>();

list.Add(0, 1);
Assert.That(list.Count, Is.EqualTo(1));
Assert.That(list[0].Value, Is.EqualTo(0));
Assert.That(list.TotalWeight, Is.EqualTo(1));

list.Add(1, 2);
Assert.That(list.Count, Is.EqualTo(2));
Assert.That(list[1].Value, Is.EqualTo(1));
Assert.That(list.TotalWeight, Is.EqualTo(3));
}

[Test]
public void Test_Remove()
{
var list = new WeightedList<int>
{
{ 0, 1 },
{ 1, 1 },
{ 2, 1 },
{ 3, 1 },
};

Assert.That(list.TotalWeight, Is.EqualTo(4));
list.RemoveAt(0);
Assert.That(list.TotalWeight, Is.EqualTo(3));
list.RemoveAt(0);
Assert.That(list.TotalWeight, Is.EqualTo(2));
list.RemoveAt(0);
Assert.That(list.TotalWeight, Is.EqualTo(1));
list.RemoveAt(0);
Assert.That(list.TotalWeight, Is.EqualTo(0));
}

[Test]
public void Test_RemoveRandom()
{
Expand Down

0 comments on commit fcb2eac

Please sign in to comment.