public void BoolValuesShouldBeReturnedInCycle(int length) { // Arrange var random = new DeterministicRandom(length); // Act var cycle1 = Enumerable.Range(1, length).Select(i => random.NextBool()).ToArray(); var cycle2 = Enumerable.Range(1, length).Select(i => random.NextBool()).ToArray(); var cycle3 = Enumerable.Range(1, length).Select(i => random.NextBool()).ToArray(); // Assert CollectionAssert.AreEqual(cycle1, cycle2); CollectionAssert.AreEqual(cycle2, cycle3); }
public void IntegerValuesShouldBeReturnedInCycle(int length) { // Arrange var random = new DeterministicRandom(length); // Act var cycle1 = Enumerable.Range(1, length).Select(i => random.NextInt()).ToArray(); var cycle2 = Enumerable.Range(1, length).Select(i => random.NextInt()).ToArray(); var cycle3 = Enumerable.Range(1, length).Select(i => random.NextInt()).ToArray(); // Assert CollectionAssert.AreEqual(cycle1, cycle2); CollectionAssert.AreEqual(cycle2, cycle3); }
public void InitializedWithStringShouldWorkAsExpected(string bits) { // Arrange var length = bits.Length; var random = new DeterministicRandom(bits); // Act var cycle1 = Enumerable.Range(1, length).Select(i => random.NextBool()).ToArray(); var cycle2 = Enumerable.Range(1, length).Select(i => random.NextBool()).ToArray(); var cycle3 = Enumerable.Range(1, length).Select(i => random.NextBool()).ToArray(); // Assert CollectionAssert.AreEqual(cycle1, cycle2); CollectionAssert.AreEqual(cycle2, cycle3); for (var i = 0; i < length; ++i) { var bit = bits[i] == '1'; Assert.AreEqual(bit, cycle1[i]); } }
public void InitializedWithStringShouldWorkAsExpected(string bits) { // Arrange var length = bits.Length; var random = new DeterministicRandom(bits); // Act var cycle1 = Enumerable.Range(1, length).Select(i => random.NextBool()).ToArray(); var cycle2 = Enumerable.Range(1, length).Select(i => random.NextBool()).ToArray(); var cycle3 = Enumerable.Range(1, length).Select(i => random.NextBool()).ToArray(); // Assert CollectionAssert.AreEqual(cycle1, cycle2); CollectionAssert.AreEqual(cycle2, cycle3); for (var i = 0; i < length; ++i) { var bit = bits[i] == '1'; Assert.AreEqual(bit, cycle1[i]); } }
public void InitializedRandomlyAndThenReinitializedWithString(int length) { // Arrange var random1 = new DeterministicRandom(length); var bits = random1.ToString(); var random2 = new DeterministicRandom(bits); // Act var cycle11 = Enumerable.Range(1, length).Select(i => random1.NextBool()).ToArray(); var cycle12 = Enumerable.Range(1, length).Select(i => random1.NextBool()).ToArray(); var cycle13 = Enumerable.Range(1, length).Select(i => random1.NextBool()).ToArray(); var cycle21 = Enumerable.Range(1, length).Select(i => random2.NextBool()).ToArray(); var cycle22 = Enumerable.Range(1, length).Select(i => random2.NextBool()).ToArray(); var cycle23 = Enumerable.Range(1, length).Select(i => random2.NextBool()).ToArray(); // Assert CollectionAssert.AreEqual(cycle11, cycle12); CollectionAssert.AreEqual(cycle12, cycle13); CollectionAssert.AreEqual(cycle11, cycle21); CollectionAssert.AreEqual(cycle12, cycle22); CollectionAssert.AreEqual(cycle13, cycle23); }
public void InitializedRandomlyAndThenReinitializedWithString(int length) { // Arrange var random1 = new DeterministicRandom(length); var bits = random1.ToString(); var random2 = new DeterministicRandom(bits); // Act var cycle11 = Enumerable.Range(1, length).Select(i => random1.NextBool()).ToArray(); var cycle12 = Enumerable.Range(1, length).Select(i => random1.NextBool()).ToArray(); var cycle13 = Enumerable.Range(1, length).Select(i => random1.NextBool()).ToArray(); var cycle21 = Enumerable.Range(1, length).Select(i => random2.NextBool()).ToArray(); var cycle22 = Enumerable.Range(1, length).Select(i => random2.NextBool()).ToArray(); var cycle23 = Enumerable.Range(1, length).Select(i => random2.NextBool()).ToArray(); // Assert CollectionAssert.AreEqual(cycle11, cycle12); CollectionAssert.AreEqual(cycle12, cycle13); CollectionAssert.AreEqual(cycle11, cycle21); CollectionAssert.AreEqual(cycle12, cycle22); CollectionAssert.AreEqual(cycle13, cycle23); }
public static void Shuffle <T>(this IList <T> list, DeterministicRandom random) { var elementsCount = list.Count; Shuffle(list, () => random.NextInt() % elementsCount); }
/// <summary> /// Initializes a new instance of <see cref="PatternCollectionGenerator"/>, /// using <see cref="DeterministicRandom"/> to get deterministic output. /// </summary> public PatternCollectionGenerator(DeterministicRandom random) { this.random = random; }
/// <summary> /// Initializes a new instance of <see cref="PatternCollectionGenerator"/>, /// using <see cref="DeterministicRandom"/> to get deterministic output. /// </summary> public PatternCollectionGenerator(DeterministicRandom random) { this.random = random; }
/// <summary> /// Initializes a new instance of <see cref="JContainerGenerator"/>, /// using <see cref="DeterministicRandom"/> to get deterministic output. /// </summary> public JContainerGenerator(DeterministicRandom random) { this.random = random; }
/// <summary> /// Initializes a new instance of <see cref="JContainerGenerator"/>, /// using <see cref="DeterministicRandom"/> to get deterministic output. /// </summary> public JContainerGenerator(DeterministicRandom random) { this.random = random; }
public void GeneratedTests(int arity, int depth, int patternCount) { // Arrange var random = new DeterministicRandom(3000); var treeGenerator = new JContainerGenerator(random); var patternGenerator = new PatternCollectionGenerator(random); var original = treeGenerator.GeneratePerfectTree(arity, depth); var patterns = patternGenerator.GeneratePatterns(original, patternCount); var expected = original.DeepClone(); var actual = original.DeepClone(); // Act expected.NaiveRemove(patterns); actual.Subset(patterns); // Debug Console.WriteLine($"BIT ARRAY:\n{random}\n"); //Console.WriteLine($"PATTERNS:\n{patterns.MergeLines()}\n"); //Console.WriteLine($"ORIGINAL:\n{original.ToPrettyString()}\n"); //Console.WriteLine($"EXPECTED:\n{expected.ToPrettyString()}\n"); //Console.WriteLine($"WAS:\n{actual.ToPrettyString()}\n"); // Assert Assert.That(JToken.DeepEquals(expected, actual)); }