-
-
Notifications
You must be signed in to change notification settings - Fork 620
Expand file tree
/
Copy pathTranslationMappingTest.cs
More file actions
71 lines (64 loc) · 2.79 KB
/
Copy pathTranslationMappingTest.cs
File metadata and controls
71 lines (64 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using System.Collections.Generic;
using System.Reflection;
using Flow.Launcher.Infrastructure;
using NUnit.Framework;
using NUnit.Framework.Legacy;
namespace Flow.Launcher.Test
{
[TestFixture]
public class TranslationMappingTest
{
[Test]
public void AddNewIndex_ShouldAddTranslatedIndexPlusLength()
{
var mapping = new TranslationMapping();
mapping.AddNewIndex(5, 3);
mapping.AddNewIndex(8, 2);
// 5+3=8, 8+2=10
ClassicAssert.AreEqual(2, GetOriginalToTranslatedCount(mapping));
ClassicAssert.AreEqual(8, GetOriginalToTranslatedAt(mapping, 0));
ClassicAssert.AreEqual(10, GetOriginalToTranslatedAt(mapping, 1));
}
[TestCase(0, 0)] // "F" -> "F"
[TestCase(1, 1)] // "l" -> "l"
[TestCase(2, 2)] // "o" -> "o"
[TestCase(3, 3)] // "w" -> "w"
[TestCase(4, 4)] // " " -> " "
[TestCase(5, 5)] // "Y" (translated from "用") -> original index 5
[TestCase(6, 5)] // "o" (translated from "用") -> original index 5
[TestCase(7, 5)] // "n" (translated from "用") -> original index 5
[TestCase(8, 5)] // "g" (translated from "用") -> original index 5
[TestCase(10, 6)] // "H" (translated from "户") -> original index 6
[TestCase(11, 6)] // "u" (translated from "户") -> original index 6
public void MapToOriginalIndex_ShouldReturnExpectedIndex(int translatedIndex, int expectedOriginalIndex)
{
var mapping = new TranslationMapping();
// Test case :
// 0123456
// Flow 用户
// 012345678901
// Flow Yong Hu
mapping.AddNewIndex(0, 1); // F
mapping.AddNewIndex(1, 1); // l
mapping.AddNewIndex(2, 1); // o
mapping.AddNewIndex(3, 1); // w
mapping.AddNewIndex(4, 1); // ' '
mapping.AddNewIndex(5, 4); // 用 -> Yong
mapping.AddNewIndex(10, 2); // 户 -> Hu
var result = mapping.MapToOriginalIndex(translatedIndex);
ClassicAssert.AreEqual(expectedOriginalIndex, result);
}
private static int GetOriginalToTranslatedCount(TranslationMapping mapping)
{
var field = typeof(TranslationMapping).GetField("_originalToTranslated", BindingFlags.NonPublic | BindingFlags.Instance);
var list = (List<int>)field.GetValue(mapping);
return list.Count;
}
private static int GetOriginalToTranslatedAt(TranslationMapping mapping, int index)
{
var field = typeof(TranslationMapping).GetField("_originalToTranslated", BindingFlags.NonPublic | BindingFlags.Instance);
var list = (List<int>)field.GetValue(mapping);
return list[index];
}
}
}