Skip to content

Commit 782ccf4

Browse files
committed
Clearing code
1 parent 76905ca commit 782ccf4

5 files changed

Lines changed: 24 additions & 15 deletions

File tree

AlgorithmsLibrary/ArithmeticCodingAlgm/ArithmeticCodingAlgm.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public static IAlgmEncoded<string, IAlgmEncoded<int, Dictionary<char, int>>> Enc
4848
{
4949
List<Symbol> codes = GetSymbolsRanges(source);
5050
decimal HighRange = 1, LowRange = 0, h, l;
51-
51+
5252
StringBuilder TheImmutablePart = new StringBuilder();
5353

5454
foreach (char c in source)
@@ -98,8 +98,8 @@ private static void DiscardTheImmutablePart(ref StringBuilder theImmutablePart,
9898
{
9999
string lr = lowRange.ToString();
100100
string hr = highRange.ToString();
101-
int i=0;
102-
while (i<lr.Length && i<hr.Length && lr[i]==hr[i])
101+
int i = 0;
102+
while (i < lr.Length && i < hr.Length && lr[i] == hr[i])
103103
{
104104
if (!((i == 0 && lr[i] == '0') || lr[i] == ','))
105105
{
@@ -111,21 +111,21 @@ private static void DiscardTheImmutablePart(ref StringBuilder theImmutablePart,
111111
}
112112
}
113113

114-
private static void DiscardTheImmutablePart(ref decimal highRange, ref decimal lowRange, ref decimal code, ref int index, string encoded,
114+
private static void DiscardTheImmutablePart(ref decimal highRange, ref decimal lowRange, ref decimal code, ref int index, string encoded,
115115
ref bool thePreviousDigitIsZero, ref int CntOfZero)
116116
{
117117
string lr = lowRange.ToString();
118118
string hr = highRange.ToString();
119119
string c = code.ToString();
120120
int i = 0, encodedLength = encoded.Length;
121-
while (i < lr.Length && i < hr.Length && i < c.Length && lr[i] == hr[i] && lr[i]==c[i])
121+
while (i < lr.Length && i < hr.Length && i < c.Length && lr[i] == hr[i] && lr[i] == c[i])
122122
{
123123
if (!((i == 0 && lr[i] == '0') || lr[i] == ','))
124124
{
125125
highRange *= 10; highRange -= (int)highRange % 10;
126126
lowRange *= 10; lowRange -= (int)lowRange % 10;
127-
code = Convert.ToDecimal("0," + (index<encodedLength?encoded.Substring(index, Math.Min(28, encodedLength - index)):"0" ));
128-
index++;
127+
code = Convert.ToDecimal("0," + (index < encodedLength ? encoded.Substring(index, Math.Min(28, encodedLength - index)) : "0"));
128+
index++;
129129
}
130130
i++;
131131
}

AlgorithmsLibrary/Extensions/StringBuilderExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public static string Substring(this StringBuilder @this, int startpos, int lengt
2121
stringBuilder.Append(@this[i]);
2222
}
2323
return stringBuilder.ToString();
24-
//@this.ToString().Substring(startpos, length);
24+
//@this.ToString().Substring(startpos, length);
2525
}
2626

2727
public static int IndexOf(this StringBuilder haystack, string needle)

AlgorithmsLibrary/LZ78Algm/LZ78Algm.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.Linq;
55
using System.Text;
66
using System.Text.RegularExpressions;
7-
using System.Threading.Tasks;
87

98
namespace AlgorithmsLibrary
109
{

AlgorithmsLibrary/LZ78Algm/LZ78CodeBlock.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class LZ78CodeBlock : IEquatable<LZ78CodeBlock>
1010
public LZ78CodeBlock(int Position, char Char)
1111
{
1212
this.Position = Position;
13-
this.Char = Char;
13+
this.Char = Char;
1414
}
1515

1616
public override string ToString()

UnitTestProject/LZ78AlgmUnitTest.cs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
using AlgorithmsLibrary;
2-
using System;
2+
using AlgorithmsLibrary.CommonClasses;
33
using System.Collections.Generic;
4-
using System.Linq;
5-
using System.Text;
6-
using System.Threading.Tasks;
74
using Xunit;
85

96
namespace UnitTestProject
107
{
118
public class LZ78AlgmUnitTest
129
{
10+
[Fact]
11+
public void EncodingEmptyString()
12+
{
13+
var result = LZ78Algm.Encode("");
14+
var expected = new List<LZ78CodeBlock> { };
15+
16+
Assert.Equal(expected, result.GetAnswer());
17+
}
18+
[Fact]
19+
public void DecodingEmptyString()
20+
{
21+
Assert.Throws<CodingException>(() => LZ78Algm.Decode(string.Empty));
22+
}
1323
[Fact]
1424
public void EncodeStringWithRepeatsLongString()
1525
{
@@ -31,7 +41,7 @@ public void EncodeStringWithRepeatsLongString()
3141

3242
Assert.Equal(expectedCodeBlocks, result.GetAnswer());
3343
}
34-
44+
3545
[Fact]
3646
public void DecodedStringWithRepeatsLongString()
3747
{

0 commit comments

Comments
 (0)