Skip to content

Add new generic test classes #196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions MetadataProcessor.Tests/TestNFApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public static void Main()
// Generics Tests
_ = new GenericClassTests();
_ = new StatckTests();
_ = new SimpleListTests();

// null attributes tests
Console.WriteLine("Null attributes tests");
Expand Down
90 changes: 90 additions & 0 deletions MetadataProcessor.Tests/TestNFApp/SimpleList.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Diagnostics;

namespace TestNFApp
{
public class SimpleList<T>
{
private T[] _items;
private int _count;

public T[] Enumerable
{
get
{
T[] values = new T[_count];
Array.Copy(_items, values, _count);
return values;
}
}
public SimpleList()
{
_items = new T[4]; // Initial capacity
_count = 0;
}

public void Add(T item)
{
if (_count == _items.Length)
{
ResizeArray(); // Resize when full
}
_items[_count++] = item;
}

public bool Remove(T item)
{
for (int i = 0; i < _count; i++)
{
if (item.Equals(_items[i]))
{
for (int j = i; j < _count - 1; j++)
{
_items[j] = _items[j + 1];
}
_items[--_count] = default(T);
return true;
}
}
return false;
}

private void ResizeArray()
{
int newSize = _items.Length * 2;
T[] newArray = new T[newSize];


for (int i = 0; i < _count; i++)
{
newArray[i] = _items[i];
}

_items = newArray;
}


public int Count => _count;
}

public class SimpleListTests
{
public SimpleListTests()
{
SimpleList<int> list = new SimpleList<int>();

for (int i = 0; i < 10; i++)
{
list.Add(i);
}

foreach (int i in list.Enumerable)
{
Console.WriteLine($">> {i}");
}
}
}
}
1 change: 1 addition & 0 deletions MetadataProcessor.Tests/TestNFApp/TestNFApp.nfproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<Compile Include="DataRowAttribute.cs" />
<Compile Include="DummyCustomAttribute1.cs" />
<Compile Include="DummyCustomAttribute2.cs" />
<Compile Include="SimpleList.cs" />
<Compile Include="StackClass.cs" />
<Compile Include="IgnoreAttribute.cs" />
<Compile Include="IOneClassOverAll.cs" />
Expand Down
Loading