Skip to content

Commit

Permalink
Update to V3
Browse files Browse the repository at this point in the history
Adds new IsEncoded and IsCharacterValueGroup methods. Improves performance.
  • Loading branch information
bijij committed Jan 22, 2021
1 parent 482f330 commit f96343a
Show file tree
Hide file tree
Showing 6 changed files with 194 additions and 62 deletions.
6 changes: 3 additions & 3 deletions src/Bottom.Bench/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ public BottomBenchmark()
_encode_data = BenchmarkData.ENCODE_INPUT[N];
_decode_data = BenchmarkData.DECODE_INPUT[N];

Bottomify.encode_byte(0); // preload cache
Bottomify.EncodeByte(0); // preload cache
}

[Benchmark]
public string Encode() => Bottomify.encode_string(_encode_data);
public string Encode() => Bottomify.EncodeString(_encode_data);

[Benchmark]
public string Decode() => Bottomify.decode_string(_decode_data);
public string Decode() => Bottomify.DecodeString(_decode_data);

}

Expand Down
2 changes: 1 addition & 1 deletion src/Bottom.CLI/Bottom.CLI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>Bottom.CLI</RootNamespace>
<StartupObject>Bottom.CLI.Program</StartupObject>
<Version>2.0.0</Version>
<Version>3.0.0.0</Version>
<AssemblyName>Bottom.CLI</AssemblyName>
</PropertyGroup>

