mirror of
https://github.com/Smaug123/WoofWare.PawPrint
synced 2025-10-08 07:28:40 +00:00
Concrete types - lots of tech debt in here (#79)
This commit is contained in:
120
WoofWare.PawPrint.Test/sourcesPure/CrossAssemblyTypes.cs
Normal file
120
WoofWare.PawPrint.Test/sourcesPure/CrossAssemblyTypes.cs
Normal file
@@ -0,0 +1,120 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections;
|
||||
|
||||
// Test cross-assembly type resolution using standard library types
|
||||
public class CrossAssemblyTypeTest
|
||||
{
|
||||
public static int TestSystemTypes()
|
||||
{
|
||||
// Test various System types to ensure proper assembly resolution
|
||||
|
||||
// System.DateTime
|
||||
var date = new DateTime(2023, 1, 1);
|
||||
if (date.Year != 2023) return 1;
|
||||
|
||||
// System.Guid
|
||||
var guid = Guid.Empty;
|
||||
if (guid != Guid.Empty) return 2;
|
||||
|
||||
// System.TimeSpan
|
||||
var timeSpan = TimeSpan.FromMinutes(30);
|
||||
if (timeSpan.TotalMinutes != 30) return 3;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static int TestCollectionTypes()
|
||||
{
|
||||
// Test various collection types from different assemblies
|
||||
|
||||
// Dictionary<TKey, TValue>
|
||||
var dict = new Dictionary<string, int>();
|
||||
dict["test"] = 42;
|
||||
if (dict["test"] != 42) return 1;
|
||||
|
||||
// HashSet<T>
|
||||
var hashSet = new HashSet<int>();
|
||||
hashSet.Add(1);
|
||||
hashSet.Add(2);
|
||||
hashSet.Add(1); // duplicate
|
||||
if (hashSet.Count != 2) return 2;
|
||||
|
||||
// Queue<T>
|
||||
var queue = new Queue<string>();
|
||||
queue.Enqueue("first");
|
||||
queue.Enqueue("second");
|
||||
if (queue.Dequeue() != "first") return 3;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static int TestGenericInterfaces()
|
||||
{
|
||||
// Test generic interfaces across assemblies
|
||||
|
||||
var list = new List<int> { 1, 2, 3 };
|
||||
|
||||
// IEnumerable<T>
|
||||
IEnumerable<int> enumerable = list;
|
||||
int count = 0;
|
||||
foreach (int item in enumerable)
|
||||
{
|
||||
count++;
|
||||
}
|
||||
if (count != 3) return 1;
|
||||
|
||||
// ICollection<T>
|
||||
ICollection<int> collection = list;
|
||||
if (collection.Count != 3) return 2;
|
||||
|
||||
// IList<T>
|
||||
IList<int> ilist = list;
|
||||
if (ilist[0] != 1) return 3;
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Test Array.Empty<T> which was mentioned in the diff as a specific case
|
||||
public class ArrayEmptyTest
|
||||
{
|
||||
public static int TestArrayEmpty()
|
||||
{
|
||||
// Test Array.Empty<T> for different types
|
||||
var emptyInts = Array.Empty<int>();
|
||||
var emptyStrings = Array.Empty<string>();
|
||||
|
||||
if (emptyInts.Length != 0) return 1;
|
||||
if (emptyStrings.Length != 0) return 2;
|
||||
|
||||
// Verify they are different instances for different types
|
||||
// but same instance for same type
|
||||
var emptyInts2 = Array.Empty<int>();
|
||||
if (!ReferenceEquals(emptyInts, emptyInts2)) return 3;
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
class Program
|
||||
{
|
||||
static int Main(string[] args)
|
||||
{
|
||||
int result;
|
||||
|
||||
result = CrossAssemblyTypeTest.TestSystemTypes();
|
||||
if (result != 0) return 100 + result;
|
||||
|
||||
result = CrossAssemblyTypeTest.TestCollectionTypes();
|
||||
if (result != 0) return 200 + result;
|
||||
|
||||
result = CrossAssemblyTypeTest.TestGenericInterfaces();
|
||||
if (result != 0) return 300 + result;
|
||||
|
||||
result = ArrayEmptyTest.TestArrayEmpty();
|
||||
if (result != 0) return 400 + result;
|
||||
|
||||
return 0; // All tests passed
|
||||
}
|
||||
}
|
142
WoofWare.PawPrint.Test/sourcesPure/GenericEdgeCases.cs
Normal file
142
WoofWare.PawPrint.Test/sourcesPure/GenericEdgeCases.cs
Normal file
@@ -0,0 +1,142 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
// Test edge cases with generic parameters as mentioned in the diff
|
||||
public class GenericParameterEdgeCases
|
||||
{
|
||||
// Test method with multiple generic parameters
|
||||
public static T2 Convert<T1, T2>(T1 input, Func<T1, T2> converter)
|
||||
{
|
||||
return converter(input);
|
||||
}
|
||||
|
||||
// Test nested generic method calls
|
||||
public static List<T> WrapInList<T>(T item)
|
||||
{
|
||||
var list = new List<T>();
|
||||
list.Add(item);
|
||||
return list;
|
||||
}
|
||||
|
||||
public static int TestMultipleGenericParameters()
|
||||
{
|
||||
// Test Convert method with different type combinations
|
||||
string result1 = Convert<int, string>(42, x => x.ToString());
|
||||
if (result1 != "42") return 1;
|
||||
|
||||
int result2 = Convert<string, int>("123", x => int.Parse(x));
|
||||
if (result2 != 123) return 2;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static int TestNestedGenericMethodCalls()
|
||||
{
|
||||
// Test calling generic method from within another generic method
|
||||
var intList = WrapInList<int>(42);
|
||||
if (intList.Count != 1) return 1;
|
||||
if (intList[0] != 42) return 2;
|
||||
|
||||
var stringList = WrapInList<string>("test");
|
||||
if (stringList.Count != 1) return 3;
|
||||
if (stringList[0] != "test") return 4;
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Test deeply nested generic types
|
||||
public class DeepNestingTest
|
||||
{
|
||||
public static int TestDeeplyNestedGenerics()
|
||||
{
|
||||
// Test Dictionary<string, List<Dictionary<int, string>>>
|
||||
var complexType = new Dictionary<string, List<Dictionary<int, string>>>();
|
||||
|
||||
var innerDict = new Dictionary<int, string>();
|
||||
innerDict[1] = "one";
|
||||
innerDict[2] = "two";
|
||||
|
||||
var listOfDicts = new List<Dictionary<int, string>>();
|
||||
listOfDicts.Add(innerDict);
|
||||
|
||||
complexType["test"] = listOfDicts;
|
||||
|
||||
if (complexType["test"].Count != 1) return 1;
|
||||
if (complexType["test"][0][1] != "one") return 2;
|
||||
if (complexType["test"][0][2] != "two") return 3;
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Test generic constraints and inheritance scenarios
|
||||
public class GenericConstraintTest<T> where T : class
|
||||
{
|
||||
private T value;
|
||||
|
||||
public GenericConstraintTest(T val)
|
||||
{
|
||||
value = val;
|
||||
}
|
||||
|
||||
public bool IsNull()
|
||||
{
|
||||
return value == null;
|
||||
}
|
||||
|
||||
public static int TestGenericConstraints()
|
||||
{
|
||||
var test = new GenericConstraintTest<string>("hello");
|
||||
if (test.IsNull()) return 1;
|
||||
|
||||
var nullTest = new GenericConstraintTest<string>(null);
|
||||
if (!nullTest.IsNull()) return 2;
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Test generic field access scenarios mentioned in the diff
|
||||
public class GenericFieldAccess<T>
|
||||
{
|
||||
public static T DefaultValue = default(T);
|
||||
|
||||
public static int TestStaticGenericField()
|
||||
{
|
||||
// Test that static fields work correctly with generics
|
||||
if (GenericFieldAccess<int>.DefaultValue != 0) return 1;
|
||||
|
||||
// Test that different instantiations have different static fields
|
||||
GenericFieldAccess<int>.DefaultValue = 42;
|
||||
if (GenericFieldAccess<int>.DefaultValue != 42) return 2;
|
||||
if (GenericFieldAccess<string>.DefaultValue != null) return 3;
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
class Program
|
||||
{
|
||||
static int Main(string[] args)
|
||||
{
|
||||
int result;
|
||||
|
||||
result = GenericParameterEdgeCases.TestMultipleGenericParameters();
|
||||
if (result != 0) return 100 + result;
|
||||
|
||||
result = GenericParameterEdgeCases.TestNestedGenericMethodCalls();
|
||||
if (result != 0) return 200 + result;
|
||||
|
||||
result = DeepNestingTest.TestDeeplyNestedGenerics();
|
||||
if (result != 0) return 300 + result;
|
||||
|
||||
result = GenericConstraintTest<string>.TestGenericConstraints();
|
||||
if (result != 0) return 400 + result;
|
||||
|
||||
result = GenericFieldAccess<int>.TestStaticGenericField();
|
||||
if (result != 0) return 500 + result;
|
||||
|
||||
return 0; // All tests passed
|
||||
}
|
||||
}
|
54
WoofWare.PawPrint.Test/sourcesPure/StaticVariables.cs
Normal file
54
WoofWare.PawPrint.Test/sourcesPure/StaticVariables.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
public class GenericCounter<T>
|
||||
{
|
||||
private static int count = 0;
|
||||
|
||||
public static void Increment()
|
||||
{
|
||||
count++;
|
||||
}
|
||||
|
||||
public static int GetCount()
|
||||
{
|
||||
return count;
|
||||
}
|
||||
|
||||
public static void Reset()
|
||||
{
|
||||
count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
class Program
|
||||
{
|
||||
static int Main(string[] argv)
|
||||
{
|
||||
// Test that different generic instantiations have separate static variables
|
||||
|
||||
// Initial state should be 0 for all
|
||||
if (GenericCounter<int>.GetCount() != 0) return 1;
|
||||
if (GenericCounter<string>.GetCount() != 0) return 2;
|
||||
|
||||
// Increment int version 3 times
|
||||
GenericCounter<int>.Increment();
|
||||
GenericCounter<int>.Increment();
|
||||
GenericCounter<int>.Increment();
|
||||
|
||||
// Increment string version 2 times
|
||||
GenericCounter<string>.Increment();
|
||||
GenericCounter<string>.Increment();
|
||||
|
||||
// Verify counts are independent
|
||||
if (GenericCounter<int>.GetCount() != 3) return 3;
|
||||
if (GenericCounter<string>.GetCount() != 2) return 4;
|
||||
|
||||
// Reset int version only
|
||||
GenericCounter<int>.Reset();
|
||||
|
||||
// Verify reset only affected int version
|
||||
if (GenericCounter<int>.GetCount() != 0) return 5;
|
||||
if (GenericCounter<string>.GetCount() != 2) return 6;
|
||||
|
||||
// Test passes - static variables are isolated per generic instantiation
|
||||
return 0;
|
||||
}
|
||||
}
|
112
WoofWare.PawPrint.Test/sourcesPure/TypeConcretization.cs
Normal file
112
WoofWare.PawPrint.Test/sourcesPure/TypeConcretization.cs
Normal file
@@ -0,0 +1,112 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
// Test basic type concretization
|
||||
public class BasicTypeTest
|
||||
{
|
||||
public static int TestBasicTypes()
|
||||
{
|
||||
// Test primitive types
|
||||
int i = 42;
|
||||
string s = "hello";
|
||||
bool b = true;
|
||||
|
||||
if (i != 42) return 1;
|
||||
if (s != "hello") return 2;
|
||||
if (!b) return 3;
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Test generic type instantiation
|
||||
public class GenericTypeTest<T>
|
||||
{
|
||||
private T value;
|
||||
|
||||
public GenericTypeTest(T val)
|
||||
{
|
||||
value = val;
|
||||
}
|
||||
|
||||
public T GetValue()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
public static int TestGenericInstantiation()
|
||||
{
|
||||
var intTest = new GenericTypeTest<int>(123);
|
||||
var stringTest = new GenericTypeTest<string>("test");
|
||||
|
||||
if (intTest.GetValue() != 123) return 1;
|
||||
if (stringTest.GetValue() != "test") return 2;
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Test nested generic types
|
||||
public class NestedGenericTest
|
||||
{
|
||||
public static int TestNestedGenerics()
|
||||
{
|
||||
var listOfInts = new List<int>();
|
||||
listOfInts.Add(1);
|
||||
listOfInts.Add(2);
|
||||
|
||||
if (listOfInts.Count != 2) return 1;
|
||||
if (listOfInts[0] != 1) return 2;
|
||||
if (listOfInts[1] != 2) return 3;
|
||||
|
||||
var listOfLists = new List<List<int>>();
|
||||
listOfLists.Add(listOfInts);
|
||||
|
||||
if (listOfLists.Count != 1) return 4;
|
||||
if (listOfLists[0].Count != 2) return 5;
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Test generic methods
|
||||
public class GenericMethodTest
|
||||
{
|
||||
public static T Identity<T>(T input)
|
||||
{
|
||||
return input;
|
||||
}
|
||||
|
||||
public static int TestGenericMethods()
|
||||
{
|
||||
int intResult = Identity<int>(42);
|
||||
string stringResult = Identity<string>("hello");
|
||||
|
||||
if (intResult != 42) return 1;
|
||||
if (stringResult != "hello") return 2;
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
class Program
|
||||
{
|
||||
static int Main(string[] args)
|
||||
{
|
||||
int result;
|
||||
|
||||
result = BasicTypeTest.TestBasicTypes();
|
||||
if (result != 0) return 100 + result;
|
||||
|
||||
result = GenericTypeTest<int>.TestGenericInstantiation();
|
||||
if (result != 0) return 200 + result;
|
||||
|
||||
result = NestedGenericTest.TestNestedGenerics();
|
||||
if (result != 0) return 300 + result;
|
||||
|
||||
result = GenericMethodTest.TestGenericMethods();
|
||||
if (result != 0) return 400 + result;
|
||||
|
||||
return 0; // All tests passed
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user