Skip to content
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
4 changes: 4 additions & 0 deletions CatLib.Core.sln.DotSettings.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/Environment/AssemblyExplorer/XmlDocument/@EntryValue">&lt;AssemblyExplorer&gt;&#xD;
&lt;Assembly Path="D:\Software\VS2017\Common7\IDE\ReferenceAssemblies\v2.0\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll" /&gt;&#xD;
&lt;/AssemblyExplorer&gt;</s:String></wpf:ResourceDictionary>
5 changes: 5 additions & 0 deletions src/CatLib.Core.NetStandard/CatLib.Core.NetStandard.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@
<Compile Include="..\CatLib.Core\Support\RingBuffer\RingBuffer.cs" Link="Support\RingBuffer\RingBuffer.cs" />
<Compile Include="..\CatLib.Core\Support\SortSet\ISortSet.cs" Link="Support\SortSet\ISortSet.cs" />
<Compile Include="..\CatLib.Core\Support\SortSet\SortSet.cs" Link="Support\SortSet\SortSet.cs" />
<Compile Include="..\CatLib.Core\Support\Storage\IStorage.cs" Link="Support\Storage\IStorage.cs" />
<Compile Include="..\CatLib.Core\Support\Storage\MemoryStorage.cs" Link="Support\Storage\MemoryStorage.cs" />
<Compile Include="..\CatLib.Core\Support\Stream\StorageStream.cs" Link="Support\Stream\StorageStream.cs" />
<Compile Include="..\CatLib.Core\Support\Template\IManaged.cs" Link="Support\Template\IManaged.cs" />
<Compile Include="..\CatLib.Core\Support\Template\IManager.cs" Link="Support\Template\IManager.cs" />
<Compile Include="..\CatLib.Core\Support\Template\ISingleManaged.cs" Link="Support\Template\ISingleManaged.cs" />
Expand Down Expand Up @@ -132,8 +135,10 @@
<Folder Include="Support\Guard\" />
<Folder Include="Support\QuickList\" />
<Folder Include="Support\SortSet\" />
<Folder Include="Support\Stream\" />
<Folder Include="Support\Template\" />
<Folder Include="Support\RingBuffer\" />
<Folder Include="Support\Storage\" />
</ItemGroup>

</Project>
3 changes: 3 additions & 0 deletions src/CatLib.Core.Tests/CatLib.Core.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,14 @@
<Compile Include="Support\QuickList\QuickListTests.cs" />
<Compile Include="Support\RingBuffer\RingBufferTests.cs" />
<Compile Include="Support\SortSet\SortSetTests.cs" />
<Compile Include="Support\Storage\MemoryStorageTests.cs" />
<Compile Include="Support\Stream\StorageStreamTests.cs" />
<Compile Include="Support\Template\ManagerTests.cs" />
<Compile Include="Support\Template\SingleManagerTests.cs" />
<Compile Include="Support\Util\ArrTests.cs" />
<Compile Include="Support\Util\DictTests.cs" />
<Compile Include="Support\Util\EnumTests.cs" />
<Compile Include="Support\Util\StreamExtensionTests.cs" />
<Compile Include="Support\Util\StrTests.cs" />
<Compile Include="Support\Util\SystemTimeTests.cs" />
<Compile Include="Support\VersionTests.cs" />
Expand Down
4 changes: 2 additions & 2 deletions src/CatLib.Core.Tests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@

[assembly: Guid("3c9f4024-910c-4881-a04d-34a6c3a09019")]

[assembly: AssemblyVersion("1.2.7.0")]
[assembly: AssemblyFileVersion("1.2.7.0")]
[assembly: AssemblyVersion("1.2.8.0")]
[assembly: AssemblyFileVersion("1.2.8.0")]
43 changes: 27 additions & 16 deletions src/CatLib.Core.Tests/Support/SortSet/SortSetTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,25 +58,36 @@ public void TestRandValue()
}

[TestMethod]

public void TestRank()
{
var sortSets = new SortSet<int, int>();
var n = 100;
while (n-- > 0)
{
var sortSets = new SortSet<int, int>();

sortSets.Add(1000, 85);
sortSets.Add(999, 75);
sortSets.Add(998, 185);
sortSets.Add(997, 85);
sortSets.Add(996, 185);
sortSets.Add(995, 85);

Assert.AreEqual(1, sortSets.GetRank(995));
Assert.AreEqual(995, sortSets.GetElementByRank(1));
Assert.AreEqual(997, sortSets.GetElementByRank(2));
Assert.AreEqual(1000, sortSets.GetElementByRank(3));
Assert.AreEqual(996, sortSets.GetElementByRank(4));
Assert.AreEqual(998, sortSets.GetElementByRank(5));

sortSets.Add(1000, 85);
sortSets.Add(999, 75);
sortSets.Add(998, 185);
sortSets.Add(997, 85);
sortSets.Add(996, 185);
sortSets.Add(995, 85);

Assert.AreEqual(1, sortSets.GetRank(995));
Assert.AreEqual(995, sortSets.GetElementByRank(1));
Assert.AreEqual(997, sortSets.GetElementByRank(2));
Assert.AreEqual(1000, sortSets.GetElementByRank(3));
Assert.AreEqual(996, sortSets.GetElementByRank(4));
Assert.AreEqual(998, sortSets.GetElementByRank(5));

Assert.AreEqual(3, sortSets.GetRangeCount(80, 90));
var i = 100;
var faild = 0;
while (i-- > 0)
{
Assert.AreEqual(3, sortSets.GetRangeCount(80, 90));
}
Console.WriteLine(faild);
}
}

