Skip to content

Commit

Permalink
Add more actionset tests
Browse files Browse the repository at this point in the history
  • Loading branch information
WorkingRobot committed Oct 31, 2023
1 parent a9c9f34 commit 5e95d8b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 33 additions & 3 deletions Craftimizer.Test/Solver/ActionSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public void TestAcceptedActions()
var lut = Craftimizer.Solver.Simulator.AcceptedActionsLUT;

Assert.IsTrue(actions.Length <= 32);
foreach(var i in Enum.GetValues<ActionType>())
foreach (var i in Enum.GetValues<ActionType>())
{
var idx = lut[(byte)i];
if (idx != 0)
Expand All @@ -29,7 +29,7 @@ public void TestSize()

set.AddAction(ActionType.BasicSynthesis);
set.AddAction(ActionType.WasteNot2);

Assert.AreEqual(2, set.Count);
Assert.IsFalse(set.IsEmpty);

Expand All @@ -50,7 +50,7 @@ public void TestAddRemove()

Assert.IsTrue(set.RemoveAction(ActionType.BasicSynthesis));
Assert.IsFalse(set.RemoveAction(ActionType.BasicSynthesis));

Assert.IsTrue(set.AddAction(ActionType.BasicSynthesis));
Assert.IsTrue(set.AddAction(ActionType.WasteNot2));

Expand Down Expand Up @@ -101,4 +101,34 @@ public void TestElementAt()
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<ActionType, int>();
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);
}
}

0 comments on commit 5e95d8b

Please sign in to comment.