Skip to content

Instantly share code, notes, and snippets.

@felegy
Created March 27, 2019 09:59
Show Gist options
  • Save felegy/4f9357de5954d3298f576631b877af91 to your computer and use it in GitHub Desktop.
Save felegy/4f9357de5954d3298f576631b877af91 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using Xunit;
public class SidPocTest
{
private const int DefaultSize = 8;
private const string DefaultAlphabet = "123456789abcdefghijkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ";
[Fact]
public void TestHasNoCollisions()
{
const int count = 10000 * 1000;
var dictUsed = new Dictionary<string, bool>();
foreach(var dummy in Enumerable.Range(1, count))
{
var result = Nanoid.Nanoid.Generate(DefaultAlphabet, DefaultSize);
Assert.False(dictUsed.TryGetValue(result, out var _));
dictUsed.Add(result, true);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment