forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a missing = in BigInteger.cs (dotnet#105456)
* Add a missing = * Add some tests for bigint AND. * Add some tests for bigint AND. * Update src/libraries/System.Runtime.Numerics/tests/BigInteger/SampleGeneration.cs Co-authored-by: Dan Moseley <danmose@microsoft.com> --------- Co-authored-by: Dan Moseley <danmose@microsoft.com>
- Loading branch information
1 parent
a905114
commit 8b7a685
Showing
6 changed files
with
255 additions
and
1 deletion.
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
81 changes: 81 additions & 0 deletions
81
src/libraries/System.Runtime.Numerics/tests/BigInteger/SampleGeneration.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,81 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace System.Numerics.Tests | ||
{ | ||
public static partial class SampleGeneration | ||
{ | ||
public static IEnumerable<ReadOnlyMemory<T>> EnumerateSequence<T>(IEnumerable<T> elementSource, int minLength, int maxLengthExclusive) | ||
{ | ||
return EnumerateSequence(elementSource.ToArray(), minLength, maxLengthExclusive); | ||
} | ||
|
||
public static IEnumerable<ReadOnlyMemory<T>> EnumerateSequence<T>(T[] elementSource, int minLength, int maxLengthExclusive) | ||
{ | ||
for (var i = minLength; maxLengthExclusive > i; ++i) | ||
{ | ||
foreach (var item in EnumerateSequence(elementSource, i)) | ||
{ | ||
yield return item; | ||
} | ||
} | ||
} | ||
|
||
public static IEnumerable<ReadOnlyMemory<T>> EnumerateSequence<T>(IEnumerable<T> elementSource, int length) | ||
{ | ||
return EnumerateSequence(elementSource.ToArray(), length); | ||
} | ||
|
||
public static IEnumerable<ReadOnlyMemory<T>> EnumerateSequence<T>(T[] elementSource, int length) | ||
{ | ||
var a = new T[length]; | ||
var r = new ReadOnlyMemory<T>(a); | ||
foreach (var _ in EnumerateSequenceYieldsCurrentCount(elementSource, a)) | ||
{ | ||
yield return r; | ||
} | ||
} | ||
|
||
private static IEnumerable<long> EnumerateSequenceYieldsCurrentCount<T>(T[] elementSource, T[] buffer) | ||
{ | ||
var c = 0L; | ||
var b = elementSource.Length; | ||
if (b != 0) | ||
{ | ||
var stack = new int[buffer.Length]; | ||
for (var i = 0; i < buffer.Length; ++i) | ||
{ | ||
buffer[i] = elementSource[0]; | ||
} | ||
{ | ||
L:; | ||
yield return c++; | ||
for (var i = 0; stack.Length != i; ++i) | ||
{ | ||
var en = ++stack[i]; | ||
if (b == en) | ||
{ | ||
} | ||
else | ||
{ | ||
buffer[i] = elementSource[en]; | ||
for (; 0 <= --i;) | ||
{ | ||
buffer[i] = elementSource[0]; | ||
stack[i] = 0; | ||
} | ||
goto L; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
138 changes: 138 additions & 0 deletions
138
src/libraries/System.Runtime.Numerics/tests/BigInteger/UInt32Samples.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,138 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.Linq; | ||
using Xunit; | ||
|
||
namespace System.Numerics.Tests | ||
{ | ||
|
||
public static partial class UInt32Samples | ||
{ | ||
private static readonly uint[] set1 = new uint[] { | ||
0B00000000000000000000000000000000U, | ||
0B00000000000000000000000000000001U, | ||
0B00111111111111111111111111111110U, | ||
0B00111111111111111111111111111111U, | ||
|
||
0B01000000000000000000000000000000U, | ||
0B01000000000000000000000000000001U, | ||
0B01111111111111111111111111111110U, | ||
0B01111111111111111111111111111111U, | ||
|
||
0B10000000000000000000000000000000U, | ||
0B10000000000000000000000000000001U, | ||
0B10111111111111111111111111111110U, | ||
0B10111111111111111111111111111111U, | ||
|
||
0B11000000000000000000000000000000U, | ||
0B11000000000000000000000000000001U, | ||
0B11111111111111111111111111111110U, | ||
0B11111111111111111111111111111111U, | ||
}; | ||
|
||
private static IEnumerable<uint> GetSet1() | ||
{ | ||
foreach (var item in set1) | ||
{ | ||
yield return item; | ||
} | ||
} | ||
|
||
public static readonly IEnumerable<uint> Set1 = GetSet1(); | ||
|
||
private static readonly uint[] set2 = new uint[] { | ||
0B00000000000000000000000000000000U, | ||
0B00000000000000000000000000000001U, | ||
0B00000000000000000100000000000000U, | ||
0B00000000000000000100000000000001U, | ||
|
||
0B00000000000000010000000000000000U, | ||
0B00000000000000010000000000000001U, | ||
0B00000000000000010100000000000000U, | ||
0B00000000000000010100000000000001U, | ||
|
||
0B00111111111111111111111111111110U, | ||
0B00111111111111111111111111111111U, | ||
0B00111111111111111011111111111110U, | ||
0B00111111111111111011111111111111U, | ||
|
||
0B00111111111111101111111111111110U, | ||
0B00111111111111101111111111111111U, | ||
0B00111111111111101011111111111110U, | ||
0B00111111111111101011111111111111U, | ||
|
||
0B01000000000000000000000000000000U, | ||
0B01000000000000000000000000000001U, | ||
0B01000000000000000100000000000000U, | ||
0B01000000000000000100000000000001U, | ||
|
||
0B01000000000000010000000000000000U, | ||
0B01000000000000010000000000000001U, | ||
0B01000000000000010100000000000000U, | ||
0B01000000000000010100000000000001U, | ||
|
||
0B01111111111111111111111111111110U, | ||
0B01111111111111111111111111111111U, | ||
0B01111111111111111011111111111110U, | ||
0B01111111111111111011111111111111U, | ||
|
||
0B01111111111111101111111111111110U, | ||
0B01111111111111101111111111111111U, | ||
0B01111111111111101011111111111110U, | ||
0B01111111111111101011111111111111U, | ||
|
||
0B10000000000000000000000000000000U, | ||
0B10000000000000000000000000000001U, | ||
0B10000000000000000100000000000000U, | ||
0B10000000000000000100000000000001U, | ||
|
||
0B10000000000000010000000000000000U, | ||
0B10000000000000010000000000000001U, | ||
0B10000000000000010100000000000000U, | ||
0B10000000000000010100000000000001U, | ||
|
||
0B10111111111111111111111111111110U, | ||
0B10111111111111111111111111111111U, | ||
0B10111111111111111011111111111110U, | ||
0B10111111111111111011111111111111U, | ||
|
||
0B10111111111111101111111111111110U, | ||
0B10111111111111101111111111111111U, | ||
0B10111111111111101011111111111110U, | ||
0B10111111111111101011111111111111U, | ||
|
||
0B11000000000000000000000000000000U, | ||
0B11000000000000000000000000000001U, | ||
0B11000000000000000100000000000000U, | ||
0B11000000000000000100000000000001U, | ||
|
||
0B11000000000000010000000000000000U, | ||
0B11000000000000010000000000000001U, | ||
0B11000000000000010100000000000000U, | ||
0B11000000000000010100000000000001U, | ||
|
||
0B11111111111111111111111111111110U, | ||
0B11111111111111111111111111111111U, | ||
0B11111111111111111011111111111110U, | ||
0B11111111111111111011111111111111U, | ||
|
||
0B11111111111111101111111111111110U, | ||
0B11111111111111101111111111111111U, | ||
0B11111111111111101011111111111110U, | ||
0B11111111111111101011111111111111U, | ||
}; | ||
|
||
private static IEnumerable<uint> GetSet2() | ||
{ | ||
foreach (var item in set2) | ||
{ | ||
yield return item; | ||
} | ||
} | ||
|
||
public static readonly IEnumerable<uint> Set2 = GetSet2(); | ||
} | ||
} |
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