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

Commit cc8c62d

Browse files
Removed schema validation for unit tests
1 parent 6241dec commit cc8c62d

File tree

7 files changed

+13
-202
lines changed

7 files changed

+13
-202
lines changed
Lines changed: 2 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -1,132 +1,8 @@
1-
using System;
2-
using System.Reflection;
3-
41
namespace PalindromePartitions.Tests.Common
52
{
6-
// Functions used to validate class schema.
3+
74
public class SchemaValidation
85
{
9-
10-
// Check if property exists.
11-
public static bool CheckProperty(Type baseClass, string propName, Type propType)
12-
{
13-
PropertyInfo infoObj = baseClass.GetProperty(propName);
14-
bool propValid = false;
15-
16-
if (infoObj != null && infoObj.PropertyType == propType)
17-
{
18-
// Valid.
19-
propValid = true;
20-
}
21-
else if (infoObj != null)
22-
{
23-
// Incorrect type.
24-
ThrowIncorrectPropertyType(baseClass.Name, propName, propType.Name);
25-
}
26-
else
27-
{
28-
// Not found.
29-
ThrowPropertyNotFound(baseClass.Name, propName);
30-
}
31-
32-
return propValid;
33-
}
34-
35-
// Check if method exists, static or otherwise.
36-
public static bool CheckMethod(Type baseClass, string methodName, Type methodReturnType, bool methodStatic)
37-
{
38-
MethodInfo infoObj = baseClass.GetMethod(methodName);
39-
bool methodValid = false;
40-
41-
if (infoObj != null && infoObj.ReturnType == methodReturnType)
42-
{
43-
// Valid.
44-
methodValid = true;
45-
}
46-
else if (infoObj != null)
47-
{
48-
// Incorrect type.
49-
ThrowIncorrectReturnType(baseClass.Name, methodName, methodReturnType.Name, methodStatic);
50-
}
51-
else
52-
{
53-
// Not found.
54-
ThrowMethodNotFound(baseClass.Name, methodName, methodStatic);
55-
}
56-
57-
return methodValid;
58-
}
59-
60-
61-
// 'Property not found' error.
62-
private static void ThrowPropertyNotFound(string vBase, string vName)
63-
{
64-
string errTxt = "";
65-
66-
errTxt += vBase;
67-
errTxt += " does not have a property named ";
68-
errTxt += QuoteName(vName);
69-
70-
throw new Exception(errTxt);
71-
}
72-
73-
74-
// 'Method not found' error.
75-
private static void ThrowMethodNotFound(string vBase, string vName, bool vStatic)
76-
{
77-
string errTxt = "";
78-
79-
errTxt += vBase;
80-
errTxt += " does not have a ";
81-
errTxt += WriteMethodType(vStatic);
82-
errTxt += "named ";
83-
errTxt += QuoteName(vName);
84-
85-
throw new Exception(errTxt);
86-
}
87-
88-
// 'Incorrect property type' error.
89-
private static void ThrowIncorrectPropertyType(string vBase, string vName, string vType)
90-
{
91-
string errTxt = "";
92-
93-
errTxt += vBase;
94-
errTxt += " property ";
95-
errTxt += QuoteName(vName);
96-
errTxt += " must be a valid ";
97-
errTxt += vType;
98-
99-
throw new Exception(errTxt);
100-
}
101-
102-
// 'Incorrect return type' error.
103-
private static void ThrowIncorrectReturnType(string vBase, string vName, string vType, bool vStatic)
104-
{
105-
string errTxt = "";
106-
107-
errTxt += vBase;
108-
errTxt += WriteMethodType(vStatic);
109-
errTxt += QuoteName(vName);
110-
errTxt += " does not return a ";
111-
errTxt += vType;
112-
errTxt += " value";
113-
114-
throw new Exception(errTxt);
115-
}
116-
117-
// Writes method into error text.
118-
private static string WriteMethodType(bool stc)
119-
{
120-
string writeRes = " method ";
121-
if (stc) writeRes = " static method ";
122-
return writeRes;
123-
}
124-
125-
// Writes quoted name into error text.
126-
private static string QuoteName(string nTxt)
127-
{
128-
return "'" + nTxt + "'";
129-
}
130-
6+
// EMPTY
1317
}
1328
}

