Skip to content

Commit

Permalink
Added more unit tests (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sandoun committed Jun 18, 2023
1 parent 431c589 commit 62bb1b4
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 14 deletions.
16 changes: 4 additions & 12 deletions MewtocolNet/Mewtocol/MewtocolHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,9 @@ internal static string BuildBCCFrame (this string asciiArr) {

}

internal static byte[] ParseDTBytes (this string _onString ,int _blockSize = 4) {

var res = new Regex(@"\%([0-9]{2})\$RD(.{"+_blockSize+"})").Match(_onString);
if(res.Success) {
string val = res.Groups[2].Value;
return val.HexStringToByteArray();
}
return null;

}

/// <summary>
/// Parses the byte string from a incoming RD message
/// </summary>
internal static string ParseDTByteString (this string _onString, int _blockSize = 4) {

if (_onString == null)
Expand All @@ -71,7 +63,7 @@ internal static string ParseDTByteString (this string _onString, int _blockSize

}

internal static bool? ParseRCSingleBit (this string _onString, int _blockSize = 4) {
internal static bool? ParseRCSingleBit (this string _onString) {

var res = new Regex(@"\%([0-9]{2})\$RC(.)").Match(_onString);
if (res.Success) {
Expand Down
39 changes: 37 additions & 2 deletions MewtocolTests/TestHelperExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void ToBitStringGeneration () {
}

[Fact(DisplayName = nameof(MewtocolHelpers.ToHexString))]
public void ToHexStringGeneration() {
public void ToHexStringGeneration () {

var bytes = new byte[6] {
0x10,
Expand All @@ -47,7 +47,7 @@ public void ToHexStringGeneration() {
}

[Fact(DisplayName = nameof(MewtocolHelpers.ToHexASCIIBytes))]
public void ToHexASCIIBytesGeneration() {
public void ToHexASCIIBytesGeneration () {

string test = "Hello, world!";

Expand All @@ -69,6 +69,41 @@ public void ToHexASCIIBytesGeneration() {

}

[Fact(DisplayName = nameof(MewtocolHelpers.BuildBCCFrame))]
public void BuildBCCFrameGeneration () {

string test = "%01#RCSX0000";
string expect = "%01#RCSX00001D";

Assert.Equal(expect, test.BuildBCCFrame());

}

[Fact(DisplayName = nameof(MewtocolHelpers.ParseDTByteString))]
public void ParseDTByteStringGeneration () {

var testList = new List<string>() {
"1112",
"1C2C",
"FFFF",
};

foreach (var item in testList) {

Assert.Equal(item, $"%01$RD{item}".BuildBCCFrame().ParseDTByteString());

}

}

[Fact(DisplayName = nameof(MewtocolHelpers.ParseRCSingleBit))]
public void ParseRCSingleBitGeneration () {

Assert.True($"%01$RC1".BuildBCCFrame().ParseRCSingleBit());
Assert.False($"%01$RC0".BuildBCCFrame().ParseRCSingleBit());

}

}

}

0 comments on commit 62bb1b4

Please sign in to comment.