public void TestTestThatCorrectCharacterCountIsReturned() { const int length = 100; var randomString = CryptoRandomString.GetCryptoRandomBase95String(length); Assert.AreEqual(length, randomString.Length); }
public void TestPerformanceTenMillionCharacters() { Stopwatch watch = new Stopwatch(); watch.Start(); const int length = 1000000; CryptoRandomString.GetCryptoRandomBase95String(length); watch.Stop(); Assert.IsTrue(watch.ElapsedMilliseconds < 1000); } // Elapsed Milliseconds 320 (it fluxuated a few milliseconds each run)
public void TestAllCharactersAreUsed() { const int length = 1000000; var randomString = CryptoRandomString.GetCryptoRandomBase95String(length); for (int i = 32; i < 126; i++) { char c = (char)i; Assert.IsTrue(randomString.Contains(c.ToString())); } }
public void TestPerformanceLoop() { Stopwatch watch = new Stopwatch(); const int length = 16; watch.Start(); for (int i = 0; i < 100000; i++) { CryptoRandomString.GetCryptoRandomBase95String(length); } watch.Stop(); Assert.IsTrue(watch.ElapsedMilliseconds < 1000); }
public void TestDistributionInTenMillionCharacters() { const int length = 1000000; const int distibution = length / 95; int[] margins = new int[9500]; for (int j = 0; j < 100; j++) { var randomString = CryptoRandomString.GetCryptoRandomBase95String(length); for (int i = 32; i < 127; i++) { //int count = randomString.Count(c => c == i); int count = CountInstancesOfChar(randomString, (char)i); margins[(j * 95) + i - 32] = count; } } Assert.IsTrue(Math.Abs(margins.Average() - distibution) < .5); }