Skip to content
This repository has been archived by the owner on May 27, 2021. It is now read-only.

Commit

Permalink
add runtime test
Browse files Browse the repository at this point in the history
  • Loading branch information
0xF6 committed May 22, 2020
1 parent fd24645 commit aabb8b0
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 10 deletions.
7 changes: 7 additions & 0 deletions VirtualMachine.sln
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "submodules", "submodules",
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ancient.Runtime", "submodules\runtime\src\Ancient.Runtime.csproj", "{267CF9D7-0E11-45D6-82E0-72B0B2B66673}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RuntimeTest", "test\RuntimeTest\RuntimeTest.csproj", "{5646B0E1-10FA-41F3-9110-8C616307DD6C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -65,6 +67,10 @@ Global
{267CF9D7-0E11-45D6-82E0-72B0B2B66673}.Debug|Any CPU.Build.0 = Debug|Any CPU
{267CF9D7-0E11-45D6-82E0-72B0B2B66673}.Release|Any CPU.ActiveCfg = Release|Any CPU
{267CF9D7-0E11-45D6-82E0-72B0B2B66673}.Release|Any CPU.Build.0 = Release|Any CPU
{5646B0E1-10FA-41F3-9110-8C616307DD6C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5646B0E1-10FA-41F3-9110-8C616307DD6C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5646B0E1-10FA-41F3-9110-8C616307DD6C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5646B0E1-10FA-41F3-9110-8C616307DD6C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -78,6 +84,7 @@ Global
{E2D48827-C38C-4689-B0A1-9FD395904FB3} = {3E153A17-EBC1-4471-BD65-0C306499D3F2}
{00506E30-C4CB-4734-BA64-920CEE5CE926} = {3E153A17-EBC1-4471-BD65-0C306499D3F2}
{267CF9D7-0E11-45D6-82E0-72B0B2B66673} = {B29BF648-1A51-4597-BE5E-E96D2C9EDD34}
{5646B0E1-10FA-41F3-9110-8C616307DD6C} = {24CBAF1C-EBD3-47DB-89BC-AD7F407DE760}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {77DF946F-0A1C-4A24-8A58-E2136BF8FC38}
Expand Down
44 changes: 38 additions & 6 deletions test/RuntimeTest/NativeStringTest.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,52 @@
namespace Tests
{
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ancient.runtime;
using ancient.runtime.@unsafe;
using NUnit.Framework;
using Xunit;

public unsafe class NativeStringTest
{
[Test]
[Fact]
public void AllocateTest()
{
var str = "foo-bar";
var p = NativeString.Wrap(str);
Assert.AreEqual(str.Length, p.GetLen());
Assert.AreEqual(Encoding.UTF8.GetByteCount(str), p.GetBuffer().Length);
Assert.AreEqual(Encoding.UTF8, p.GetEncoding());
Assert.AreEqual(NativeString.GetHashCode(str), p.GetHashCode());
Assert.Equal(str.Length, p.GetLen());
Assert.Equal(Encoding.UTF8.GetByteCount(str), p.GetBuffer().Length);
Assert.Equal(Encoding.UTF8, p.GetEncoding());
Assert.Equal(NativeString.GetHashCode(str), p.GetHashCode());
}
public class StringGenerator : IEnumerable<string[]>, IEnumerable<object[]>
{
public string[][] Data() =>
Enumerable.Range(0, 1)
.Select(i => Enumerable.Range(0, (int) Math.Pow(10, i))
.Select(v => Guid.NewGuid().ToString())
.ToArray()).ToArray();


public IEnumerator<string[]> GetEnumerator()
=> Data().ToList().GetEnumerator();
IEnumerator IEnumerable.GetEnumerator()
=> GetEnumerator();
IEnumerator<object[]> IEnumerable<object[]>.GetEnumerator()
=> Data().Select(x => new object[]{x}).GetEnumerator();
}

//[Theory(Timeout = 1000 * 120)]
//[ClassData(typeof(StringGenerator))]
public void LoadTest(string[] data)
{
var hashMap = new HashSet<int>();

foreach (var s in data)
Assert.True(hashMap.Add(NativeString.GetHashCode(s)));

}
}
}
13 changes: 9 additions & 4 deletions test/RuntimeTest/RuntimeTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@


<ItemGroup>
<PackageReference Include="nunit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="JetBrains.DotMemoryUnit" Version="3.1.20200127.214830" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.0-preview-20200428-01" />
<PackageReference Include="RandomDataGenerator.Net" Version="1.0.11" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\libs\Ancient.Runtime\Ancient.Runtime.csproj" />
<ProjectReference Include="..\..\submodules\runtime\src\Ancient.Runtime.csproj" />
</ItemGroup>

</Project>

0 comments on commit aabb8b0

Please sign in to comment.