补全 S1 测试
- 调整 CombatNode 正常结束与异常的变量语义,现在是 DidCombatWin 与 Exception - 补充测试样例 - 完成 S1 目标
This commit is contained in:
@@ -0,0 +1,139 @@
|
||||
using GeometryTD.Definition;
|
||||
using GeometryTD.Procedure;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace GeometryTD.Tests.EditMode
|
||||
{
|
||||
public sealed class ProcedureMainServicesTests
|
||||
{
|
||||
[Test]
|
||||
public void TryAdvanceRun_Returns_AdvancedToNextNode_For_Normal_Completion()
|
||||
{
|
||||
RunState runState = CreateTwoNodeRun();
|
||||
|
||||
ProcedureMainRunAdvanceResult result = ProcedureMainRunFlowService.TryAdvanceRun(
|
||||
runState,
|
||||
RunNodeCompletionStatus.Completed,
|
||||
new BackpackInventoryData { Gold = 88 });
|
||||
|
||||
Assert.That(result, Is.EqualTo(ProcedureMainRunAdvanceResult.AdvancedToNextNode));
|
||||
Assert.That(runState.IsCompleted, Is.False);
|
||||
Assert.That(runState.Nodes[0].Status, Is.EqualTo(RunNodeStatus.Completed));
|
||||
Assert.That(runState.CurrentNodeIndex, Is.EqualTo(1));
|
||||
Assert.That(runState.CurrentNode.Status, Is.EqualTo(RunNodeStatus.Available));
|
||||
Assert.That(runState.RunInventorySnapshot.Gold, Is.EqualTo(88));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TryAdvanceRun_Returns_NodeException_For_Exception_Fallback()
|
||||
{
|
||||
RunState runState = CreateTwoNodeRun();
|
||||
|
||||
ProcedureMainRunAdvanceResult result = ProcedureMainRunFlowService.TryAdvanceRun(
|
||||
runState,
|
||||
RunNodeCompletionStatus.Exception,
|
||||
new BackpackInventoryData { Gold = 5 });
|
||||
|
||||
Assert.That(result, Is.EqualTo(ProcedureMainRunAdvanceResult.NodeException));
|
||||
Assert.That(runState.IsCompleted, Is.False);
|
||||
Assert.That(runState.CurrentNodeIndex, Is.EqualTo(0));
|
||||
Assert.That(runState.CurrentNode.Status, Is.EqualTo(RunNodeStatus.Exception));
|
||||
Assert.That(runState.Nodes[1].Status, Is.EqualTo(RunNodeStatus.Locked));
|
||||
Assert.That(runState.RunInventorySnapshot.Gold, Is.EqualTo(5));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TryAdvanceRun_Returns_RunCompleted_When_Last_Node_Finishes()
|
||||
{
|
||||
RunState runState = RunStateFactory.Create(
|
||||
LevelThemeType.Plain,
|
||||
new BackpackInventoryData { Gold = 30 },
|
||||
new[]
|
||||
{
|
||||
new RunNodeSeed { NodeId = 901, NodeType = RunNodeType.BossCombat, LinkedLevelId = 4 }
|
||||
});
|
||||
|
||||
ProcedureMainRunAdvanceResult result = ProcedureMainRunFlowService.TryAdvanceRun(
|
||||
runState,
|
||||
RunNodeCompletionStatus.Completed,
|
||||
new BackpackInventoryData { Gold = 123 });
|
||||
|
||||
Assert.That(result, Is.EqualTo(ProcedureMainRunAdvanceResult.RunCompleted));
|
||||
Assert.That(runState.IsCompleted, Is.True);
|
||||
Assert.That(runState.CurrentNodeIndex, Is.EqualTo(1));
|
||||
Assert.That(runState.CompletedNodeCount, Is.EqualTo(1));
|
||||
Assert.That(runState.RunInventorySnapshot.Gold, Is.EqualTo(123));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TryAdvanceRun_Returns_NoChange_When_Run_Cannot_Advance()
|
||||
{
|
||||
ProcedureMainRunAdvanceResult nullRunResult = ProcedureMainRunFlowService.TryAdvanceRun(
|
||||
null,
|
||||
RunNodeCompletionStatus.Completed,
|
||||
new BackpackInventoryData { Gold = 1 });
|
||||
|
||||
Assert.That(nullRunResult, Is.EqualTo(ProcedureMainRunAdvanceResult.NoChange));
|
||||
|
||||
RunState completedRun = RunStateFactory.Create(
|
||||
LevelThemeType.Plain,
|
||||
new BackpackInventoryData { Gold = 10 },
|
||||
new RunNodeSeed[0]);
|
||||
|
||||
ProcedureMainRunAdvanceResult completedRunResult = ProcedureMainRunFlowService.TryAdvanceRun(
|
||||
completedRun,
|
||||
RunNodeCompletionStatus.Completed,
|
||||
new BackpackInventoryData { Gold = 20 });
|
||||
|
||||
Assert.That(completedRunResult, Is.EqualTo(ProcedureMainRunAdvanceResult.NoChange));
|
||||
Assert.That(completedRun.RunInventorySnapshot.Gold, Is.EqualTo(10));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TryEnterCompletedPendingFinish_Shows_Dialog_Only_Once()
|
||||
{
|
||||
ProcedureMainRunCompletionResult firstResult =
|
||||
ProcedureMainRunCompletionService.TryEnterCompletedPendingFinish(false);
|
||||
ProcedureMainRunCompletionResult secondResult =
|
||||
ProcedureMainRunCompletionService.TryEnterCompletedPendingFinish(true);
|
||||
|
||||
Assert.That(firstResult, Is.EqualTo(ProcedureMainRunCompletionResult.ShowCompletionDialog));
|
||||
Assert.That(secondResult, Is.EqualTo(ProcedureMainRunCompletionResult.NoChange));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TryConfirmReturnToMenu_Returns_Menu_Only_In_Completed_Pending_Finish()
|
||||
{
|
||||
ProcedureMainRunCompletionResult validResult =
|
||||
ProcedureMainRunCompletionService.TryConfirmReturnToMenu(
|
||||
ProcedureMainFlowPhase.RunCompletedPendingFinish,
|
||||
false);
|
||||
|
||||
ProcedureMainRunCompletionResult hubResult =
|
||||
ProcedureMainRunCompletionService.TryConfirmReturnToMenu(
|
||||
ProcedureMainFlowPhase.Hub,
|
||||
false);
|
||||
|
||||
ProcedureMainRunCompletionResult pendingResult =
|
||||
ProcedureMainRunCompletionService.TryConfirmReturnToMenu(
|
||||
ProcedureMainFlowPhase.RunCompletedPendingFinish,
|
||||
true);
|
||||
|
||||
Assert.That(validResult, Is.EqualTo(ProcedureMainRunCompletionResult.ReturnToMenu));
|
||||
Assert.That(hubResult, Is.EqualTo(ProcedureMainRunCompletionResult.NoChange));
|
||||
Assert.That(pendingResult, Is.EqualTo(ProcedureMainRunCompletionResult.NoChange));
|
||||
}
|
||||
|
||||
private static RunState CreateTwoNodeRun()
|
||||
{
|
||||
return RunStateFactory.Create(
|
||||
LevelThemeType.Plain,
|
||||
new BackpackInventoryData { Gold = 50 },
|
||||
new[]
|
||||
{
|
||||
new RunNodeSeed { NodeId = 101, NodeType = RunNodeType.Combat, LinkedLevelId = 1 },
|
||||
new RunNodeSeed { NodeId = 102, NodeType = RunNodeType.Event }
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bb7e69f8c974497c9431d4e1d9e6e8b4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -59,7 +59,7 @@ namespace GeometryTD.Tests.EditMode
|
||||
|
||||
bool firstCompleted = RunStateAdvanceService.TryCompleteCurrentNode(
|
||||
runState,
|
||||
true,
|
||||
RunNodeCompletionStatus.Completed,
|
||||
new BackpackInventoryData { Gold = 80 });
|
||||
|
||||
Assert.That(firstCompleted, Is.True);
|
||||
@@ -68,8 +68,14 @@ namespace GeometryTD.Tests.EditMode
|
||||
Assert.That(runState.Nodes[1].Status, Is.EqualTo(RunNodeStatus.Available));
|
||||
Assert.That(runState.RunInventorySnapshot.Gold, Is.EqualTo(80));
|
||||
|
||||
RunStateAdvanceService.TryCompleteCurrentNode(runState, true, new BackpackInventoryData { Gold = 95 });
|
||||
RunStateAdvanceService.TryCompleteCurrentNode(runState, true, new BackpackInventoryData { Gold = 130 });
|
||||
RunStateAdvanceService.TryCompleteCurrentNode(
|
||||
runState,
|
||||
RunNodeCompletionStatus.Completed,
|
||||
new BackpackInventoryData { Gold = 95 });
|
||||
RunStateAdvanceService.TryCompleteCurrentNode(
|
||||
runState,
|
||||
RunNodeCompletionStatus.Completed,
|
||||
new BackpackInventoryData { Gold = 130 });
|
||||
|
||||
Assert.That(runState.IsCompleted, Is.True);
|
||||
Assert.That(runState.CurrentNodeIndex, Is.EqualTo(3));
|
||||
@@ -78,7 +84,7 @@ namespace GeometryTD.Tests.EditMode
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AdvanceService_Failure_Marks_Current_Node_Failed_Without_Completing_Run()
|
||||
public void AdvanceService_Exception_Marks_Current_Node_Exception_Without_Completing_Run()
|
||||
{
|
||||
RunState runState = RunStateFactory.Create(
|
||||
LevelThemeType.Plain,
|
||||
@@ -90,13 +96,13 @@ namespace GeometryTD.Tests.EditMode
|
||||
|
||||
bool result = RunStateAdvanceService.TryCompleteCurrentNode(
|
||||
runState,
|
||||
false,
|
||||
RunNodeCompletionStatus.Exception,
|
||||
new BackpackInventoryData { Gold = 5 });
|
||||
|
||||
Assert.That(result, Is.True);
|
||||
Assert.That(runState.IsCompleted, Is.False);
|
||||
Assert.That(runState.CurrentNodeIndex, Is.EqualTo(0));
|
||||
Assert.That(runState.CurrentNode.Status, Is.EqualTo(RunNodeStatus.Failed));
|
||||
Assert.That(runState.CurrentNode.Status, Is.EqualTo(RunNodeStatus.Exception));
|
||||
Assert.That(runState.RunInventorySnapshot.Gold, Is.EqualTo(5));
|
||||
}
|
||||
|
||||
@@ -109,6 +115,7 @@ namespace GeometryTD.Tests.EditMode
|
||||
7,
|
||||
RunNodeType.Shop,
|
||||
3,
|
||||
RunNodeCompletionStatus.Completed,
|
||||
true,
|
||||
inventory);
|
||||
|
||||
@@ -118,7 +125,8 @@ namespace GeometryTD.Tests.EditMode
|
||||
Assert.That(eventArgs.NodeId, Is.EqualTo(7));
|
||||
Assert.That(eventArgs.NodeType, Is.EqualTo(RunNodeType.Shop));
|
||||
Assert.That(eventArgs.SequenceIndex, Is.EqualTo(3));
|
||||
Assert.That(eventArgs.Succeeded, Is.True);
|
||||
Assert.That(eventArgs.CompletionStatus, Is.EqualTo(RunNodeCompletionStatus.Completed));
|
||||
Assert.That(eventArgs.CombatWon, Is.True);
|
||||
Assert.That(eventArgs.InventorySnapshotAfterNode.Gold, Is.EqualTo(66));
|
||||
|
||||
eventArgs.Clear();
|
||||
@@ -127,7 +135,8 @@ namespace GeometryTD.Tests.EditMode
|
||||
Assert.That(eventArgs.NodeId, Is.EqualTo(0));
|
||||
Assert.That(eventArgs.NodeType, Is.EqualTo(RunNodeType.None));
|
||||
Assert.That(eventArgs.SequenceIndex, Is.EqualTo(-1));
|
||||
Assert.That(eventArgs.Succeeded, Is.False);
|
||||
Assert.That(eventArgs.CompletionStatus, Is.EqualTo(RunNodeCompletionStatus.None));
|
||||
Assert.That(eventArgs.CombatWon, Is.False);
|
||||
Assert.That(eventArgs.InventorySnapshotAfterNode, Is.Null);
|
||||
}
|
||||
|
||||
@@ -189,7 +198,7 @@ namespace GeometryTD.Tests.EditMode
|
||||
{
|
||||
bool advanced = RunStateAdvanceService.TryCompleteCurrentNode(
|
||||
runState,
|
||||
true,
|
||||
RunNodeCompletionStatus.Completed,
|
||||
new BackpackInventoryData { Gold = 100 + i });
|
||||
|
||||
Assert.That(advanced, Is.True);
|
||||
|
||||
Reference in New Issue
Block a user