This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Random span-based API tests (#23692)
* Random span extensions * Random span tests * random span tests * Test configurations * Fixed item group condition
- Loading branch information
1 parent
4341d5c
commit 94a3498
Showing
4 changed files
with
114 additions
and
9 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
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
56 changes: 56 additions & 0 deletions
56
src/System.Runtime.Extensions/tests/System/Random.netcoreapp.cs
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using Xunit; | ||
|
||
namespace System.Tests | ||
{ | ||
public static partial class RandomTests | ||
{ | ||
[Fact] | ||
public static void Empty_Span() | ||
{ | ||
int seed = Environment.TickCount; | ||
Random r = new Random(seed); | ||
r.NextBytes(Span<byte>.Empty); | ||
} | ||
|
||
[Fact] | ||
public static void Seeded_Span() | ||
{ | ||
int seed = Environment.TickCount; | ||
|
||
Random r1 = new Random(seed); | ||
Random r2 = new Random(seed); | ||
|
||
Span<byte> s1 = new Span<byte>(new byte[1000]); | ||
r1.NextBytes(s1); | ||
Span<byte> s2 = new Span<byte>(new byte[1000]); | ||
r2.NextBytes(s2); | ||
for (int i = 0; i < s1.Length; i++) | ||
{ | ||
Assert.Equal(s1[i], s2[i]); | ||
} | ||
for (int i = 0; i < s1.Length; i++) | ||
{ | ||
int x1 = r1.Next(); | ||
int x2 = r2.Next(); | ||
Assert.Equal(x1, x2); | ||
} | ||
} | ||
|
||
[Fact] | ||
public static void ExpectedValues_NextBytesSpan() | ||
{ | ||
byte[][] expectedValues = ByteValues(); | ||
for (int seed = 0; seed < expectedValues.Length; seed++) | ||
{ | ||
byte[] actualValues = new byte[expectedValues[seed].Length]; | ||
var r = new Random(seed); | ||
r.NextBytes(new Span<byte>(actualValues)); | ||
Assert.Equal(expectedValues[seed], actualValues); | ||
} | ||
} | ||
} | ||
} |