test: add test for tas oper and fix uniform fps op issue
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
<Application x:Class="BallanceTasEditor.App"
|
||||
<Application x:Class="BallanceTasEditor.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="clr-namespace:BallanceTasEditor"
|
||||
StartupUri="Views/MainWindow.xaml">
|
||||
StartupUri="Frontend/Views/MainWindow.xaml">
|
||||
<Application.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="/Styles/AccessoryIconControl.xaml"/>
|
||||
<ResourceDictionary Source="/Styles/NoteBanner.xaml"/>
|
||||
<ResourceDictionary Source="/Styles/GenericButton.xaml"/>
|
||||
<ResourceDictionary Source="/Frontend/Styles/AccessoryIconControl.xaml"/>
|
||||
<ResourceDictionary Source="/Frontend/Styles/NoteBanner.xaml"/>
|
||||
<ResourceDictionary Source="/Frontend/Styles/GenericButton.xaml"/>
|
||||
<ResourceDictionary>
|
||||
|
||||
</ResourceDictionary>
|
||||
|
||||
@@ -385,19 +385,25 @@ namespace BallanceTasEditor.Backend {
|
||||
}
|
||||
}
|
||||
|
||||
public enum InsertFrameOperationKind {
|
||||
public enum InsertFrameOperationPosition {
|
||||
Before, After
|
||||
}
|
||||
|
||||
public enum InsertFrameOperationMode {
|
||||
Insert, Overwrite
|
||||
}
|
||||
|
||||
public class InsertFrameOperation : ITasRevocableOperation {
|
||||
public InsertFrameOperation(InsertFrameOperationKind kind, int index, IExactSizeEnumerable<TasFrame> frames) {
|
||||
m_Kind = kind;
|
||||
public InsertFrameOperation(InsertFrameOperationPosition pos, InsertFrameOperationMode mode, int index, IExactSizeEnumerable<TasFrame> frames) {
|
||||
m_Position = pos;
|
||||
m_Mode = mode;
|
||||
m_Index = index;
|
||||
m_InsertedFrames = frames.Select((frame) => frame.ToRaw()).ToArray();
|
||||
m_IsExecuted = false;
|
||||
}
|
||||
|
||||
private InsertFrameOperationKind m_Kind;
|
||||
private InsertFrameOperationPosition m_Position;
|
||||
private InsertFrameOperationMode m_Mode;
|
||||
private int m_Index;
|
||||
private RawTasFrame[] m_InsertedFrames;
|
||||
private bool m_IsExecuted;
|
||||
@@ -414,11 +420,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_Kind) {
|
||||
case InsertFrameOperationKind.Before:
|
||||
switch (m_Position) {
|
||||
case InsertFrameOperationPosition.Before:
|
||||
ArgumentOutOfRangeException.ThrowIfGreaterThan(m_Index, seq.GetCount());
|
||||
break;
|
||||
case InsertFrameOperationKind.After:
|
||||
case InsertFrameOperationPosition.After:
|
||||
ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(m_Index, seq.GetCount());
|
||||
break;
|
||||
default:
|
||||
@@ -432,9 +438,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_Kind switch {
|
||||
InsertFrameOperationKind.Before => m_Index,
|
||||
InsertFrameOperationKind.After => m_Index + 1,
|
||||
var index = m_Position switch {
|
||||
InsertFrameOperationPosition.Before => m_Index,
|
||||
InsertFrameOperationPosition.After => m_Index + 1,
|
||||
_ => throw new UnreachableException("Unknown InsertFrameOperationKind"),
|
||||
};
|
||||
// Execute inserting.
|
||||
@@ -454,9 +460,9 @@ namespace BallanceTasEditor.Backend {
|
||||
var count = m_InsertedFrames.Length;
|
||||
if (count != 0) {
|
||||
// Compute the index for removing
|
||||
var index = m_Kind switch {
|
||||
InsertFrameOperationKind.Before => m_Index,
|
||||
InsertFrameOperationKind.After => m_Index + 1,
|
||||
var index = m_Position switch {
|
||||
InsertFrameOperationPosition.Before => m_Index,
|
||||
InsertFrameOperationPosition.After => m_Index + 1,
|
||||
_ => throw new UnreachableException("Unknown InsertFrameOperationKind"),
|
||||
};
|
||||
// Execute removing.
|
||||
@@ -497,8 +503,13 @@ namespace BallanceTasEditor.Backend {
|
||||
}
|
||||
|
||||
public class UniformFpsOperation : ITasOperation {
|
||||
public UniformFpsOperation(float deltaTime) {
|
||||
m_DeltaTime = deltaTime;
|
||||
public UniformFpsOperation(uint fps) {
|
||||
// Check arguments
|
||||
if (!FpsConverter.IsValidFps(fps)) {
|
||||
throw new ArgumentOutOfRangeException(nameof(fps));
|
||||
}
|
||||
// Assign arguments
|
||||
m_DeltaTime = FpsConverter.ToDelta(fps);
|
||||
m_IsExecuted = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,10 +13,6 @@
|
||||
<Resource Include="Frontend\Assets\*.ico" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="Frontend\Assets\App.ico" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CommunityToolkit.HighPerformance" Version="8.4.0" />
|
||||
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.1" />
|
||||
|
||||
@@ -70,7 +70,7 @@ namespace BallanceTasEditorTests.Backend {
|
||||
}
|
||||
|
||||
private static string SummarizeSequence(ITasSequence sequence) {
|
||||
return string.Join(
|
||||
return String.Join(
|
||||
";",
|
||||
sequence.Select((f) => {
|
||||
var rawFrame = f.ToRaw();
|
||||
@@ -321,14 +321,20 @@ namespace BallanceTasEditorTests.Backend {
|
||||
public required string Inserted { get; init; }
|
||||
public required string Expected { get; init; }
|
||||
|
||||
public required InsertFrameOperationKind Kind { get; init; }
|
||||
public required InsertFrameOperationPosition Position { get; init; }
|
||||
public required InsertFrameOperationMode Mode { get; init; }
|
||||
public required int Index { get; init; }
|
||||
public required uint Fps { get; init; }
|
||||
public required int Count { get; init; }
|
||||
}
|
||||
|
||||
private static IEnumerable<InsertFrameOperationTestPayload> GetInsertFrameOperationTestPayload() {
|
||||
yield break;
|
||||
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,
|
||||
Index = 0
|
||||
};
|
||||
}
|
||||
|
||||
private static IEnumerable<object[]> InsertFrameOperationTestDataProvider {
|
||||
@@ -343,8 +349,17 @@ namespace BallanceTasEditorTests.Backend {
|
||||
[DataTestMethod]
|
||||
[DynamicData(nameof(InsertFrameOperationTestDataProvider))]
|
||||
public void InsertFrameOperationTest(ITasSequence sequence, InsertFrameOperationTestPayload payload) {
|
||||
//var op = new InsertFrameOperation(payload.Kind, payload.Index, payload.Fps, payload.Count);
|
||||
//AssertRevocableOperation(sequence, op, payload.Source, payload.Expected);
|
||||
// YYC MARK:
|
||||
// I use a nasty way to extract "inserted" data from given string,
|
||||
// because we only support parsing pattern string into TAS sequence.
|
||||
GenerateSequence(sequence, payload.Inserted);
|
||||
var inserted = sequence.ToArray();
|
||||
var insertedIter = new ExactSizeEnumerableAdapter<TasFrame>(inserted, inserted.Length);
|
||||
sequence.Clear();
|
||||
|
||||
// Now we can test it
|
||||
var op = new InsertFrameOperation(payload.Position, payload.Mode, payload.Index, insertedIter);
|
||||
AssertRevocableOperation(sequence, op, payload.Source, payload.Expected);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -357,7 +372,10 @@ namespace BallanceTasEditorTests.Backend {
|
||||
}
|
||||
|
||||
private static IEnumerable<ClearKeysOperationTestPayload> GetClearKeysOperationTestPayload() {
|
||||
yield break;
|
||||
yield return new ClearKeysOperationTestPayload {
|
||||
Source = "1,1;1,2;1,3;1,4;1,5",
|
||||
Expected = "1,0;1,0;1,0;1,0;1,0"
|
||||
};
|
||||
}
|
||||
|
||||
private static IEnumerable<object[]> ClearKeysOperationTestDataProvider {
|
||||
@@ -388,7 +406,11 @@ namespace BallanceTasEditorTests.Backend {
|
||||
}
|
||||
|
||||
private static IEnumerable<UniformFpsOperationTestPayload> GetUniformFpsOperationTestPayload() {
|
||||
yield break;
|
||||
yield return new UniformFpsOperationTestPayload {
|
||||
Source = "1,1;1,2;1,3;1,4;1,5",
|
||||
Expected = "240,1;240,2;240,3;240,4;240,5",
|
||||
Fps = 240
|
||||
};
|
||||
}
|
||||
|
||||
private static IEnumerable<object[]> UniformFpsOperationTestDataProvider {
|
||||
|
||||
Reference in New Issue
Block a user