From 237d435526b5d565247f5b66c6cb4ba45332f82e Mon Sep 17 00:00:00 2001 From: Vishnu Bhagyanath Date: Wed, 18 Dec 2024 10:42:02 +0530 Subject: [PATCH] fix: cleanup after RandomTest (#45) --- Rudim.Test/UnitTest/Board/TraversalTest.cs | 8 ++++---- Rudim.Test/UnitTest/Common/RandomTest.cs | 13 ++++++++----- Rudim/Common/Random.cs | 7 +++++++ 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/Rudim.Test/UnitTest/Board/TraversalTest.cs b/Rudim.Test/UnitTest/Board/TraversalTest.cs index c1312e6..8efffd4 100644 --- a/Rudim.Test/UnitTest/Board/TraversalTest.cs +++ b/Rudim.Test/UnitTest/Board/TraversalTest.cs @@ -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(); diff --git a/Rudim.Test/UnitTest/Common/RandomTest.cs b/Rudim.Test/UnitTest/Common/RandomTest.cs index 0e60366..8d6653d 100644 --- a/Rudim.Test/UnitTest/Common/RandomTest.cs +++ b/Rudim.Test/UnitTest/Common/RandomTest.cs @@ -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() @@ -30,5 +28,10 @@ public void ShouldGenerateUniqueIntNumbers() Assert.True(generatedNumbers.Add(number), $"Collision detected for int number: {number}"); } } + + public void Dispose() + { + Random._RESET_SEED(); + } } } \ No newline at end of file diff --git a/Rudim/Common/Random.cs b/Rudim/Common/Random.cs index eae3135..b4b4580 100644 --- a/Rudim/Common/Random.cs +++ b/Rudim/Common/Random.cs @@ -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; + } } } \ No newline at end of file