-
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.
- Loading branch information
Haik
committed
Oct 31, 2023
1 parent
dda55f4
commit 4bcee44
Showing
4 changed files
with
67 additions
and
12 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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
namespace Pandatech.Crypto.Tests; | ||
|
||
public class RandomTests | ||
{ | ||
[Fact] | ||
public void Generate_ShouldReturnByteArray() | ||
{ | ||
const int length = 16; | ||
var randomBytes = Random.GenerateBytes(length); | ||
|
||
Assert.NotNull(randomBytes); | ||
Assert.Equal(length, randomBytes.Length); | ||
} | ||
|
||
[Fact] | ||
public void GeneratePandaId_WithZeroPreviousId_ReturnsValidId() | ||
{ | ||
const long previousId = 0; | ||
for (var i = 0; i < 1_000_000; ++i) | ||
{ | ||
var newId = Random.GeneratePandaId(previousId); | ||
|
||
Assert.True(newId is > 1_000_000 and < 1_000_037); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void GeneratePandaId_WithNonZeroPreviousId_ReturnsIncrementedId() | ||
{ | ||
const long previousId = 1_000_000; | ||
for (var i = 0; i < 1_000_000; ++i) | ||
{ | ||
var newId = Random.GeneratePandaId(previousId); | ||
|
||
Assert.True(newId > previousId); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void GeneratePandaId_WithinReasonableIterations_DoesNotProduceDuplicates() | ||
{ | ||
long previousId = 0; | ||
|
||
for (var i = 0; i < 1_000_000; ++i) | ||
{ | ||
var id = Random.GeneratePandaId(previousId); | ||
Assert.NotEqual(previousId, id); | ||
previousId = id; | ||
} | ||
} | ||
} |
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