[TestMethod]
Expand Down
139 changes: 139 additions & 0 deletions src/CatLib.Core.Tests/Support/Storage/MemoryStorageTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/*
* This file is part of the CatLib package.
*
* (c) Yu Bin <support@catlib.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* Document: http://catlib.io/
*/

using System;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace CatLib
{
[TestClass]
public class MemoryStorageTests
{
[TestMethod]
public void TestWrite()
{
// Append() is alias as Write
var storage = new MemoryStorage(4);
storage.Append(Encoding.Default.GetBytes("hello world"), 0, 11);
var data = new byte[16];
Assert.AreEqual(11, storage.Read(data, 0, data.Length));
Assert.AreEqual("hello world", Encoding.Default.GetString(Arr.Slice(data, 0, 11)));
}

[TestMethod]
public void TestAppend()
{
var storage = new MemoryStorage(4);
storage.Append(Encoding.Default.GetBytes("hello world"), 0, 11);
storage.Append(Encoding.Default.GetBytes("1"), 0, 1);
var data = new byte[16];
Assert.AreEqual(12, storage.Read(data, 0, data.Length));
Assert.AreEqual("hello world1", Encoding.Default.GetString(Arr.Slice(data, 0, 12)));

storage.Append(Encoding.Default.GetBytes("2"), 0, 1);
Assert.AreEqual(13, storage.Read(data, 0, data.Length));
Assert.AreEqual("hello world12", Encoding.Default.GetString(Arr.Slice(data, 0, 13)));
}

[TestMethod]
public void TestBlockAutomaticExpansion()
{
var storage = new MemoryStorage(4, 2);
storage.Append(Encoding.Default.GetBytes("12345678"), 0, 8);
storage.Append(Encoding.Default.GetBytes("9"), 0, 1);

var data = new byte[16];
Assert.AreEqual(9, storage.Read(data, 0, data.Length));
Assert.AreEqual("123456789", Encoding.Default.GetString(Arr.Slice(data, 0, 9)));
}

[TestMethod]
[ExpectedException(typeof(ObjectDisposedException))]
public void TestDispose()
{
MemoryStorage storage;
using (storage = new MemoryStorage(4, 2))
{
storage.Append(Encoding.Default.GetBytes("12345678"), 0, 8);
}

var data = new byte[16];
storage.Read(data, 0, data.Length);
}

[TestMethod]
[ExpectedException(typeof(ObjectDisposedException))]
public void TestDispose2()
{
MemoryStorage storage;
using (storage = new MemoryStorage(4, 2))
{

}
storage.Append(Encoding.Default.GetBytes("12345678"), 0, 8);
}

[TestMethod]
public void TestJumpWrite()
{
var storage = new MemoryStorage(4, 2);
storage.Append(Encoding.Default.GetBytes("1234"), 0, 4);
storage.Write(Encoding.Default.GetBytes("5678"), 0, 4, 13);
Assert.AreEqual(17, storage.Length);

var data = new byte[]
{
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32
};
Assert.AreEqual(17, storage.Read(data, 0, data.Length));
Assert.AreEqual("1234\0\0\0\0\0\0\0\0\05678", Encoding.Default.GetString(Arr.Slice(data, 0, 17)));
}

[TestMethod]
[ExpectedException(typeof(OutOfMemoryException))]
public void TestOutOfMemory()
{
var storage = new MemoryStorage(8, 4, 2);
try
{
storage.Append(Encoding.Default.GetBytes("12345678"), 0, 8);
}
catch (OutOfMemoryException)
{

}

storage.Append(Encoding.Default.GetBytes("1"), 0, 1);
}

[TestMethod]
public void TestDoubleDispose()
{
var storage = new MemoryStorage(8, 4, 2);
Assert.AreEqual(false, storage.Disabled);
storage.Dispose();
Assert.AreEqual(true, storage.Disabled);
storage.Dispose();
Assert.AreEqual(true, storage.Disabled);
}

[TestMethod]
public void TestGetLocker()
{
using (var storage = new MemoryStorage(8, 4, 2))
{
Assert.AreNotEqual(null, storage.Locker);
}
}
}
}
Loading