From 256a72db8892318b68cb2e97bd1cbf221ce8afbe Mon Sep 17 00:00:00 2001 From: Asriel Camora Date: Tue, 31 Oct 2023 15:41:09 -0700 Subject: [PATCH] Add more actionset tests --- .github/workflows/build.yml | 4 ++-- Craftimizer.Test/Solver/ActionSet.cs | 36 +++++++++++++++++++++++++--- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2a5f9e7..848adc5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -36,11 +36,11 @@ jobs: - name: Build run: | - dotnet build --configuration Release + dotnet build --configuration Release --no-restore - name: Test run: | - dotnet test --configuration Release --logger "trx;logfilename=results.trx" --logger "html;logfilename=results.html" --logger "console;verbosity=detailed" --results-directory="TestResults" + dotnet test --configuration Release --logger "trx;logfilename=results.trx" --logger "html;logfilename=results.html" --logger "console;verbosity=detailed" --no-build --results-directory="TestResults" - name: Upload Artifacts uses: actions/upload-artifact@v3 diff --git a/Craftimizer.Test/Solver/ActionSet.cs b/Craftimizer.Test/Solver/ActionSet.cs index d76f372..87a00ee 100644 --- a/Craftimizer.Test/Solver/ActionSet.cs +++ b/Craftimizer.Test/Solver/ActionSet.cs @@ -12,7 +12,7 @@ public class ActionSetTests var lut = Craftimizer.Solver.Simulator.AcceptedActionsLUT; Assert.IsTrue(actions.Length <= 32); - foreach(var i in Enum.GetValues()) + foreach (var i in Enum.GetValues()) { var idx = lut[(byte)i]; if (idx != 0) @@ -29,7 +29,7 @@ public class ActionSetTests set.AddAction(ActionType.BasicSynthesis); set.AddAction(ActionType.WasteNot2); - + Assert.AreEqual(2, set.Count); Assert.IsFalse(set.IsEmpty); @@ -50,7 +50,7 @@ public class ActionSetTests Assert.IsTrue(set.RemoveAction(ActionType.BasicSynthesis)); Assert.IsFalse(set.RemoveAction(ActionType.BasicSynthesis)); - + Assert.IsTrue(set.AddAction(ActionType.BasicSynthesis)); Assert.IsTrue(set.AddAction(ActionType.WasteNot2)); @@ -101,4 +101,34 @@ public class ActionSetTests Assert.AreEqual(ActionType.ByregotsBlessing, set.ElementAt(1)); Assert.AreEqual(ActionType.BasicSynthesis, set.ElementAt(2)); } + + [TestMethod] + public void TestRandomIndex() + { + var actions = new[] + { + ActionType.BasicTouch, + ActionType.BasicSynthesis, + ActionType.GreatStrides, + ActionType.TrainedFinesse, + }; + + var set = new ActionSet(); + foreach(var action in actions) + set.AddAction(action); + + var counts = new Dictionary(); + var rng = new Random(0); + for (var i = 0; i < 100; i++) + { + var action = set.SelectRandom(rng); + + Assert.IsTrue(actions.Contains(action)); + + counts[action] = counts.GetValueOrDefault(action) + 1; + } + + foreach (var action in actions) + Assert.IsTrue(counts.GetValueOrDefault(action) > 0); + } }