mirror of
https://github.com/AlexMacocian/SystemExtensions.git
synced 2026-07-25 08:22:08 +00:00
Implemented Serializable + Tests
This commit is contained in:
@@ -5,6 +5,8 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using System.IO;
|
||||
|
||||
namespace SystemExtensions.Collections.Tests
|
||||
{
|
||||
@@ -124,5 +126,35 @@ namespace SystemExtensions.Collections.Tests
|
||||
|
||||
int[] array = avlTree.ToArray();
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void Serialize()
|
||||
{
|
||||
AVLTree<int> avlTree2 = new AVLTree<int>();
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
avlTree.Add(i);
|
||||
}
|
||||
BinaryFormatter serializer = new BinaryFormatter();
|
||||
string s = string.Empty;
|
||||
using (var stream = new MemoryStream())
|
||||
{
|
||||
serializer.Serialize(stream, avlTree);
|
||||
stream.Position = 0;
|
||||
avlTree2 = (AVLTree<int>)serializer.Deserialize(stream);
|
||||
}
|
||||
IEnumerator<int> avlTreeEnum = avlTree.GetEnumerator();
|
||||
IEnumerator<int> avlTree2Enum = avlTree2.GetEnumerator();
|
||||
|
||||
for(int i = 0; i < 100; i++)
|
||||
{
|
||||
if(avlTreeEnum.Current != avlTree2Enum.Current)
|
||||
{
|
||||
Assert.Fail();
|
||||
}
|
||||
avlTreeEnum.MoveNext();
|
||||
avlTree2Enum.MoveNext();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,9 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using SystemExtensions;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using System.Xml.Serialization;
|
||||
using System.IO;
|
||||
|
||||
namespace SystemExtensions.Collections.Tests
|
||||
{
|
||||
@@ -173,5 +176,34 @@ namespace SystemExtensions.Collections.Tests
|
||||
|
||||
Assert.Fail();
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void Serialize()
|
||||
{
|
||||
BinaryHeap<int> binaryHeap2 = new BinaryHeap<int>();
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
binaryHeap.Insert(i);
|
||||
}
|
||||
BinaryFormatter serializer = new BinaryFormatter();
|
||||
string s = string.Empty;
|
||||
using (var stream = new MemoryStream()) {
|
||||
serializer.Serialize(stream, binaryHeap);
|
||||
stream.Position = 0;
|
||||
binaryHeap2 = (BinaryHeap<int>)serializer.Deserialize(stream);
|
||||
}
|
||||
IEnumerator<int> binaryHeapEnum = binaryHeap.GetEnumerator();
|
||||
IEnumerator<int> binaryHeapEnum2 = binaryHeap2.GetEnumerator();
|
||||
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
if (binaryHeapEnum.Current != binaryHeapEnum2.Current)
|
||||
{
|
||||
Assert.Fail();
|
||||
}
|
||||
binaryHeapEnum.MoveNext();
|
||||
binaryHeapEnum2.MoveNext();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,8 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using System.IO;
|
||||
|
||||
namespace SystemExtensions.Collections.Tests
|
||||
{
|
||||
@@ -175,5 +177,35 @@ namespace SystemExtensions.Collections.Tests
|
||||
|
||||
Assert.Fail();
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void Serialize()
|
||||
{
|
||||
FibonacciHeap<int> fibonacciHeap2 = new FibonacciHeap<int>();
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
fibonacciHeap.Insert(i);
|
||||
}
|
||||
BinaryFormatter serializer = new BinaryFormatter();
|
||||
string s = string.Empty;
|
||||
using (var stream = new MemoryStream())
|
||||
{
|
||||
serializer.Serialize(stream, fibonacciHeap);
|
||||
stream.Position = 0;
|
||||
fibonacciHeap2 = (FibonacciHeap<int>)serializer.Deserialize(stream);
|
||||
}
|
||||
IEnumerator<int> enum1 = fibonacciHeap.GetEnumerator();
|
||||
IEnumerator<int> enum2 = fibonacciHeap2.GetEnumerator();
|
||||
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
if (enum1.Current != enum2.Current)
|
||||
{
|
||||
Assert.Fail();
|
||||
}
|
||||
enum1.MoveNext();
|
||||
enum2.MoveNext();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,8 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using SystemExtensions;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using System.IO;
|
||||
|
||||
namespace SystemExtensions.Collections.Tests
|
||||
{
|
||||
@@ -81,5 +83,35 @@ namespace SystemExtensions.Collections.Tests
|
||||
Assert.Fail();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void Serialize()
|
||||
{
|
||||
PriorityQueue<int> priorityQueue2 = new PriorityQueue<int>();
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
priorityQueue.Enqueue(i);
|
||||
}
|
||||
BinaryFormatter serializer = new BinaryFormatter();
|
||||
string s = string.Empty;
|
||||
using (var stream = new MemoryStream())
|
||||
{
|
||||
serializer.Serialize(stream, priorityQueue);
|
||||
stream.Position = 0;
|
||||
priorityQueue2 = (PriorityQueue<int>)serializer.Deserialize(stream);
|
||||
}
|
||||
IEnumerator<int> enum1 = priorityQueue.GetEnumerator();
|
||||
IEnumerator<int> enum2 = priorityQueue2.GetEnumerator();
|
||||
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
if (enum1.Current != enum2.Current)
|
||||
{
|
||||
Assert.Fail();
|
||||
}
|
||||
enum1.MoveNext();
|
||||
enum2.MoveNext();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,8 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using System.IO;
|
||||
|
||||
namespace SystemExtensions.Collections.Tests
|
||||
{
|
||||
@@ -124,5 +126,35 @@ namespace SystemExtensions.Collections.Tests
|
||||
Assert.Fail();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void Serialize()
|
||||
{
|
||||
SkipList<int> skipList2 = new SkipList<int>();
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
skipList.Add(i);
|
||||
}
|
||||
BinaryFormatter serializer = new BinaryFormatter();
|
||||
string s = string.Empty;
|
||||
using (var stream = new MemoryStream())
|
||||
{
|
||||
serializer.Serialize(stream, skipList);
|
||||
stream.Position = 0;
|
||||
skipList2 = (SkipList<int>)serializer.Deserialize(stream);
|
||||
}
|
||||
IEnumerator<int> enum1 = skipList.GetEnumerator();
|
||||
IEnumerator<int> enum2 = skipList2.GetEnumerator();
|
||||
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
if (enum1.Current != enum2.Current)
|
||||
{
|
||||
Assert.Fail();
|
||||
}
|
||||
enum1.MoveNext();
|
||||
enum2.MoveNext();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,8 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using System.IO;
|
||||
|
||||
namespace SystemExtensions.Collections.Tests
|
||||
{
|
||||
@@ -110,5 +112,35 @@ namespace SystemExtensions.Collections.Tests
|
||||
|
||||
Assert.Fail();
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void Serialize()
|
||||
{
|
||||
Treap<int> treap2 = new Treap<int>();
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
treap.Add(i);
|
||||
}
|
||||
BinaryFormatter serializer = new BinaryFormatter();
|
||||
string s = string.Empty;
|
||||
using (var stream = new MemoryStream())
|
||||
{
|
||||
serializer.Serialize(stream, treap);
|
||||
stream.Position = 0;
|
||||
treap2 = (Treap<int>)serializer.Deserialize(stream);
|
||||
}
|
||||
IEnumerator<int> enum1 = treap.GetEnumerator();
|
||||
IEnumerator<int> enum2 = treap2.GetEnumerator();
|
||||
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
if (enum1.Current != enum2.Current)
|
||||
{
|
||||
Assert.Fail();
|
||||
}
|
||||
enum1.MoveNext();
|
||||
enum2.MoveNext();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,6 +46,7 @@
|
||||
<HintPath>..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<Choose>
|
||||
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
|
||||
|
||||
Reference in New Issue
Block a user