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

Commit aabb8b0

Browse files
committed
add runtime test
1 parent fd24645 commit aabb8b0

File tree

3 files changed

+54
-10
lines changed

3 files changed

+54
-10
lines changed

VirtualMachine.sln

+7
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "submodules", "submodules",
2727
EndProject
2828
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ancient.Runtime", "submodules\runtime\src\Ancient.Runtime.csproj", "{267CF9D7-0E11-45D6-82E0-72B0B2B66673}"
2929
EndProject
30+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RuntimeTest", "test\RuntimeTest\RuntimeTest.csproj", "{5646B0E1-10FA-41F3-9110-8C616307DD6C}"
31+
EndProject
3032
Global
3133
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3234
Debug|Any CPU = Debug|Any CPU
@@ -65,6 +67,10 @@ Global
6567
{267CF9D7-0E11-45D6-82E0-72B0B2B66673}.Debug|Any CPU.Build.0 = Debug|Any CPU
6668
{267CF9D7-0E11-45D6-82E0-72B0B2B66673}.Release|Any CPU.ActiveCfg = Release|Any CPU
6769
{267CF9D7-0E11-45D6-82E0-72B0B2B66673}.Release|Any CPU.Build.0 = Release|Any CPU
70+
{5646B0E1-10FA-41F3-9110-8C616307DD6C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
71+
{5646B0E1-10FA-41F3-9110-8C616307DD6C}.Debug|Any CPU.Build.0 = Debug|Any CPU
72+
{5646B0E1-10FA-41F3-9110-8C616307DD6C}.Release|Any CPU.ActiveCfg = Release|Any CPU
73+
{5646B0E1-10FA-41F3-9110-8C616307DD6C}.Release|Any CPU.Build.0 = Release|Any CPU
6874
EndGlobalSection
6975
GlobalSection(SolutionProperties) = preSolution
7076
HideSolutionNode = FALSE
@@ -78,6 +84,7 @@ Global
7884
{E2D48827-C38C-4689-B0A1-9FD395904FB3} = {3E153A17-EBC1-4471-BD65-0C306499D3F2}
7985
{00506E30-C4CB-4734-BA64-920CEE5CE926} = {3E153A17-EBC1-4471-BD65-0C306499D3F2}
8086
{267CF9D7-0E11-45D6-82E0-72B0B2B66673} = {B29BF648-1A51-4597-BE5E-E96D2C9EDD34}
87+
{5646B0E1-10FA-41F3-9110-8C616307DD6C} = {24CBAF1C-EBD3-47DB-89BC-AD7F407DE760}
8188
EndGlobalSection
8289
GlobalSection(ExtensibilityGlobals) = postSolution
8390
SolutionGuid = {77DF946F-0A1C-4A24-8A58-E2136BF8FC38}

test/RuntimeTest/NativeStringTest.cs

+38-6
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,52 @@
11
namespace Tests
22
{
3+
using System;
4+
using System.Collections;
5+
using System.Collections.Generic;
6+
using System.Linq;
37
using System.Text;
8+
using ancient.runtime;
49
using ancient.runtime.@unsafe;
5-
using NUnit.Framework;
10+
using Xunit;
611

712
public unsafe class NativeStringTest
813
{
9-
[Test]
14+
[Fact]
1015
public void AllocateTest()
1116
{
1217
var str = "foo-bar";
1318
var p = NativeString.Wrap(str);
14-
Assert.AreEqual(str.Length, p.GetLen());
15-
Assert.AreEqual(Encoding.UTF8.GetByteCount(str), p.GetBuffer().Length);
16-
Assert.AreEqual(Encoding.UTF8, p.GetEncoding());
17-
Assert.AreEqual(NativeString.GetHashCode(str), p.GetHashCode());
19+
Assert.Equal(str.Length, p.GetLen());
20+
Assert.Equal(Encoding.UTF8.GetByteCount(str), p.GetBuffer().Length);
21+
Assert.Equal(Encoding.UTF8, p.GetEncoding());
22+
Assert.Equal(NativeString.GetHashCode(str), p.GetHashCode());
23+
}
24+
public class StringGenerator : IEnumerable<string[]>, IEnumerable<object[]>
25+
{
26+
public string[][] Data() =>
27+
Enumerable.Range(0, 1)
28+
.Select(i => Enumerable.Range(0, (int) Math.Pow(10, i))
29+
.Select(v => Guid.NewGuid().ToString())
30+
.ToArray()).ToArray();
31+
32+
33+
public IEnumerator<string[]> GetEnumerator()
34+
=> Data().ToList().GetEnumerator();
35+
IEnumerator IEnumerable.GetEnumerator()
36+
=> GetEnumerator();
37+
IEnumerator<object[]> IEnumerable<object[]>.GetEnumerator()
38+
=> Data().Select(x => new object[]{x}).GetEnumerator();
39+
}
40+
41+
//[Theory(Timeout = 1000 * 120)]
42+
//[ClassData(typeof(StringGenerator))]
43+
public void LoadTest(string[] data)
44+
{
45+
var hashMap = new HashSet<int>();
46+
47+
foreach (var s in data)
48+
Assert.True(hashMap.Add(NativeString.GetHashCode(s)));
49+
1850
}
1951
}
2052
}

test/RuntimeTest/RuntimeTest.csproj

+9-4
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,18 @@
1010

1111

1212
<ItemGroup>
13-
<PackageReference Include="nunit" Version="3.12.0" />
14-
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
15-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
13+
<PackageReference Include="JetBrains.DotMemoryUnit" Version="3.1.20200127.214830" />
14+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.0-preview-20200428-01" />
15+
<PackageReference Include="RandomDataGenerator.Net" Version="1.0.11" />
16+
<PackageReference Include="xunit" Version="2.4.1" />
17+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
18+
<PrivateAssets>all</PrivateAssets>
19+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
20+
</PackageReference>
1621
</ItemGroup>
1722

1823
<ItemGroup>
19-
<ProjectReference Include="..\..\libs\Ancient.Runtime\Ancient.Runtime.csproj" />
24+
<ProjectReference Include="..\..\submodules\runtime\src\Ancient.Runtime.csproj" />
2025
</ItemGroup>
2126

2227
</Project>

0 commit comments

Comments
 (0)