public void MatchingRuleWithZeroRollout()
        {
            var clause = new ClauseBuilder().Attribute("email").Op("in").Values(LdValue.Of("*****@*****.**")).Build();
            var rule   = new SegmentRule(new List <Clause> {
                clause
            }, 0, null);
            var s = new SegmentBuilder("test").Version(1).Rules(rule).Build();
            var u = User.Builder("foo").Email("*****@*****.**").Build();

            Assert.False(SegmentMatchesUser(s, u));
        }
        public void NonMatchingRuleWithMultipleClauses()
        {
            var clause1 = new ClauseBuilder().Attribute("email").Op("in").Values(LdValue.Of("*****@*****.**")).Build();
            var clause2 = new ClauseBuilder().Attribute("name").Op("in").Values(LdValue.Of("bill")).Build();
            var rule    = new SegmentRule(new List <Clause> {
                clause1, clause2
            }, null, null);
            var s = new SegmentBuilder("test").Version(1).Rules(rule).Build();
            var u = User.Builder("foo").Email("*****@*****.**").Name("bob").Build();

            Assert.False(SegmentMatchesUser(s, u));
        }
            private bool MatchSegmentRule(Segment segment, SegmentRule segmentRule)
            {
                foreach (var c in segmentRule.Clauses)
                {
                    if (!MatchClauseNoSegments(c))
                    {
                        return(false);
                    }
                }

                // If the Weight is absent, this rule matches
                if (!segmentRule.Weight.HasValue)
                {
                    return(true);
                }

                // All of the clauses are met. See if the user buckets in
                var    by     = segmentRule.BucketBy.GetValueOrDefault(UserAttribute.Key);
                double bucket = Bucketing.BucketUser(_user, segment.Key, by, segment.Salt);
                double weight = (double)segmentRule.Weight / 100000F;

                return(bucket < weight);
            }