[TestMethod] public void Random_UniqueNext() { #region count < Math.Sqrt(maxValue - minValue) { // test shifting from maxValue int i = 999; TestingRandom random = new TestingRandom(() => i--); ISet <int> set = new SetHashLinked <int>(); random.NextUnique(5, 0, 1000, j => { Assert.IsFalse(set.Contains(j)); set.Add(j); }); Assert.IsTrue(set.Count == 5); } { // test shifting from 0 TestingRandom random = new TestingRandom(() => 0); ISet <int> set = new SetHashLinked <int>(); random.NextUnique(5, 0, 1000, i => { Assert.IsFalse(set.Contains(i)); set.Add(i); }); Assert.IsTrue(set.Count == 5); } { // test shifting from inner value TestingRandom random = new TestingRandom(() => 7); ISet <int> set = new SetHashLinked <int>(); random.NextUnique(5, 0, 1000, i => { Assert.IsFalse(set.Contains(i)); set.Add(i); }); Assert.IsTrue(set.Count == 5); } { // test Random random = new Random(); for (int i = 0; i < 10000; i++) { ISet <int> set = new SetHashLinked <int>(); random.NextUnique(5, 0, 1000, j => { Assert.IsFalse(set.Contains(j)); set.Add(j); }); Assert.IsTrue(set.Count == 5); } } { // test invalid random argument exception TestingRandom random = new TestingRandom(() => 1000); Assert.ThrowsException <ArgumentException>(() => random.NextUnique(5, 0, 1000, i => { })); } { // test invalid random argument exception TestingRandom random = new TestingRandom(() => - 1); Assert.ThrowsException <ArgumentException>(() => random.NextUnique(5, 0, 1000, i => { })); } #endregion #region count >= Math.Sqrt(maxValue - minValue) { // test shifting from maxValue int i = 999; TestingRandom random = new TestingRandom(() => i--); ISet <int> set = new SetHashLinked <int>(); random.NextUnique(100, 0, 1000, j => { Assert.IsFalse(set.Contains(j)); set.Add(j); }); Assert.IsTrue(set.Count == 100); } { // test shifting from 0 TestingRandom random = new TestingRandom(() => 0); ISet <int> set = new SetHashLinked <int>(); random.NextUnique(100, 0, 1000, i => { Assert.IsFalse(set.Contains(i)); set.Add(i); }); Assert.IsTrue(set.Count == 100); } { // test shifting from inner value TestingRandom random = new TestingRandom(() => 7); ISet <int> set = new SetHashLinked <int>(); random.NextUnique(100, 0, 1000, i => { Assert.IsFalse(set.Contains(i)); set.Add(i); }); Assert.IsTrue(set.Count == 100); } { // test Random random = new Random(); for (int i = 0; i < 10000; i++) { ISet <int> set = new SetHashLinked <int>(); random.NextUnique(100, 0, 1000, j => { Assert.IsFalse(set.Contains(j)); set.Add(j); }); Assert.IsTrue(set.Count == 100); } } { // test invalid random argument exception TestingRandom random = new TestingRandom(() => 1000); Assert.ThrowsException <ArgumentException>(() => random.NextUnique(100, 0, 1000, i => { })); } { // test invalid random argument exception TestingRandom random = new TestingRandom(() => - 1); Assert.ThrowsException <ArgumentException>(() => random.NextUnique(100, 0, 1000, i => { })); } #endregion }