Skip to content

Commit

Permalink
fix: cleanup after RandomTest (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
znxftw authored Dec 18, 2024
1 parent 5eb7082 commit 237d435
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
8 changes: 4 additions & 4 deletions Rudim.Test/UnitTest/Board/TraversalTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ public class TraversalTest
// This helps keep track if certain optimizations are good enough to make up for the extra time spent
// Compare time spent with and without the change before updating the keys
[Theory]
[InlineData(Helpers.StartingFEN, 1792286, 5, 8)]
[InlineData(Helpers.EndgameFEN, 415340, 45, 9)]
[InlineData(Helpers.AdvancedMoveFEN, 2677577, 1520, 8)]
[InlineData(Helpers.KiwiPeteFEN, 6761199, -60, 8)]
[InlineData(Helpers.StartingFEN, 1787870, 5, 8)]
[InlineData(Helpers.EndgameFEN, 420262, 45, 9)]
[InlineData(Helpers.AdvancedMoveFEN, 2649058, 1520, 8)]
[InlineData(Helpers.KiwiPeteFEN, 6764976, -60, 8)]
public void ShouldTraverseDeterministically(string position, int expectedNodes, int expectedScore, int depth)
{
Global.Reset();
Expand Down
13 changes: 8 additions & 5 deletions Rudim.Test/UnitTest/Common/RandomTest.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
using Rudim.Common;
using System;
using System.Collections.Generic;
using Xunit;
using Random = Rudim.Common.Random;

namespace Rudim.Test.UnitTest.Common
{
// This test being run before other tests causes a different expected output.
// Currently this is not a problem, just that this test always needs to be run, or values in
// Traversal Test will need to be changed.
public class RandomTest
public class RandomTest : IDisposable
{
[Fact]
public void ShouldGenerateUniqueULongNumbers()
Expand All @@ -30,5 +28,10 @@ public void ShouldGenerateUniqueIntNumbers()
Assert.True(generatedNumbers.Add(number), $"Collision detected for int number: {number}");
}
}

public void Dispose()
{
Random._RESET_SEED();
}
}
}
7 changes: 7 additions & 0 deletions Rudim/Common/Random.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,12 @@ public static int NextInt()
randomNumber ^= randomNumber << 5;
return _intState = randomNumber;
}

// DO NOT USE FOR PROJECT - ONLY USED IN RandomTest.cs for determinism
public static void _RESET_SEED()
{
_ulongState = 1804289383;
_intState = 1804289383;
}
}
}

0 comments on commit 237d435

Please sign in to comment.