Skip to content

Commit 9f1a301

Browse files
authored
Add new generic test classes (#196)
***NO_CI***
1 parent 3de8e01 commit 9f1a301

File tree

3 files changed

+92
-0
lines changed

3 files changed

+92
-0
lines changed

MetadataProcessor.Tests/TestNFApp/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public static void Main()
8282
// Generics Tests
8383
_ = new GenericClassTests();
8484
_ = new StatckTests();
85+
_ = new SimpleListTests();
8586

8687
// null attributes tests
8788
Console.WriteLine("Null attributes tests");
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System;
5+
using System.Diagnostics;
6+
7+
namespace TestNFApp
8+
{
9+
public class SimpleList<T>
10+
{
11+
private T[] _items;
12+
private int _count;
13+
14+
public T[] Enumerable
15+
{
16+
get
17+
{
18+
T[] values = new T[_count];
19+
Array.Copy(_items, values, _count);
20+
return values;
21+
}
22+
}
23+
public SimpleList()
24+
{
25+
_items = new T[4]; // Initial capacity
26+
_count = 0;
27+
}
28+
29+
public void Add(T item)
30+
{
31+
if (_count == _items.Length)
32+
{
33+
ResizeArray(); // Resize when full
34+
}
35+
_items[_count++] = item;
36+
}
37+
38+
public bool Remove(T item)
39+
{
40+
for (int i = 0; i < _count; i++)
41+
{
42+
if (item.Equals(_items[i]))
43+
{
44+
for (int j = i; j < _count - 1; j++)
45+
{
46+
_items[j] = _items[j + 1];
47+
}
48+
_items[--_count] = default(T);
49+
return true;
50+
}
51+
}
52+
return false;
53+
}
54+
55+
private void ResizeArray()
56+
{
57+
int newSize = _items.Length * 2;
58+
T[] newArray = new T[newSize];
59+
60+
61+
for (int i = 0; i < _count; i++)
62+
{
63+
newArray[i] = _items[i];
64+
}
65+
66+
_items = newArray;
67+
}
68+
69+
70+
public int Count => _count;
71+
}
72+
73+
public class SimpleListTests
74+
{
75+
public SimpleListTests()
76+
{
77+
SimpleList<int> list = new SimpleList<int>();
78+
79+
for (int i = 0; i < 10; i++)
80+
{
81+
list.Add(i);
82+
}
83+
84+
foreach (int i in list.Enumerable)
85+
{
86+
Console.WriteLine($">> {i}");
87+
}
88+
}
89+
}
90+
}

MetadataProcessor.Tests/TestNFApp/TestNFApp.nfproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
<Compile Include="DataRowAttribute.cs" />
2424
<Compile Include="DummyCustomAttribute1.cs" />
2525
<Compile Include="DummyCustomAttribute2.cs" />
26+
<Compile Include="SimpleList.cs" />
2627
<Compile Include="StackClass.cs" />
2728
<Compile Include="IgnoreAttribute.cs" />
2829
<Compile Include="IOneClassOverAll.cs" />

0 commit comments

Comments
 (0)