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