public void RandomEqualTest() { SafeRandom rnd = new SafeRandom(); for (int loop = 0; loop < 100000; loop++) { byte[] a = new byte[rnd.Next(1, 100)]; rnd.NextBytes(a); byte[] b = DeepCopy(a); bool actual = ByteArrayEqualityComparer.AreEqual(a, b); Assert.IsTrue(actual); } }
public void RandomNotEqualTest() { SafeRandom rnd = new SafeRandom(); for (int loop = 0; loop < 1000000; loop++) { byte[] a = new byte[rnd.Next(1, 100)]; rnd.NextBytes(a); byte[] b = DeepCopy(a); b[rnd.Next(0, b.Length)]++; // Increment at a random index bool actual = ByteArrayEqualityComparer.AreEqual(a, b); Assert.IsFalse(actual); } }
private static Task <bool>[] InsertAndReadStreamsAndCheckMatch(RelationalStorageForTesting sut, int streamSize, int countOfStreams, CancellationToken cancellationToken) { //Stream in and steam out three binary streams in parallel. var streamChecks = new Task <bool> [countOfStreams]; var sr = new SafeRandom(); for (int i = 0; i < countOfStreams; ++i) { int streamId = i; streamChecks[i] = Task.Run(async() => { var rb = new byte[streamSize]; sr.NextBytes(rb); await InsertIntoDatabaseUsingStream(sut, streamId, rb, cancellationToken); var dataStreamFromTheDb = await ReadFromDatabaseUsingAsyncStream(sut, streamId, cancellationToken); return(dataStreamFromTheDb.StreamData.SequenceEqual(rb)); }); } return(streamChecks); }
public void NextBytes() { var b = new byte[256]; _random.NextBytes(b); }