??????????????Generics Unit Test??
???????????? ???????[ 2013/7/22 14:04:06 ] ????????
???????????????????????????????????????????
????д??????????????????
public class StackNum<T> where T : struct
{
List<T> array = null;
public StackNum()
{
this.array = new List<T>();
}
public void Push(T value)
{
array.Add(value);
}
public T Pop()
{
T val = array[this.Length - 1];
this.array.Remove(val);
return val;
}
public int Length
{
get { return this.array.Count; }
}
}
????StackNum
??????????????д????????????
class StackTestHelper
{
public static void LengthTest<T>()
where T : struct
{
var stack = GetStackInstance<T>();
Assert.AreEqual(stack.Length?? 0);
}
public static void PushTest<T>()
where T : struct
{
var stack = GetStackInstance<T>();
stack.Push(default(T));
Assert.AreEqual(stack.Length?? 1);
}
public static void PopTest<T>(params T[] values)
where T : struct
{
var stack = GetStackInstance<T>();
if (values == null)
{
return;
}
int pushLength = 0;
foreach (T val in values)
{
stack.Push(val);
Assert.AreEqual(stack.Length?? ++pushLength);
}
for (int i = stack.Length - 1; i >= 0; i--)
{
Assert.AreEqual<T>(stack.Pop()?? values[i]);
Assert.AreEqual(stack.Length?? i);
}
}
public static StackNum<T> GetStackInstance<T>()
where T : struct
{
return new StackNum<T>();
}
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11