mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Improve code quality
This commit is contained in:
parent
071b75bcb5
commit
d7d3549c82
2 changed files with 9 additions and 10 deletions
|
|
@ -11,12 +11,10 @@ namespace Flow.Launcher.Infrastructure
|
|||
// list[i] is the last translated index + 1 of original index i
|
||||
private readonly List<int> _originalToTranslated = new();
|
||||
|
||||
|
||||
public void AddNewIndex(int translatedIndex, int length)
|
||||
{
|
||||
if (_isConstructed)
|
||||
throw new InvalidOperationException("Mapping shouldn't be changed after construction");
|
||||
|
||||
_originalToTranslated.Add(translatedIndex + length);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
using Flow.Launcher.Infrastructure;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using Flow.Launcher.Infrastructure;
|
||||
using NUnit.Framework;
|
||||
using NUnit.Framework.Legacy;
|
||||
|
||||
|
|
@ -34,22 +36,21 @@ namespace Flow.Launcher.Test
|
|||
mapping.AddNewIndex(2, 2);
|
||||
mapping.AddNewIndex(5, 3);
|
||||
|
||||
|
||||
var result = mapping.MapToOriginalIndex(translatedIndex);
|
||||
ClassicAssert.AreEqual(expectedOriginalIndex, result);
|
||||
}
|
||||
|
||||
private int GetOriginalToTranslatedCount(TranslationMapping mapping)
|
||||
private static int GetOriginalToTranslatedCount(TranslationMapping mapping)
|
||||
{
|
||||
var field = typeof(TranslationMapping).GetField("originalToTranslated", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
|
||||
var list = (System.Collections.Generic.List<int>)field.GetValue(mapping);
|
||||
var field = typeof(TranslationMapping).GetField("originalToTranslated", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
var list = (List<int>)field.GetValue(mapping);
|
||||
return list.Count;
|
||||
}
|
||||
|
||||
private int GetOriginalToTranslatedAt(TranslationMapping mapping, int index)
|
||||
private static int GetOriginalToTranslatedAt(TranslationMapping mapping, int index)
|
||||
{
|
||||
var field = typeof(TranslationMapping).GetField("originalToTranslated", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
|
||||
var list = (System.Collections.Generic.List<int>)field.GetValue(mapping);
|
||||
var field = typeof(TranslationMapping).GetField("originalToTranslated", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
var list = (List<int>)field.GetValue(mapping);
|
||||
return list[index];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue