Add test project
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
|
||||
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
|
||||
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
|
||||
<PackageReference Include="coverlet.collector" Version="3.2.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Simulator\Craftimizer.Simulator.csproj" />
|
||||
<ProjectReference Include="..\Solver\Craftimizer.Solver.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,104 @@
|
||||
using Craftimizer.Simulator.Actions;
|
||||
|
||||
namespace Craftimizer.Test.Solver;
|
||||
|
||||
[TestClass]
|
||||
public class ActionSetTests
|
||||
{
|
||||
[TestMethod]
|
||||
public void TestAcceptedActions()
|
||||
{
|
||||
var actions = Craftimizer.Solver.Simulator.AcceptedActions;
|
||||
var lut = Craftimizer.Solver.Simulator.AcceptedActionsLUT;
|
||||
|
||||
Assert.IsTrue(actions.Length <= 32);
|
||||
foreach(var i in Enum.GetValues<ActionType>())
|
||||
{
|
||||
var idx = lut[(byte)i];
|
||||
if (idx != 0)
|
||||
Assert.AreEqual(i, actions[idx]);
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestSize()
|
||||
{
|
||||
var set = new ActionSet();
|
||||
Assert.IsTrue(set.IsEmpty);
|
||||
Assert.AreEqual(0, set.Count);
|
||||
|
||||
set.AddAction(ActionType.BasicSynthesis);
|
||||
set.AddAction(ActionType.WasteNot2);
|
||||
|
||||
Assert.AreEqual(2, set.Count);
|
||||
Assert.IsFalse(set.IsEmpty);
|
||||
|
||||
set.RemoveAction(ActionType.BasicSynthesis);
|
||||
set.RemoveAction(ActionType.WasteNot2);
|
||||
|
||||
Assert.IsTrue(set.IsEmpty);
|
||||
Assert.AreEqual(0, set.Count);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestAddRemove()
|
||||
{
|
||||
var set = new ActionSet();
|
||||
|
||||
Assert.IsTrue(set.AddAction(ActionType.BasicSynthesis));
|
||||
Assert.IsFalse(set.AddAction(ActionType.BasicSynthesis));
|
||||
|
||||
Assert.IsTrue(set.RemoveAction(ActionType.BasicSynthesis));
|
||||
Assert.IsFalse(set.RemoveAction(ActionType.BasicSynthesis));
|
||||
|
||||
Assert.IsTrue(set.AddAction(ActionType.BasicSynthesis));
|
||||
Assert.IsTrue(set.AddAction(ActionType.WasteNot2));
|
||||
|
||||
Assert.IsTrue(set.RemoveAction(ActionType.BasicSynthesis));
|
||||
Assert.IsTrue(set.RemoveAction(ActionType.WasteNot2));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestHasAction()
|
||||
{
|
||||
var set = new ActionSet();
|
||||
|
||||
set.AddAction(ActionType.BasicSynthesis);
|
||||
|
||||
Assert.IsTrue(set.HasAction(ActionType.BasicSynthesis));
|
||||
Assert.IsFalse(set.HasAction(ActionType.WasteNot2));
|
||||
|
||||
set.AddAction(ActionType.WasteNot2);
|
||||
Assert.IsTrue(set.HasAction(ActionType.BasicSynthesis));
|
||||
Assert.IsTrue(set.HasAction(ActionType.WasteNot2));
|
||||
|
||||
set.RemoveAction(ActionType.BasicSynthesis);
|
||||
Assert.IsFalse(set.HasAction(ActionType.BasicSynthesis));
|
||||
Assert.IsTrue(set.HasAction(ActionType.WasteNot2));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestElementAt()
|
||||
{
|
||||
var set = new ActionSet();
|
||||
|
||||
set.AddAction(ActionType.BasicSynthesis);
|
||||
set.AddAction(ActionType.ByregotsBlessing);
|
||||
set.AddAction(ActionType.DelicateSynthesis);
|
||||
set.AddAction(ActionType.FocusedTouch);
|
||||
|
||||
Assert.AreEqual(3, set.Count);
|
||||
|
||||
Assert.AreEqual(ActionType.DelicateSynthesis, set.ElementAt(0));
|
||||
Assert.AreEqual(ActionType.FocusedTouch, set.ElementAt(1));
|
||||
Assert.AreEqual(ActionType.ByregotsBlessing, set.ElementAt(2));
|
||||
Assert.AreEqual(ActionType.BasicSynthesis, set.ElementAt(3));
|
||||
|
||||
set.RemoveAction(ActionType.FocusedTouch);
|
||||
|
||||
Assert.AreEqual(3, set.Count);
|
||||
Assert.AreEqual(ActionType.DelicateSynthesis, set.ElementAt(0));
|
||||
Assert.AreEqual(ActionType.ByregotsBlessing, set.ElementAt(1));
|
||||
Assert.AreEqual(ActionType.BasicSynthesis, set.ElementAt(2));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
global using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
global using Craftimizer.Solver;
|
||||
global using Craftimizer.Simulator;
|
||||
Reference in New Issue
Block a user