Expand Down
4 changes: 2 additions & 2 deletions src/Bottom.CLI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ static int Main(string[] args)
string result;
if (bottomify)
{
result = Bottomify.encode_string(text);
result = Bottomify.EncodeString(text);
}
else
{
result = Bottomify.decode_string(text);
result = Bottomify.DecodeString(text);
}
if (!(output is null))
Expand Down
74 changes: 54 additions & 20 deletions src/Bottom.UnitTest/UnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,75 +5,109 @@ namespace Bottom.UnitTest
[TestClass]
public class UnitTests
{
[TestMethod]
public void TestIsCharacterValueGroup()
{
Assert.AreEqual(
true,
Bottomify.IsCharacterValueGroup("πŸ’–πŸ’–,,,,πŸ‘‰πŸ‘ˆ")
);
Assert.AreEqual(
false,
Bottomify.IsCharacterValueGroup("πŸ’–βœ¨βœ¨βœ¨,,,,\u200BπŸ’–πŸ’–,\u200BπŸ’–πŸ’–βœ¨πŸ₯Ί\u200BπŸ’–πŸ’–βœ¨πŸ₯Ί,\u200B")
);
Assert.AreEqual(
true,
Bottomify.IsCharacterValueGroup("hello")
);
}

[TestMethod]
public void TestIsEncoded()
{
Assert.AreEqual(
true,
Bottomify.IsEncoded("πŸ’–βœ¨βœ¨βœ¨,,,,\u200BπŸ’–πŸ’–,\u200BπŸ’–πŸ’–βœ¨πŸ₯Ί\u200BπŸ’–πŸ’–βœ¨πŸ₯Ί,\u200B")
);
Assert.AreEqual(
false,
Bottomify.IsEncoded("Hello")
);
}

[TestMethod]
public void TestStringEncode()
{
Assert.AreEqual(
Bottomify.encode_string("Test"),
"πŸ’–βœ¨βœ¨βœ¨,,,,πŸ‘‰πŸ‘ˆπŸ’–πŸ’–,πŸ‘‰πŸ‘ˆπŸ’–πŸ’–βœ¨πŸ₯ΊπŸ‘‰πŸ‘ˆπŸ’–πŸ’–βœ¨πŸ₯Ί,πŸ‘‰πŸ‘ˆ"
"πŸ’–βœ¨βœ¨βœ¨,,,,πŸ‘‰πŸ‘ˆπŸ’–πŸ’–,πŸ‘‰πŸ‘ˆπŸ’–πŸ’–βœ¨πŸ₯ΊπŸ‘‰πŸ‘ˆπŸ’–πŸ’–βœ¨πŸ₯Ί,πŸ‘‰πŸ‘ˆ",
Bottomify.EncodeString("Test")
);
}

[TestMethod]
public void TestByteEncode()
{
Assert.AreEqual(
Bottomify.encode_byte((byte)'h'),
"πŸ’–πŸ’–,,,,πŸ‘‰πŸ‘ˆ"
"πŸ’–πŸ’–,,,,πŸ‘‰πŸ‘ˆ",
Bottomify.EncodeByte((byte)'h')
);
}

[TestMethod]
public void TestByteDecode()
public void TestCharacterValueGroupDecode()
{
Assert.AreEqual(
Bottomify.decode_byte("πŸ’–πŸ’–,,,,"),
(byte)'h'
(byte)'h',
Bottomify.DecodeCharacterValueGroup("πŸ’–πŸ’–,,,,πŸ‘‰πŸ‘ˆ")
);
Assert.AreEqual(
(byte)'a',
Bottomify.DecodeCharacterValueGroup("πŸ’–βœ¨βœ¨βœ¨βœ¨,,,,,,,πŸ‘‰πŸ‘ˆ")
);
}

[TestMethod]
public void TestStringDecode()
{
Assert.AreEqual(
Bottomify.decode_string("πŸ’–βœ¨βœ¨βœ¨,,,,\u200BπŸ’–πŸ’–,\u200BπŸ’–πŸ’–βœ¨πŸ₯Ί\u200BπŸ’–πŸ’–βœ¨πŸ₯Ί,\u200B"),
"Test"
"Test",
Bottomify.DecodeString("πŸ’–βœ¨βœ¨βœ¨,,,,\u200BπŸ’–πŸ’–,\u200BπŸ’–πŸ’–βœ¨πŸ₯Ί\u200BπŸ’–πŸ’–βœ¨πŸ₯Ί,\u200B")
);
Assert.AreEqual(
Bottomify.decode_string("πŸ’–βœ¨βœ¨βœ¨,,,,πŸ‘‰πŸ‘ˆπŸ’–πŸ’–,πŸ‘‰πŸ‘ˆπŸ’–πŸ’–βœ¨πŸ₯ΊπŸ‘‰πŸ‘ˆπŸ’–πŸ’–βœ¨πŸ₯Ί,πŸ‘‰πŸ‘ˆ"),
"Test"
"Test",
Bottomify.DecodeString("πŸ’–βœ¨βœ¨βœ¨,,,,πŸ‘‰πŸ‘ˆπŸ’–πŸ’–,πŸ‘‰πŸ‘ˆπŸ’–πŸ’–βœ¨πŸ₯ΊπŸ‘‰πŸ‘ˆπŸ’–πŸ’–βœ¨πŸ₯Ί,πŸ‘‰πŸ‘ˆ")
);
}

[TestMethod]
public void TestUnicodeStringEncode()
{
Assert.AreEqual(
Bottomify.encode_string("πŸ₯Ί"),
"πŸ«‚βœ¨βœ¨βœ¨βœ¨πŸ‘‰πŸ‘ˆπŸ’–πŸ’–πŸ’–πŸ₯Ί,,,,πŸ‘‰πŸ‘ˆπŸ’–πŸ’–πŸ’–βœ¨πŸ₯ΊπŸ‘‰πŸ‘ˆπŸ’–πŸ’–πŸ’–βœ¨βœ¨βœ¨πŸ₯Ί,πŸ‘‰πŸ‘ˆ"
"πŸ«‚βœ¨βœ¨βœ¨βœ¨πŸ‘‰πŸ‘ˆπŸ’–πŸ’–πŸ’–πŸ₯Ί,,,,πŸ‘‰πŸ‘ˆπŸ’–πŸ’–πŸ’–βœ¨πŸ₯ΊπŸ‘‰πŸ‘ˆπŸ’–πŸ’–πŸ’–βœ¨βœ¨βœ¨πŸ₯Ί,πŸ‘‰πŸ‘ˆ",
Bottomify.EncodeString("πŸ₯Ί")
);
Assert.AreEqual(
Bottomify.encode_string("γŒγ‚“γ°γ‚Œ"),
"πŸ«‚βœ¨βœ¨πŸ₯Ί,,πŸ‘‰πŸ‘ˆπŸ’–πŸ’–βœ¨βœ¨πŸ₯Ί,,,,πŸ‘‰πŸ‘ˆπŸ’–πŸ’–βœ¨βœ¨βœ¨βœ¨πŸ‘‰πŸ‘ˆπŸ«‚βœ¨βœ¨πŸ₯Ί,,πŸ‘‰πŸ‘ˆ" +
"πŸ’–πŸ’–βœ¨βœ¨βœ¨πŸ‘‰πŸ‘ˆπŸ’–πŸ’–βœ¨βœ¨βœ¨βœ¨πŸ₯Ί,,πŸ‘‰πŸ‘ˆπŸ«‚βœ¨βœ¨πŸ₯Ί,,πŸ‘‰πŸ‘ˆπŸ’–πŸ’–βœ¨βœ¨πŸ₯Ί,,,,πŸ‘‰πŸ‘ˆ" +
"πŸ’–πŸ’–πŸ’–βœ¨βœ¨πŸ₯Ί,πŸ‘‰πŸ‘ˆπŸ«‚βœ¨βœ¨πŸ₯Ί,,πŸ‘‰πŸ‘ˆπŸ’–πŸ’–βœ¨βœ¨βœ¨πŸ‘‰πŸ‘ˆπŸ’–πŸ’–βœ¨βœ¨βœ¨βœ¨πŸ‘‰πŸ‘ˆ"
"πŸ’–πŸ’–πŸ’–βœ¨βœ¨πŸ₯Ί,πŸ‘‰πŸ‘ˆπŸ«‚βœ¨βœ¨πŸ₯Ί,,πŸ‘‰πŸ‘ˆπŸ’–πŸ’–βœ¨βœ¨βœ¨πŸ‘‰πŸ‘ˆπŸ’–πŸ’–βœ¨βœ¨βœ¨βœ¨πŸ‘‰πŸ‘ˆ",
Bottomify.EncodeString("γŒγ‚“γ°γ‚Œ")
);
}

[TestMethod]
public void TestUnicodeStringDecode()
{
Assert.AreEqual(
Bottomify.decode_string("πŸ«‚βœ¨βœ¨βœ¨βœ¨πŸ‘‰πŸ‘ˆπŸ’–πŸ’–πŸ’–πŸ₯Ί,,,,πŸ‘‰πŸ‘ˆπŸ’–πŸ’–πŸ’–βœ¨πŸ₯ΊπŸ‘‰πŸ‘ˆπŸ’–πŸ’–πŸ’–βœ¨βœ¨βœ¨πŸ₯Ί,πŸ‘‰πŸ‘ˆ"),
"πŸ₯Ί"
"πŸ₯Ί",
Bottomify.DecodeString("πŸ«‚βœ¨βœ¨βœ¨βœ¨πŸ‘‰πŸ‘ˆπŸ’–πŸ’–πŸ’–πŸ₯Ί,,,,πŸ‘‰πŸ‘ˆπŸ’–πŸ’–πŸ’–βœ¨πŸ₯ΊπŸ‘‰πŸ‘ˆπŸ’–πŸ’–πŸ’–βœ¨βœ¨βœ¨πŸ₯Ί,πŸ‘‰πŸ‘ˆ")
);
Assert.AreEqual(
Bottomify.decode_string(
"γŒγ‚“γ°γ‚Œ",
Bottomify.DecodeString(
"πŸ«‚βœ¨βœ¨πŸ₯Ί,,πŸ‘‰πŸ‘ˆπŸ’–πŸ’–βœ¨βœ¨πŸ₯Ί,,,,πŸ‘‰πŸ‘ˆπŸ’–πŸ’–βœ¨βœ¨βœ¨βœ¨πŸ‘‰πŸ‘ˆπŸ«‚βœ¨βœ¨πŸ₯Ί,,πŸ‘‰πŸ‘ˆ" +
"πŸ’–πŸ’–βœ¨βœ¨βœ¨πŸ‘‰πŸ‘ˆπŸ’–πŸ’–βœ¨βœ¨βœ¨βœ¨πŸ₯Ί,,πŸ‘‰πŸ‘ˆπŸ«‚βœ¨βœ¨πŸ₯Ί,,πŸ‘‰πŸ‘ˆπŸ’–πŸ’–βœ¨βœ¨πŸ₯Ί,,,,πŸ‘‰πŸ‘ˆ" +
"πŸ’–πŸ’–πŸ’–βœ¨βœ¨πŸ₯Ί,πŸ‘‰πŸ‘ˆπŸ«‚βœ¨βœ¨πŸ₯Ί,,πŸ‘‰πŸ‘ˆπŸ’–πŸ’–βœ¨βœ¨βœ¨πŸ‘‰πŸ‘ˆπŸ’–πŸ’–βœ¨βœ¨βœ¨βœ¨πŸ‘‰πŸ‘ˆ"
),
"γŒγ‚“γ°γ‚Œ"
)
);
}
}
Expand Down
Loading

0 comments on commit f96343a

Please sign in to comment.