This repository has been archived by the owner on May 27, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
54 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))); | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters