feat: add before and after support for tas operation
This commit is contained in:
@@ -1,7 +1,3 @@
|
|||||||
// Import LanguageExt globally
|
|
||||||
global using LanguageExt;
|
|
||||||
global using static LanguageExt.Prelude;
|
|
||||||
|
|
||||||
using System.Configuration;
|
using System.Configuration;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@@ -354,13 +355,19 @@ namespace BallanceTasEditor.Backend {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum InsertFrameOperationKind {
|
||||||
|
Before, After
|
||||||
|
}
|
||||||
|
|
||||||
public class InsertFrameOperation : ITasRevocableOperation {
|
public class InsertFrameOperation : ITasRevocableOperation {
|
||||||
public InsertFrameOperation(int index, IExactSizeEnumerable<TasFrame> frames) {
|
public InsertFrameOperation(InsertFrameOperationKind kind, int index, IExactSizeEnumerable<TasFrame> frames) {
|
||||||
|
m_Kind = kind;
|
||||||
m_Index = index;
|
m_Index = index;
|
||||||
m_InsertedFrames = frames.Select((frame) => frame.ToRaw()).ToArray();
|
m_InsertedFrames = frames.Select((frame) => frame.ToRaw()).ToArray();
|
||||||
m_IsExecuted = false;
|
m_IsExecuted = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private InsertFrameOperationKind m_Kind;
|
||||||
private int m_Index;
|
private int m_Index;
|
||||||
private RawTasFrame[] m_InsertedFrames;
|
private RawTasFrame[] m_InsertedFrames;
|
||||||
private bool m_IsExecuted;
|
private bool m_IsExecuted;
|
||||||
@@ -375,7 +382,18 @@ namespace BallanceTasEditor.Backend {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check arguments
|
// 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_Kind) {
|
||||||
|
case InsertFrameOperationKind.Before:
|
||||||
ArgumentOutOfRangeException.ThrowIfGreaterThan(m_Index, seq.GetCount());
|
ArgumentOutOfRangeException.ThrowIfGreaterThan(m_Index, seq.GetCount());
|
||||||
|
break;
|
||||||
|
case InsertFrameOperationKind.After:
|
||||||
|
ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(m_Index, seq.GetCount());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new UnreachableException("Unknown InsertFrameOperationKind");
|
||||||
|
}
|
||||||
|
|
||||||
// Skip if count is zero
|
// Skip if count is zero
|
||||||
var count = m_InsertedFrames.Length;
|
var count = m_InsertedFrames.Length;
|
||||||
@@ -383,8 +401,14 @@ namespace BallanceTasEditor.Backend {
|
|||||||
// Prepare iterator
|
// Prepare iterator
|
||||||
var iter = m_InsertedFrames.Select((frame) => TasFrame.FromRaw(frame));
|
var iter = m_InsertedFrames.Select((frame) => TasFrame.FromRaw(frame));
|
||||||
var exactSizedIter = new ExactSizeEnumerableAdapter<TasFrame>(iter, count);
|
var exactSizedIter = new ExactSizeEnumerableAdapter<TasFrame>(iter, count);
|
||||||
|
// Compute the insert index
|
||||||
|
var index = m_Kind switch {
|
||||||
|
InsertFrameOperationKind.Before => m_Index,
|
||||||
|
InsertFrameOperationKind.After => m_Index + 1,
|
||||||
|
_ => throw new UnreachableException("Unknown InsertFrameOperationKind"),
|
||||||
|
};
|
||||||
// Execute inserting.
|
// Execute inserting.
|
||||||
seq.Insert(m_Index, exactSizedIter);
|
seq.Insert(index, exactSizedIter);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set execution status
|
// Set execution status
|
||||||
@@ -399,7 +423,14 @@ namespace BallanceTasEditor.Backend {
|
|||||||
// Arguments were checked so we directly restore them.
|
// Arguments were checked so we directly restore them.
|
||||||
var count = m_InsertedFrames.Length;
|
var count = m_InsertedFrames.Length;
|
||||||
if (count != 0) {
|
if (count != 0) {
|
||||||
seq.Remove(m_Index, m_Index + count - 1);
|
// Compute the index for removing
|
||||||
|
var index = m_Kind switch {
|
||||||
|
InsertFrameOperationKind.Before => m_Index,
|
||||||
|
InsertFrameOperationKind.After => m_Index + 1,
|
||||||
|
_ => throw new UnreachableException("Unknown InsertFrameOperationKind"),
|
||||||
|
};
|
||||||
|
// Execute removing.
|
||||||
|
seq.Remove(index, index + count - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Modify execution status
|
// Modify execution status
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:local="clr-namespace:BallanceTasEditor.Views"
|
xmlns:local="clr-namespace:BallanceTasEditor.Frontend.Views"
|
||||||
xmlns:vm="clr-namespace:BallanceTasEditor.Frontend.ViewModels"
|
xmlns:vm="clr-namespace:BallanceTasEditor.Frontend.ViewModels"
|
||||||
xmlns:conveter="clr-namespace:BallanceTasEditor.Frontend.Converters"
|
xmlns:conveter="clr-namespace:BallanceTasEditor.Frontend.Converters"
|
||||||
d:DataContext="{d:DesignInstance vm:NewFileDialog}"
|
d:DataContext="{d:DesignInstance vm:NewFileDialog}"
|
||||||
|
|||||||
@@ -0,0 +1,86 @@
|
|||||||
|
using BallanceTasEditor.Backend;
|
||||||
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace BallanceTasEditorTests.Backend {
|
||||||
|
[TestClass]
|
||||||
|
public class TasOperationTests {
|
||||||
|
|
||||||
|
private static IEnumerable<object[]> TasSequenceInstanceProvider {
|
||||||
|
get {
|
||||||
|
yield return new object[] { new ListTasSequence() };
|
||||||
|
yield return new object[] { new LegacyTasSequence() };
|
||||||
|
// TODO: Add GapBufferTasSequence once we finish it.
|
||||||
|
//yield return new object[] { new GapBufferTasSequence() };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// CellKeysOperation测试。
|
||||||
|
/// </summary>
|
||||||
|
[DataTestMethod]
|
||||||
|
[DynamicData(nameof(TasSequenceInstanceProvider))]
|
||||||
|
public void CellKeysOperationTest(ITasSequence sequence, CellKeysOperationKind kind, int startIndex, int endIndex, TasKey startKey, TasKey endKey) {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// FrameFpsOperation测试。
|
||||||
|
/// </summary>
|
||||||
|
[DataTestMethod]
|
||||||
|
[DynamicData(nameof(TasSequenceInstanceProvider))]
|
||||||
|
public void FrameFpsOperationTest(ITasSequence sequence) {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// RemoveFrameOperation测试。
|
||||||
|
/// </summary>
|
||||||
|
[DataTestMethod]
|
||||||
|
[DynamicData(nameof(TasSequenceInstanceProvider))]
|
||||||
|
public void RemoveFrameOperationTest(ITasSequence sequence) {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// AddFrameOperation测试。
|
||||||
|
/// </summary>
|
||||||
|
[DataTestMethod]
|
||||||
|
[DynamicData(nameof(TasSequenceInstanceProvider))]
|
||||||
|
public void AddFrameOperationTest(ITasSequence sequence) {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// InsertFrameOperation测试。
|
||||||
|
/// </summary>
|
||||||
|
[DataTestMethod]
|
||||||
|
[DynamicData(nameof(TasSequenceInstanceProvider))]
|
||||||
|
public void InsertFrameOperationTest(ITasSequence sequence) {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// ClearKeysOperation测试。
|
||||||
|
/// </summary>
|
||||||
|
[DataTestMethod]
|
||||||
|
[DynamicData(nameof(TasSequenceInstanceProvider))]
|
||||||
|
public void ClearKeysOperationTest(ITasSequence sequence) {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// UniformFpsOperation测试。
|
||||||
|
/// </summary>
|
||||||
|
[DataTestMethod]
|
||||||
|
[DynamicData(nameof(TasSequenceInstanceProvider))]
|
||||||
|
public void UniformFpsOperationTest(ITasSequence sequence) {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,19 +13,19 @@ namespace BallanceTasEditorTests.Backend {
|
|||||||
|
|
||||||
private static readonly TasFrame[] BLANK = { };
|
private static readonly TasFrame[] BLANK = { };
|
||||||
private static readonly TasFrame[] PROBE = {
|
private static readonly TasFrame[] PROBE = {
|
||||||
new TasFrame(10),
|
TasFrame.FromFps(10),
|
||||||
new TasFrame(20),
|
TasFrame.FromFps(20),
|
||||||
new TasFrame(30),
|
TasFrame.FromFps(30),
|
||||||
new TasFrame(40),
|
TasFrame.FromFps(40),
|
||||||
new TasFrame(50),
|
TasFrame.FromFps(50),
|
||||||
};
|
};
|
||||||
|
|
||||||
private static CountableEnumerable<TasFrame> GetCountableProbe() {
|
private static IExactSizeEnumerable<TasFrame> GetExactSizeProbe() {
|
||||||
return new CountableEnumerable<TasFrame>(PROBE);
|
return new ExactSizeEnumerableAdapter<TasFrame>(PROBE, PROBE.Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static CountableEnumerable<TasFrame> GetCountableBlank() {
|
private static IExactSizeEnumerable<TasFrame> GetExactSizeBlank() {
|
||||||
return new CountableEnumerable<TasFrame>(BLANK);
|
return new ExactSizeEnumerableAdapter<TasFrame>(BLANK, BLANK.Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IEnumerable<object[]> TasSequenceInstanceProvider {
|
private static IEnumerable<object[]> TasSequenceInstanceProvider {
|
||||||
@@ -40,7 +40,7 @@ namespace BallanceTasEditorTests.Backend {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Visit函数独立测试。
|
/// Visit函数独立测试。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[TestMethod]
|
[DataTestMethod]
|
||||||
[DynamicData(nameof(TasSequenceInstanceProvider))]
|
[DynamicData(nameof(TasSequenceInstanceProvider))]
|
||||||
public void VisitTest(ITasSequence sequence) {
|
public void VisitTest(ITasSequence sequence) {
|
||||||
// 空时访问
|
// 空时访问
|
||||||
@@ -49,7 +49,7 @@ namespace BallanceTasEditorTests.Backend {
|
|||||||
AssertExtension.ThrowsDerivedException<ArgumentException>(() => sequence.Visit(1));
|
AssertExtension.ThrowsDerivedException<ArgumentException>(() => sequence.Visit(1));
|
||||||
|
|
||||||
// 设置数据
|
// 设置数据
|
||||||
sequence.Insert(0, GetCountableProbe());
|
sequence.Insert(0, GetExactSizeProbe());
|
||||||
// 访问数据
|
// 访问数据
|
||||||
AssertExtension.ThrowsDerivedException<ArgumentException>(() => sequence.Visit(-1));
|
AssertExtension.ThrowsDerivedException<ArgumentException>(() => sequence.Visit(-1));
|
||||||
for (int i = 0; i < PROBE.Length; i++) {
|
for (int i = 0; i < PROBE.Length; i++) {
|
||||||
@@ -61,16 +61,16 @@ namespace BallanceTasEditorTests.Backend {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Insert函数独立测试。
|
/// Insert函数独立测试。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[TestMethod]
|
[DataTestMethod]
|
||||||
[DynamicData(nameof(TasSequenceInstanceProvider))]
|
[DynamicData(nameof(TasSequenceInstanceProvider))]
|
||||||
public void InsertTest(ITasSequence sequence) {
|
public void InsertTest(ITasSequence sequence) {
|
||||||
// 需要在不同的存储器上,分别检测在空的时候插入,
|
// 需要在不同的存储器上,分别检测在空的时候插入,
|
||||||
// 和在非空时的头,中,尾分别插入的结果。
|
// 和在非空时的头,中,尾分别插入的结果。
|
||||||
|
|
||||||
// 先检测空插入
|
// 先检测空插入
|
||||||
AssertExtension.ThrowsDerivedException<ArgumentException>(() => sequence.Insert(-1, GetCountableProbe()));
|
AssertExtension.ThrowsDerivedException<ArgumentException>(() => sequence.Insert(-1, GetExactSizeProbe()));
|
||||||
AssertExtension.ThrowsDerivedException<ArgumentException>(() => sequence.Insert(1, GetCountableProbe()));
|
AssertExtension.ThrowsDerivedException<ArgumentException>(() => sequence.Insert(1, GetExactSizeProbe()));
|
||||||
sequence.Insert(0, GetCountableProbe());
|
sequence.Insert(0, GetExactSizeProbe());
|
||||||
for (int i = 0; i < PROBE.Length; i++) {
|
for (int i = 0; i < PROBE.Length; i++) {
|
||||||
Assert.AreEqual(sequence.Visit(i), PROBE[i]);
|
Assert.AreEqual(sequence.Visit(i), PROBE[i]);
|
||||||
}
|
}
|
||||||
@@ -80,8 +80,8 @@ namespace BallanceTasEditorTests.Backend {
|
|||||||
foreach (var index in indices) {
|
foreach (var index in indices) {
|
||||||
// 清空,一次插入,然后二次插入
|
// 清空,一次插入,然后二次插入
|
||||||
sequence.Clear();
|
sequence.Clear();
|
||||||
sequence.Insert(0, GetCountableProbe());
|
sequence.Insert(0, GetExactSizeProbe());
|
||||||
sequence.Insert(index, GetCountableProbe());
|
sequence.Insert(index, GetExactSizeProbe());
|
||||||
|
|
||||||
// 用List做正确模拟
|
// 用List做正确模拟
|
||||||
var expected = new List<TasFrame>();
|
var expected = new List<TasFrame>();
|
||||||
@@ -100,7 +100,7 @@ namespace BallanceTasEditorTests.Backend {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Remove函数独立测试。
|
/// Remove函数独立测试。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[TestMethod]
|
[DataTestMethod]
|
||||||
[DynamicData(nameof(TasSequenceInstanceProvider))]
|
[DynamicData(nameof(TasSequenceInstanceProvider))]
|
||||||
public void RemoveTest(ITasSequence sequence) {
|
public void RemoveTest(ITasSequence sequence) {
|
||||||
// 在空的时候删除0项
|
// 在空的时候删除0项
|
||||||
@@ -111,7 +111,7 @@ namespace BallanceTasEditorTests.Backend {
|
|||||||
foreach (var index in indices) {
|
foreach (var index in indices) {
|
||||||
// 清空,插入,删除
|
// 清空,插入,删除
|
||||||
sequence.Clear();
|
sequence.Clear();
|
||||||
sequence.Insert(0, GetCountableProbe());
|
sequence.Insert(0, GetExactSizeProbe());
|
||||||
sequence.Remove(index, 1);
|
sequence.Remove(index, 1);
|
||||||
|
|
||||||
// 用List做正确模拟
|
// 用List做正确模拟
|
||||||
@@ -130,11 +130,11 @@ namespace BallanceTasEditorTests.Backend {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Clear函数独立测试。
|
/// Clear函数独立测试。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[TestMethod]
|
[DataTestMethod]
|
||||||
[DynamicData(nameof(TasSequenceInstanceProvider))]
|
[DynamicData(nameof(TasSequenceInstanceProvider))]
|
||||||
public void ClearTest(ITasSequence sequence) {
|
public void ClearTest(ITasSequence sequence) {
|
||||||
// 设置数据后清空
|
// 设置数据后清空
|
||||||
sequence.Insert(0, GetCountableProbe());
|
sequence.Insert(0, GetExactSizeProbe());
|
||||||
sequence.Clear();
|
sequence.Clear();
|
||||||
|
|
||||||
// 检查是否为空
|
// 检查是否为空
|
||||||
@@ -144,28 +144,28 @@ namespace BallanceTasEditorTests.Backend {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// IsEmpty函数独立测试。
|
/// IsEmpty函数独立测试。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[TestMethod]
|
[DataTestMethod]
|
||||||
[DynamicData(nameof(TasSequenceInstanceProvider))]
|
[DynamicData(nameof(TasSequenceInstanceProvider))]
|
||||||
public void IsEmptyTest(ITasSequence sequence) {
|
public void IsEmptyTest(ITasSequence sequence) {
|
||||||
// 检查是否为空
|
// 检查是否为空
|
||||||
Assert.IsTrue(sequence.IsEmpty());
|
Assert.IsTrue(sequence.IsEmpty());
|
||||||
|
|
||||||
// 插入数据后再检查
|
// 插入数据后再检查
|
||||||
sequence.Insert(0, GetCountableProbe());
|
sequence.Insert(0, GetExactSizeProbe());
|
||||||
Assert.IsFalse(sequence.IsEmpty());
|
Assert.IsFalse(sequence.IsEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// GetCount函数独立测试。
|
/// GetCount函数独立测试。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[TestMethod]
|
[DataTestMethod]
|
||||||
[DynamicData(nameof(TasSequenceInstanceProvider))]
|
[DynamicData(nameof(TasSequenceInstanceProvider))]
|
||||||
public void GetCountTest(ITasSequence sequence) {
|
public void GetCountTest(ITasSequence sequence) {
|
||||||
// 检查长度为0
|
// 检查长度为0
|
||||||
Assert.AreEqual(sequence.GetCount(), 0);
|
Assert.AreEqual(sequence.GetCount(), 0);
|
||||||
|
|
||||||
// 插入数据后再检查
|
// 插入数据后再检查
|
||||||
sequence.Insert(0, GetCountableProbe());
|
sequence.Insert(0, GetExactSizeProbe());
|
||||||
Assert.AreEqual(sequence.GetCount(), PROBE.Length);
|
Assert.AreEqual(sequence.GetCount(), PROBE.Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,7 +173,7 @@ namespace BallanceTasEditorTests.Backend {
|
|||||||
/// 混合检查Visit,Clear,GetCount,IsEmpty。
|
/// 混合检查Visit,Clear,GetCount,IsEmpty。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sequence"></param>
|
/// <param name="sequence"></param>
|
||||||
[TestMethod]
|
[DataTestMethod]
|
||||||
[DynamicData(nameof(TasSequenceInstanceProvider))]
|
[DynamicData(nameof(TasSequenceInstanceProvider))]
|
||||||
public void HybridTest(ITasSequence sequence) {
|
public void HybridTest(ITasSequence sequence) {
|
||||||
// 检查空和大小
|
// 检查空和大小
|
||||||
@@ -181,7 +181,7 @@ namespace BallanceTasEditorTests.Backend {
|
|||||||
Assert.AreEqual(sequence.GetCount(), 0);
|
Assert.AreEqual(sequence.GetCount(), 0);
|
||||||
|
|
||||||
// 设置内容
|
// 设置内容
|
||||||
sequence.Insert(0, GetCountableProbe());
|
sequence.Insert(0, GetExactSizeProbe());
|
||||||
// 并再次检查大小
|
// 并再次检查大小
|
||||||
Assert.IsFalse(sequence.IsEmpty());
|
Assert.IsFalse(sequence.IsEmpty());
|
||||||
Assert.AreEqual(sequence.GetCount(), PROBE.Length);
|
Assert.AreEqual(sequence.GetCount(), PROBE.Length);
|
||||||
@@ -200,7 +200,7 @@ namespace BallanceTasEditorTests.Backend {
|
|||||||
|
|
||||||
// 清空后插入0项,然后确认
|
// 清空后插入0项,然后确认
|
||||||
sequence.Clear();
|
sequence.Clear();
|
||||||
sequence.Insert(0, GetCountableBlank());
|
sequence.Insert(0, GetExactSizeBlank());
|
||||||
AssertExtension.ThrowsDerivedException<ArgumentException>(() => sequence.Visit(-1));
|
AssertExtension.ThrowsDerivedException<ArgumentException>(() => sequence.Visit(-1));
|
||||||
AssertExtension.ThrowsDerivedException<ArgumentException>(() => sequence.Visit(0));
|
AssertExtension.ThrowsDerivedException<ArgumentException>(() => sequence.Visit(0));
|
||||||
AssertExtension.ThrowsDerivedException<ArgumentException>(() => sequence.Visit(1));
|
AssertExtension.ThrowsDerivedException<ArgumentException>(() => sequence.Visit(1));
|
||||||
|
|||||||
Reference in New Issue
Block a user