Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: cleanup after RandomTest #45

Merged
merged 2 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
}