Exemplo n.º 1
0
        public void StatisticallyDistributed5050()
        {
            const int total     = 1000000;
            var       trueCases = Enumerable.Repeat(0, total).Count(i => RandomValue.Bool());
            var       ratio     = trueCases / (double)total;

            ratio.ShouldBeInRange(0.49, 0.51);
        }
            protected override SyntaxTreeNode Visit(TextNode node)
            {
                if (!RandomValue.Bool())
                {
                    return(base.Visit(node));
                }

                return(new TextNode(node.Text, node.HtmlTemplate));
            }
            protected override SyntaxTreeNode Visit(TagNode node)
            {
                var baseResult = base.Visit(node);

                if (!RandomValue.Bool())
                {
                    return(baseResult);
                }
                return(baseResult.SetSubNodes(baseResult.SubNodes.ToList()));
            }
Exemplo n.º 4
0
 public void Setup()
 {
     _validModel = new TestModel
     {
         TestGuid   = RandomValue.Guid(),
         TestBool   = RandomValue.Bool(),
         TestDate   = RandomValue.DateTime(),
         TestInt    = RandomValue.Int(),
         TestString = RandomValue.String()
     };
     _sut = new TestModelHelper <TestModel>(_validModel);
 }
        public void RandomBoolShouldProduceTrueApprox50PercentOfTheTime()
        {
            var randomBools = new List <bool>();

            for (int i = 0; i < 1000; i++)
            {
                randomBools.Add(RandomValue.Bool());
            }

            var listOfTrues = randomBools.Where(x => x == true);

            listOfTrues.Count().ShouldBeInRange(400, 600);
        }
Exemplo n.º 6
0
        static SyntaxTreeNode CreateNode(BBTag[] allowedTags, bool allowText)
        {
            switch (new[] { allowText ? 0 : 1, 2 }[RandomValue.Int(1, 0)])
            {
            case 0:
                var text = RandomValue.String();
                return(new TextNode(text));

            case 1:
                var tag  = allowedTags[RandomValue.Int(allowedTags.Length, 0)];
                var node = new TagNode(tag);

                AddSubnodes(allowedTags, node);

                if (tag.Attributes != null)
                {
                    var selectedIds = new List <string>();
                    foreach (var attr in tag.Attributes)
                    {
                        if (!selectedIds.Contains(attr.ID) && RandomValue.Bool())
                        {
                            string val;
                            do
                            {
                                val = RandomValue.String();
                            } while (val.IndexOfAny("[] ".ToCharArray()) != -1);

                            node.AttributeValues[attr] = val;
                            selectedIds.Add(attr.ID);
                        }
                    }
                }
                return(node);

            default:
                //PexAssume.Fail();
                return(null);
            }
        }