Skip to content

Commit d3e2a07

Browse files
1fisedisiriak
authored andcommitted
Tests for lcc (#66)
* Tests for Lcc * Renaming LCC class as GeneralStringAlgorithms, mods on test.
1 parent c0ce450 commit d3e2a07

File tree

2 files changed

+45
-10
lines changed

2 files changed

+45
-10
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System;
2+
using Algorithms.Strings;
3+
using NUnit.Framework;
4+
5+
namespace Algorithms.Tests.Strings
6+
{
7+
public class GeneralStringAlgorithmsTests
8+
{
9+
[Test]
10+
[Parallelizable]
11+
public void MaxCountCharIsObtained()
12+
{
13+
// Arrange
14+
const string input = "Griffith";
15+
const string input2 = "Randomwoooord";
16+
const string input3 = "Control";
17+
18+
// Act
19+
var (rChar, rMax) = GeneralStringAlgorithms.FindLongestConsecutiveCharacters(input);
20+
var (rChar2, rMax2) = GeneralStringAlgorithms.FindLongestConsecutiveCharacters(input2);
21+
var (rChar3, rMax3) = GeneralStringAlgorithms.FindLongestConsecutiveCharacters(input3);
22+
23+
// Assert
24+
Assert.NotNull(rChar);
25+
Assert.NotNull(rChar2);
26+
Assert.NotNull(rChar3);
27+
28+
Assert.AreEqual('f', rChar);
29+
Assert.AreEqual(2, rMax);
30+
31+
Assert.AreEqual('o', rChar2);
32+
Assert.AreEqual(4, rMax2);
33+
34+
Assert.AreEqual('C', rChar3);
35+
Assert.AreEqual(1, rMax3);
36+
}
37+
}
38+
}
Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
using System;
22

3-
namespace Example
3+
namespace Algorithms.Strings
44
{
5-
public static partial class StringViewModel
5+
public static class GeneralStringAlgorithms
66
{
7-
8-
public static Tuple<char, int> LongesConsecutiveCharacters(string input)
7+
public static Tuple<char, int> FindLongestConsecutiveCharacters(string input)
98
{
10-
var max_char = input[0];
9+
var maxChar = input[0];
1110

1211
var max = 1;
1312
var current = 1;
@@ -20,7 +19,7 @@ public static Tuple<char, int> LongesConsecutiveCharacters(string input)
2019
if (current > max)
2120
{
2221
max = current;
23-
max_char = input[i];
22+
maxChar = input[i];
2423
}
2524
}
2625
else
@@ -29,9 +28,7 @@ public static Tuple<char, int> LongesConsecutiveCharacters(string input)
2928
}
3029
}
3130

32-
return new Tuple<char, int>(max_char, max);
31+
return new Tuple<char, int>(maxChar, max);
3332
}
34-
35-
3633
}
37-
}
34+
}

0 commit comments

Comments
 (0)