test: finish tas op test
This commit is contained in:
@@ -385,25 +385,19 @@ namespace BallanceTasEditor.Backend {
|
||||
}
|
||||
}
|
||||
|
||||
public enum InsertFrameOperationPosition {
|
||||
public enum InsertFrameOperationKind {
|
||||
Before, After
|
||||
}
|
||||
|
||||
public enum InsertFrameOperationMode {
|
||||
Insert, Overwrite
|
||||
}
|
||||
|
||||
public class InsertFrameOperation : ITasRevocableOperation {
|
||||
public InsertFrameOperation(InsertFrameOperationPosition pos, InsertFrameOperationMode mode, int index, IExactSizeEnumerable<TasFrame> frames) {
|
||||
m_Position = pos;
|
||||
m_Mode = mode;
|
||||
public InsertFrameOperation(InsertFrameOperationKind kind, int index, IExactSizeEnumerable<TasFrame> frames) {
|
||||
m_Kind = kind;
|
||||
m_Index = index;
|
||||
m_InsertedFrames = frames.Select((frame) => frame.ToRaw()).ToArray();
|
||||
m_IsExecuted = false;
|
||||
}
|
||||
|
||||
private InsertFrameOperationPosition m_Position;
|
||||
private InsertFrameOperationMode m_Mode;
|
||||
private InsertFrameOperationKind m_Kind;
|
||||
private int m_Index;
|
||||
private RawTasFrame[] m_InsertedFrames;
|
||||
private bool m_IsExecuted;
|
||||
@@ -420,11 +414,11 @@ namespace BallanceTasEditor.Backend {
|
||||
// Check arguments
|
||||
// If we insert before some frame, the valid index can be [0, count],
|
||||
// however, if we insert after some frame, the valid index is [0, count),
|
||||
switch (m_Position) {
|
||||
case InsertFrameOperationPosition.Before:
|
||||
switch (m_Kind) {
|
||||
case InsertFrameOperationKind.Before:
|
||||
ArgumentOutOfRangeException.ThrowIfGreaterThan(m_Index, seq.GetCount());
|
||||
break;
|
||||
case InsertFrameOperationPosition.After:
|
||||
case InsertFrameOperationKind.After:
|
||||
ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(m_Index, seq.GetCount());
|
||||
break;
|
||||
default:
|
||||
@@ -438,9 +432,9 @@ namespace BallanceTasEditor.Backend {
|
||||
var iter = m_InsertedFrames.Select((frame) => TasFrame.FromRaw(frame));
|
||||
var exactSizedIter = new ExactSizeEnumerableAdapter<TasFrame>(iter, count);
|
||||
// Compute the insert index
|
||||
var index = m_Position switch {
|
||||
InsertFrameOperationPosition.Before => m_Index,
|
||||
InsertFrameOperationPosition.After => m_Index + 1,
|
||||
var index = m_Kind switch {
|
||||
InsertFrameOperationKind.Before => m_Index,
|
||||
InsertFrameOperationKind.After => m_Index + 1,
|
||||
_ => throw new UnreachableException("Unknown InsertFrameOperationKind"),
|
||||
};
|
||||
// Execute inserting.
|
||||
@@ -460,9 +454,9 @@ namespace BallanceTasEditor.Backend {
|
||||
var count = m_InsertedFrames.Length;
|
||||
if (count != 0) {
|
||||
// Compute the index for removing
|
||||
var index = m_Position switch {
|
||||
InsertFrameOperationPosition.Before => m_Index,
|
||||
InsertFrameOperationPosition.After => m_Index + 1,
|
||||
var index = m_Kind switch {
|
||||
InsertFrameOperationKind.Before => m_Index,
|
||||
InsertFrameOperationKind.After => m_Index + 1,
|
||||
_ => throw new UnreachableException("Unknown InsertFrameOperationKind"),
|
||||
};
|
||||
// Execute removing.
|
||||
|
||||
@@ -321,18 +321,37 @@ namespace BallanceTasEditorTests.Backend {
|
||||
public required string Inserted { get; init; }
|
||||
public required string Expected { get; init; }
|
||||
|
||||
public required InsertFrameOperationPosition Position { get; init; }
|
||||
public required InsertFrameOperationMode Mode { get; init; }
|
||||
public required InsertFrameOperationKind Kind { get; init; }
|
||||
public required int Index { get; init; }
|
||||
}
|
||||
|
||||
private static IEnumerable<InsertFrameOperationTestPayload> GetInsertFrameOperationTestPayload() {
|
||||
yield return new InsertFrameOperationTestPayload {
|
||||
Source = "1,1;1,2;1,3;1,4;1,5",
|
||||
Inserted = "1,6;1,7;1,8;1,9;1,10",
|
||||
Expected = "1,1;1,2;2,1;2,2;1,3;1,4;1,5",
|
||||
Position = InsertFrameOperationPosition.After,
|
||||
Mode = InsertFrameOperationMode.Overwrite,
|
||||
Inserted = "1,6;1,7;1,8",
|
||||
Expected = "1,1;1,2;1,6;1,7;1,8;1,3;1,4;1,5",
|
||||
Kind = InsertFrameOperationKind.Before,
|
||||
Index = 2
|
||||
};
|
||||
yield return new InsertFrameOperationTestPayload {
|
||||
Source = "1,1;1,2;1,3;1,4;1,5",
|
||||
Inserted = "1,6;1,7;1,8",
|
||||
Expected = "1,1;1,2;1,3;1,6;1,7;1,8;1,4;1,5",
|
||||
Kind = InsertFrameOperationKind.After,
|
||||
Index = 2
|
||||
};
|
||||
yield return new InsertFrameOperationTestPayload {
|
||||
Source = "1,1;1,2;1,3;1,4;1,5",
|
||||
Inserted = "1,6;1,7",
|
||||
Expected = "1,1;1,2;1,3;1,4;1,5;1,6;1,7",
|
||||
Kind = InsertFrameOperationKind.After,
|
||||
Index = 4
|
||||
};
|
||||
yield return new InsertFrameOperationTestPayload {
|
||||
Source = "1,1;1,2;1,3;1,4;1,5",
|
||||
Inserted = "1,6;1,7",
|
||||
Expected = "1,6;1,7;1,1;1,2;1,3;1,4;1,5",
|
||||
Kind = InsertFrameOperationKind.Before,
|
||||
Index = 0
|
||||
};
|
||||
}
|
||||
@@ -358,7 +377,7 @@ namespace BallanceTasEditorTests.Backend {
|
||||
sequence.Clear();
|
||||
|
||||
// Now we can test it
|
||||
var op = new InsertFrameOperation(payload.Position, payload.Mode, payload.Index, insertedIter);
|
||||
var op = new InsertFrameOperation(payload.Kind, payload.Index, insertedIter);
|
||||
AssertRevocableOperation(sequence, op, payload.Source, payload.Expected);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user