NextBool() public method

Reads next bit and returns a boolean value.
public NextBool ( ) : bool
return bool
        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);
        }
示例#2
0
        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 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]);
            }
        }
示例#4
0
        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]);
            }
        }
        private JContainer GeneratePerfectObject(int arity, int depth)
        {
            var root = new JObject();

            if (depth == 1)
            {
                for (var i = 0; i < arity; ++i)
                {
                    root.Add(i.ToString(), i.ToString());
                }

                return(root);
            }

            for (var i = 0; i < arity; ++i)
            {
                root.Add(i.ToString(), random.NextBool()
                    ? GeneratePerfectObject(arity, depth - 1)
                    : GeneratePerfectArray(arity, depth - 1));
            }

            return(root);
        }
        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);
        }
示例#7
0
        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);
        }
        /// <summary>
        /// Generates a collection of patterns for the specified <see cref="JContainer"/>.
        /// </summary>
        public PatternCollection GeneratePatterns(JContainer root, int desiredCount, bool skipValues = true)
        {
            var descendants = root.DescendantsAndSelf().ToArray();

            descendants.Shuffle(random);

            if (skipValues)
            {
                descendants = descendants.Where(x => x is JObject || x is JArray).ToArray();
            }

            var patterns = descendants
                           .Select(x => x.Path)
                           .Where(x => !string.IsNullOrWhiteSpace(x))
                           .Take(desiredCount)
                           .Select(x => (random.NextBool() ? "!" : "") + x)
                           .Select(AddWildcards)
                           .ToArray();

            return(PatternCollection.Parse(patterns));
        }