mirror of
https://github.com/AlexMacocian/SystemExtensions.git
synced 2026-07-15 14:19:29 +00:00
112 lines
2.2 KiB
C#
112 lines
2.2 KiB
C#
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
using System.Collections.Generic;
|
|
using System.Runtime.Serialization.Formatters.Binary;
|
|
using System.IO;
|
|
|
|
namespace System.Collections.Tests;
|
|
|
|
[TestClass()]
|
|
public class TreapTests
|
|
{
|
|
Treap<int> treap = new Treap<int>();
|
|
[TestMethod()]
|
|
public void TreapTest()
|
|
{
|
|
this.treap = new Treap<int>();
|
|
}
|
|
|
|
[TestMethod()]
|
|
public void InsertTest()
|
|
{
|
|
var random = new Random();
|
|
for(var i = 0; i < 1000; i++)
|
|
{
|
|
this.treap.Add(random.Next(0, 5000));
|
|
}
|
|
}
|
|
|
|
[TestMethod()]
|
|
public void RemoveTest()
|
|
{
|
|
this.treap.Add(60);
|
|
this.treap.Add(6);
|
|
this.treap.Add(5);
|
|
this.treap.Remove(60);
|
|
if(this.treap.Contains(60) || this.treap.Count > 2)
|
|
{
|
|
Assert.Fail();
|
|
}
|
|
}
|
|
|
|
[TestMethod()]
|
|
public void ClearTest()
|
|
{
|
|
var random = new Random();
|
|
for (var i = 0; i < 100; i++)
|
|
{
|
|
this.treap.Add(random.Next(0, 5000));
|
|
}
|
|
|
|
this.treap.Clear();
|
|
if(this.treap.Count > 0)
|
|
{
|
|
Assert.Fail();
|
|
}
|
|
}
|
|
|
|
[TestMethod()]
|
|
public void ContainsTest()
|
|
{
|
|
this.treap.Add(50);
|
|
this.treap.Add(25);
|
|
this.treap.Add(991142);
|
|
this.treap.Add(12313);
|
|
this.treap.Add(24);
|
|
this.treap.Add(23);
|
|
if (!this.treap.Contains(24))
|
|
{
|
|
Assert.Fail();
|
|
}
|
|
}
|
|
|
|
[TestMethod()]
|
|
public void ToArrayTest()
|
|
{
|
|
for(var i = 0; i < 1000; i++)
|
|
{
|
|
this.treap.Add(i);
|
|
}
|
|
|
|
var arr = this.treap.ToArray();
|
|
for(var i = 0; i < 1000; i++)
|
|
{
|
|
if(arr[i] != i)
|
|
{
|
|
Assert.Fail();
|
|
}
|
|
}
|
|
}
|
|
|
|
[TestMethod()]
|
|
public void GetEnumeratorTest()
|
|
{
|
|
for (var i = 0; i < 1000; i++)
|
|
{
|
|
this.treap.Add(i);
|
|
}
|
|
|
|
var count = 0;
|
|
foreach(var value in this.treap)
|
|
{
|
|
System.Diagnostics.Debug.WriteLine(value);
|
|
count++;
|
|
}
|
|
|
|
if(count == this.treap.Count)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Assert.Fail();
|
|
}
|
|
} |