net-solution/PalindromePartitions.Tests/FullAlgorithmTests.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,7 @@ namespace PalindromePartitions.Tests
1111
[TestFixture]
1212
public class FullAlgorithmTests
1313
{
14-
[Test]
15-
public void FunctionExists()
16-
{
17-
Type classObject = typeof(StringPartitioning);
18-
SchemaValidation.CheckMethod(classObject, "RunLoop", typeof(void), true);
19-
}
20-
21-
// 'geeks' input.
14+
// 'geeks' input.
2215
[Test]
2316
public void Geeks()
2417
{

net-solution/PalindromePartitions.Tests/InputTests.cs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,8 @@ public class InputTests
1414
private static string emptyErrorText = "Input string is missing.";
1515
private static string maxLengthText = "Input string can only have up to 100 characters.";
1616
private static string wrongCharsText = "Input string must only contain alphanumeric characters.";
17-
18-
[Test]
19-
public void FunctionsExist()
20-
{
21-
Type classObject = typeof(InputArg);
22-
SchemaValidation.CheckMethod(classObject, "ReadInputText", typeof(string), true);
23-
SchemaValidation.CheckMethod(classObject, "ValidateInputText", typeof(bool), true);
24-
}
25-
26-
27-
[Test]
17+
18+
[Test]
2819
public void ValidString()
2920
{
3021
string[] givenArgs = {"qu1ck8r0wnf0x"};

net-solution/PalindromePartitions.Tests/PartitionListInitializationTest.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,7 @@ namespace PalindromePartitions.Tests
1111
[TestFixture]
1212
public class PartitionListInitializationTest
1313
{
14-
[Test]
15-
public void FunctionExists()
16-
{
17-
Type classObject = typeof(AlgorithmResults);
18-
SchemaValidation.CheckMethod(classObject, "InitializeList", typeof(List<Partition>), true);
19-
}
20-
21-
[Test]
14+
[Test]
2215
public void IntlTest()
2316
{
2417
string entryString = "initialize";

net-solution/PalindromePartitions.Tests/PartitionObjectTests.cs

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,35 +16,9 @@ public class PartitionObjectTests
1616
// Error message strings.
1717
private static readonly string NegativeText = "Non-negative number required. (Parameter 'index')";
1818
private static readonly string BoundText = WriteBoundErrorText();
19-
20-
21-
// Class object schema.
22-
[Test]
23-
public void ObjectSchema()
24-
{
25-
// Value types.
26-
Type intType = typeof(int);
27-
Type strType = typeof(string);
28-
Type strListType = typeof(List<string>);
29-
30-
// 'Count' property.
31-
SchemaValidation.CheckProperty(ObjectType, "Count", intType);
32-
33-
// Constructor functions.
34-
SchemaValidation.CheckMethod(ObjectType, "Initialize", ObjectType, true);
35-
SchemaValidation.CheckMethod(ObjectType, "Empty", ObjectType, true);
36-
SchemaValidation.CheckMethod(ObjectType, "Parse", ObjectType, true);
37-
SchemaValidation.CheckMethod(ObjectType, "Derive", ObjectType, true);
38-
39-
// Object functions.
40-
SchemaValidation.CheckMethod(ObjectType, "Slice", strListType, false);
41-
SchemaValidation.CheckMethod(ObjectType, "MergeSubstrings", strType, false);
42-
SchemaValidation.CheckMethod(ObjectType, "Join", strType, false);
43-
SchemaValidation.CheckMethod(ObjectType, "GetSubstring", strType, false);
44-
}
45-
46-
47-
// 'Join' function.
19+
20+
21+
// 'Join' function.
4822
[Test]
4923
public void JoinFunction()
5024
{

net-solution/PalindromePartitions.Tests/ResultOutputTests.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,7 @@ namespace PalindromePartitions.Tests
99
[TestFixture]
1010
public class ResultOutputTests
1111
{
12-
[Test]
13-
public void FunctionExists()
14-
{
15-
Type classObject = typeof(AlgorithmResults);
16-
SchemaValidation.CheckMethod(classObject, "GetOutputType", typeof(int), true);
17-
}
18-
19-
20-
[Test]
12+
[Test]
2113
public void Complete()
2214
{
2315
int testFlag = AlgorithmResults.GetOutputType(20);
Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
using System;
21
using NUnit.Framework;
3-
using PalindromePartitions.Classes;
4-
using PalindromePartitions.Tests.Common;
52

63
namespace PalindromePartitions.Tests
74
{
@@ -10,15 +7,10 @@ namespace PalindromePartitions.Tests
107
public class TryCatchSchema
118
{
129
[Test]
13-
public void FunctionExists()
10+
public void Placeholder()
1411
{
15-
Type classObject = typeof(TryCatchResult);
16-
Type boolType = typeof(bool);
17-
Type strType = typeof(string);
18-
19-
SchemaValidation.CheckProperty(classObject, "Successful", boolType);
20-
SchemaValidation.CheckProperty(classObject, "ErrorMessage", strType);
21-
}
12+
Assert.True(true);
13+
}
2214

2315
}
2416
}

0 commit comments

Comments
 (0)