Skip to content

Commit

Permalink
fix: Magic number
Browse files Browse the repository at this point in the history
  • Loading branch information
jcs090218 committed Sep 23, 2023
1 parent 4f85f87 commit 1c70713
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 21 deletions.
7 changes: 6 additions & 1 deletion Compile/Compile.Test/UnitTest1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,13 @@ public void TestCapital()
public void TestScore()
{
Score score = Flx.Score("switch-to-buffer", "stb");

Assert.AreEqual(237, score.score);

score = Flx.Score("TestSomeFunctionExterme", "met");
Assert.AreEqual(57, score.score);

score = Flx.Score("MetaX_Version", "met");
Assert.AreEqual(211, score.score);
}
}
}
2 changes: 1 addition & 1 deletion Compile/Compile/Compile.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>$(VersionPrefix)0.1.1</Version>
<Version>$(VersionPrefix)0.1.2</Version>
<Description>Rewrite emacs-flx in C#</Description>
<Copyright>FlxCs is distributed under the terms of the MIT license.</Copyright>
<PackageProjectUrl>https://github.com/jcs090218/FlxCs</PackageProjectUrl>
Expand Down
2 changes: 1 addition & 1 deletion Source/Assets/FlxCs/Scripts/Flx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ public static void FindBestMatch(List<Score> imatch,
if ((caar - 1) == index)
{
tempScore = cadr + heatmap[index] +
(Math.Min(cddr, 0) * 15) + // boost contiguous matches
(Math.Min(cddr, 3) * 15) + // boost contiguous matches
60;
}
else
Expand Down
5 changes: 5 additions & 0 deletions Source/Assets/FlxCs/Scripts/Score.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,10 @@ public Score(List<int> indices, int score, int tail)
this.score = score;
this.tail = tail;
}

public override string ToString()
{
return score + " " + Util.ToString(indices);
}
}
}
12 changes: 12 additions & 0 deletions Source/Assets/FlxCs/Scripts/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,17 @@ public static void DictInsert(Dictionary<int, List<int>> result, int key, int va
List<int> lst = result[key];
lst.Insert(0, val);
}

public static string ToString<T>(List<T> lst)
{
string str = "";

foreach (var elm in lst)
{
str += elm.ToString() + " ";
}

return str;
}
}
}
29 changes: 11 additions & 18 deletions Source/Assets/_Project/Scripts/Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,14 @@ public class Test : MonoBehaviour
// Start is called before the first frame update
private void Start()
{
Score score = Flx.Score("switch-to-buffer", "stb");

print(score.score);

Print(score.indices);
TestOne("TestSomeFunctionExterme", "met");
TestOne("MetaX_Version", "met");
}

private void Other()
private void TestOne(string str, string query)
{
print(Flx.Word('C'));

var lst = new List<int>() { 1, 2, 3, 4 };

Flx.IncVec(lst, null, null, null);

foreach (int i in lst)
{
print(i);
}
Score score = Flx.Score(str, query);
print(score.ToString());
}

public static void Print<T>(List<T> lst)
Expand All @@ -43,11 +32,15 @@ public static void Print<T>(List<T> lst)

public static void Print<T>(Dictionary<int, List<T>> dict)
{
string str = "";

foreach (KeyValuePair<int, List<T>> entry in dict)
{
Debug.LogWarning(entry.Key);
Print(entry.Value);
str += entry.Key + " ";
//Print(entry.Value);
}

Debug.Log(str);
}
}
#endif

0 comments on commit 1c70713

Please sign in to comment.