Skip to content
This repository was archived by the owner on Sep 29, 2023. It is now read-only.

Commit 6241dec

Browse files
~Ran unit tests project against ReSharper
1 parent 20b89bb commit 6241dec

File tree

10 files changed

+103
-160
lines changed

10 files changed

+103
-160
lines changed

net-solution/PalindromePartitions.Tests/Common/AlgorithmContents.cs

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using NUnit.Framework;
33
using System.Collections.Generic;
4-
using PalindromePartitions.Classes;
54

65
namespace PalindromePartitions.Tests.Common
76
{
@@ -18,27 +17,23 @@ public static void CheckResults(List<string> expStrList, List<string> actStrList
1817

1918
// Result comparison loop.
2019
private static void LoopComparison(List<string> expList, List<string> actList)
21-
{
22-
int loopIndex = 0;
23-
string currentActualString = "";
24-
bool currentUnique = false;
25-
bool currentExpectFound = false;
26-
27-
bool canContinue = true;
20+
{
21+
int loopIndex = 0;
22+
bool canContinue = true;
2823

29-
while (loopIndex >= 0 && loopIndex < actList.Count && canContinue == true)
24+
while (loopIndex >= 0 && loopIndex < actList.Count && canContinue)
3025
{
3126
// Validate actual output string.
32-
currentActualString = actList[loopIndex];
33-
currentUnique = CheckUnique(currentActualString, actList, loopIndex);
34-
currentExpectFound = FindExpected(currentActualString, expList);
27+
string currentActualString = actList[loopIndex];
28+
bool currentUnique = CheckUnique(currentActualString, actList, loopIndex);
29+
bool currentExpectFound = FindExpected(currentActualString, expList);
3530

36-
if (currentUnique == true && currentExpectFound == true)
31+
if (currentUnique && currentExpectFound)
3732
{
3833
// Match found.
39-
loopIndex = loopIndex + 1;
40-
}
41-
else if (currentUnique == true)
34+
loopIndex++;
35+
}
36+
else if (currentUnique)
4237
{
4338
// Result not allowed.
4439
canContinue = false;
@@ -63,7 +58,7 @@ private static bool CheckUnique(string tgtString, List<string> strList, int orig
6358
if (matchIndex >= 0 && matchIndex > originPoint && matchIndex < strList.Count)
6459
{
6560
// Duplicate found.
66-
uniqueRes = true;
61+
uniqueRes = false;
6762
}
6863

6964
return uniqueRes;
Lines changed: 22 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System;
21
using System.Collections.Generic;
32

43
namespace PalindromePartitions.Tests.Common
@@ -7,14 +6,14 @@ namespace PalindromePartitions.Tests.Common
76
public class AlgorithmTestData
87
{
98
// Private properties - Input
10-
private static string pGeeksInput = "geeks";
11-
private static string pLettersInput = "aab";
12-
private static string pCustomInput = "thequickbrownfoxnamedottojumpsoverthelazytacocatlastnight";
9+
private static readonly string GeeksInput = "geeks";
10+
private static readonly string LettersInput = "aab";
11+
private static readonly string CustomInput = "thequickbrownfoxnamedottojumpsoverthelazytacocatlastnight";
1312

1413
// Private properties - Output
15-
private static List<string> pGeeksOutput = DefineGeeksExpect();
16-
private static List<string> pLettersOutput = DefineLettersExpect();
17-
private static List<string> pCustomOutput = DefineCustomExpect();
14+
private static readonly List<string> GeeksOutput = DefineGeeksExpect();
15+
private static readonly List<string> LettersOutput = DefineLettersExpect();
16+
private static readonly List<string> CustomOutput = DefineCustomExpect();
1817

1918

2019
// Function writes expexted 'Geeks' output.
@@ -60,40 +59,21 @@ private static List<string> DefineCustomExpect()
6059

6160

6261
// Public 'Geeks' input property.
63-
public static string geeksInput
64-
{
65-
get {return pGeeksInput;}
66-
}
67-
68-
// Public 'Letters' input property.
69-
public static string lettersInput
70-
{
71-
get {return pLettersInput;}
72-
}
73-
74-
// Public 'Custom' input property.
75-
public static string customInput
76-
{
77-
get {return pCustomInput;}
78-
}
79-
80-
// Public 'Geeks' output property.
81-
public static List<string> geeksOutput
82-
{
83-
get {return pGeeksOutput;}
84-
}
85-
86-
// Public 'Letters' output property.
87-
public static List<string> lettersOutput
88-
{
89-
get {return pLettersOutput;}
90-
}
91-
92-
// Public 'Custom' output property.
93-
public static List<string> customOutput
94-
{
95-
get {return pCustomOutput;}
96-
}
97-
62+
public static string geeksInput => GeeksInput;
63+
64+
// Public 'Letters' input property.
65+
public static string lettersInput => LettersInput;
66+
67+
// Public 'Custom' input property.
68+
public static string customInput => CustomInput;
69+
70+
// Public 'Geeks' output property.
71+
public static List<string> geeksOutput => GeeksOutput;
72+
73+
// Public 'Letters' output property.
74+
public static List<string> lettersOutput => LettersOutput;
75+
76+
// Public 'Custom' output property.
77+
public static List<string> customOutput => CustomOutput;
9878
}
9979
}

net-solution/PalindromePartitions.Tests/Common/InvalidCalls.cs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,13 @@ public class InvalidCalls
1313
public static TryCatchResult ArgumentValidationPopulated(string entryValue)
1414
{
1515
string[] givenArgs = new string[1];
16-
string extractedValue = "";
17-
bool textValid = false;
16+
bool textValid;
1817
string excMsg = "";
1918

2019
try
2120
{
2221
givenArgs[0] = entryValue;
23-
extractedValue = InputArg.ReadInputText(givenArgs);
22+
string extractedValue = InputArg.ReadInputText(givenArgs);
2423
textValid = InputArg.ValidateInputText(ref extractedValue);
2524

2625
}
@@ -38,14 +37,13 @@ public static TryCatchResult ArgumentValidationPopulated(string entryValue)
3837
// Input argument validation - Empty.
3938
public static TryCatchResult ArgumentValidationEmpty()
4039
{
41-
string[] emptyArr = new string[0];
42-
string readString = "";
43-
bool emptyValid = false;
40+
bool emptyValid;
4441
string excMsg = "";
4542

4643
try
4744
{
48-
readString = InputArg.ReadInputText(emptyArr);
45+
string[] emptyArr = new string[0];
46+
string readString = InputArg.ReadInputText(emptyArr);
4947
emptyValid = InputArg.ValidateInputText(ref readString);
5048
}
5149
catch (Exception flaggedError)
@@ -61,8 +59,8 @@ public static TryCatchResult ArgumentValidationEmpty()
6159

6260
// Slice partition.
6361
public static TryCatchResult PartitionSlice(Partition entryObj, int inpStart, int inpLength)
64-
{
65-
bool sliceValid = false;
62+
{
63+
bool sliceValid;
6664
string excMsg = "";
6765

6866
try
@@ -83,8 +81,8 @@ public static TryCatchResult PartitionSlice(Partition entryObj, int inpStart, in
8381

8482
// Merge partition substrings.
8583
public static TryCatchResult PartitionMerge(Partition entryObj, int inpStart, int inpEnd)
86-
{
87-
bool mergeValid = false;
84+
{
85+
bool mergeValid;
8886
string excMsg = "";
8987

9088
try

net-solution/PalindromePartitions.Tests/Common/LongString.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,17 @@ namespace PalindromePartitions.Tests.Common
55
// Class used to write really long string for input validation.
66
public class LongString
77
{
8-
private static Random randGen = new Random();
8+
private static readonly Random RandGen = new Random();
99

1010
public static string Write()
1111
{
1212
string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
13-
int randomIndex = -1;
1413
string textRes = "";
1514

1615
while (textRes.Length < 105)
1716
{
1817
// Adds random letter.
19-
randomIndex = randGen.Next(alphabet.Length);
18+
int randomIndex = RandGen.Next(alphabet.Length);
2019
textRes += alphabet[randomIndex].ToString();
2120
}
2221

net-solution/PalindromePartitions.Tests/Common/PartitionContents.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,14 @@ public static string Check(Partition resObj)
3030
public static void CompareInitializedConstructor(ref string origStr, Partition resObj)
3131
{
3232
int loopIndex = 0;
33-
string currentChar = "";
34-
string currentSubstring = "";
35-
36-
bool compMatch = true;
33+
bool compMatch = true;
3734

3835
// Loop original strng characters.
39-
while (loopIndex >= 0 && loopIndex < origStr.Length && compMatch == true)
36+
while (loopIndex >= 0 && loopIndex < origStr.Length && compMatch)
4037
{
4138
// Read both character and substring.
42-
currentChar = origStr[loopIndex].ToString();
43-
currentSubstring = resObj.GetSubstring(loopIndex);
39+
string currentChar = origStr[loopIndex].ToString();
40+
string currentSubstring = resObj.GetSubstring(loopIndex);
4441

4542
if (currentChar == currentSubstring)
4643
{

net-solution/PalindromePartitions.Tests/Common/PartitionReduce.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System;
21
using System.Collections.Generic;
32
using PalindromePartitions.Classes;
43

@@ -9,17 +8,13 @@ public class PartitionReduce
98
{
109
public static List<string> Loop(List<Partition> resObj)
1110
{
12-
int loopIndex = 0;
13-
Partition currentPartition = Partition.Empty();
14-
string currentString = "";
11+
List<string> reduceRes = new List<string>();
1512

16-
List<string> reduceRes = new List<string>();
17-
18-
for (loopIndex = 0; loopIndex < resObj.Count; loopIndex = loopIndex + 1)
13+
for (int loopIndex = 0; loopIndex < resObj.Count; loopIndex++)
1914
{
2015
// Join partition substrings together.
21-
currentPartition = resObj[loopIndex];
22-
currentString = currentPartition.Join();
16+
Partition currentPartition = resObj[loopIndex];
17+
string currentString = currentPartition.Join();
2318
reduceRes.Add(currentString);
2419
}
2520

net-solution/PalindromePartitions.Tests/Common/SchemaValidation.cs

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
using System;
22
using System.Reflection;
3-
using System.Collections.Generic;
4-
using NUnit.Framework;
5-
using PalindromePartitions.Classes;
63

74
namespace PalindromePartitions.Tests.Common
85
{
@@ -68,7 +65,7 @@ private static void ThrowPropertyNotFound(string vBase, string vName)
6865

6966
errTxt += vBase;
7067
errTxt += " does not have a property named ";
71-
errTxt += quoteName(vName);
68+
errTxt += QuoteName(vName);
7269

7370
throw new Exception(errTxt);
7471
}
@@ -83,7 +80,7 @@ private static void ThrowMethodNotFound(string vBase, string vName, bool vStatic
8380
errTxt += " does not have a ";
8481
errTxt += WriteMethodType(vStatic);
8582
errTxt += "named ";
86-
errTxt += quoteName(vName);
83+
errTxt += QuoteName(vName);
8784

8885
throw new Exception(errTxt);
8986
}
@@ -95,7 +92,7 @@ private static void ThrowIncorrectPropertyType(string vBase, string vName, strin
9592

9693
errTxt += vBase;
9794
errTxt += " property ";
98-
errTxt += quoteName(vName);
95+
errTxt += QuoteName(vName);
9996
errTxt += " must be a valid ";
10097
errTxt += vType;
10198

@@ -109,7 +106,7 @@ private static void ThrowIncorrectReturnType(string vBase, string vName, string
109106

110107
errTxt += vBase;
111108
errTxt += WriteMethodType(vStatic);
112-
errTxt += quoteName(vName);
109+
errTxt += QuoteName(vName);
113110
errTxt += " does not return a ";
114111
errTxt += vType;
115112
errTxt += " value";
@@ -121,21 +118,15 @@ private static void ThrowIncorrectReturnType(string vBase, string vName, string
121118
private static string WriteMethodType(bool stc)
122119
{
123120
string writeRes = " method ";
124-
125-
if (stc == true)
126-
{
127-
writeRes = " static method ";
128-
}
129-
130-
return writeRes;
121+
if (stc) writeRes = " static method ";
122+
return writeRes;
131123
}
132124

133125
// Writes quoted name into error text.
134-
private static string quoteName(string nTxt)
126+
private static string QuoteName(string nTxt)
135127
{
136-
string quoteRes = "'" + nTxt + "'";
137-
return quoteRes;
138-
}
128+
return "'" + nTxt + "'";
129+
}
139130

140131
}
141132
}

net-solution/PalindromePartitions.Tests/FullAlgorithmTests.cs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@ public void FunctionExists()
2323
public void Geeks()
2424
{
2525
List<Partition> testOutcome = CallAlgorithm(AlgorithmTestData.geeksInput);
26-
List<string> resultStrings = new List<string>();
27-
28-
CheckResultObject(testOutcome, 2);
29-
resultStrings = PartitionReduce.Loop(testOutcome);
26+
27+
CheckResultObject(testOutcome, 2);
28+
List<string> resultStrings = PartitionReduce.Loop(testOutcome);
3029
AlgorithmContents.CheckResults(AlgorithmTestData.geeksOutput, resultStrings);
3130
}
3231

@@ -35,10 +34,9 @@ public void Geeks()
3534
public void Letters()
3635
{
3736
List<Partition> testOutcome = CallAlgorithm(AlgorithmTestData.lettersInput);
38-
List<string> resultStrings = new List<string>();
39-
40-
CheckResultObject(testOutcome, 2);
41-
resultStrings = PartitionReduce.Loop(testOutcome);
37+
38+
CheckResultObject(testOutcome, 2);
39+
List<string> resultStrings = PartitionReduce.Loop(testOutcome);
4240
AlgorithmContents.CheckResults(AlgorithmTestData.lettersOutput, resultStrings);
4341
}
4442

@@ -47,10 +45,9 @@ public void Letters()
4745
public void Custom()
4846
{
4947
List<Partition> testOutcome = CallAlgorithm(AlgorithmTestData.customInput);
50-
List<string> resultStrings = new List<string>();
51-
52-
CheckResultObject(testOutcome, 12);
53-
resultStrings = PartitionReduce.Loop(testOutcome);
48+
49+
CheckResultObject(testOutcome, 12);
50+
List<string> resultStrings = PartitionReduce.Loop(testOutcome);
5451
AlgorithmContents.CheckResults(AlgorithmTestData.customOutput, resultStrings);
5552
}
5653

@@ -61,7 +58,7 @@ private static List<Partition> CallAlgorithm(string algoInput)
6158
bool inputStringValid = InputArg.ValidateInputText(ref algoInput);
6259
List<Partition> resultList = new List<Partition>();
6360

64-
if (inputStringValid == true)
61+
if (inputStringValid)
6562
{
6663
resultList = AlgorithmResults.InitializeList(ref algoInput);
6764
StringPartitioning.RunLoop(resultList);

0 commit comments

Comments
 (0)