public void MessagePassedToConstructorIsReturned()
 {
     const string Msg = "msg";
     var innerRule = new Mock<IRule<string>>();
     var rule = new NotRule<string>(innerRule.Object, Msg);
     Assert.AreEqual(Msg, rule.Message);
 }
Ejemplo n.º 2
0
        public void DefaultMessageIsEmpty()
        {
            var innerRule = new Mock <IRule <string> >();
            var rule      = new NotRule <string>(innerRule.Object);

            Assert.IsTrue(string.IsNullOrEmpty(rule.Message));
        }
Ejemplo n.º 3
0
        public void MessagePassedToConstructorIsReturned()
        {
            const string Msg       = "msg";
            var          innerRule = new Mock <IRule <string> >();
            var          rule      = new NotRule <string>(innerRule.Object, Msg);

            Assert.AreEqual(Msg, rule.Message);
        }
Ejemplo n.º 4
0
 private static void Part1()
 {
     var lines = File.ReadAllLines("input1.txt");
     var hasVowelsRule = new HasVowelsRule();
     var hasAdjacentEqualLettersRule = new HasAdjacentEqualLettersRule();
     var doesNotHaveSubstringsRule = new NotRule(new HasSubstrings());
     var rules = new IRule[] {hasVowelsRule, hasAdjacentEqualLettersRule, doesNotHaveSubstringsRule,};
     var result = lines.Count(line => rules.All(x => x.Check(line)));
     Console.WriteLine(result);
 }
        protected override string DescribeNotRule(NotRule <T> rule)
        {
            var result      = DescribeResult(rule.IsTrueFor(evaluateWith));
            var description = Describe(rule.Rule);

            if (NeedsParenthesis(rule, rule.Rule))
            {
                description = string.Format("({0})", description);
            }

            return(string.Format("NOT[{1}] {0}", description, result));
        }
Ejemplo n.º 6
0
        public void Day_ShouldNotMatch_Monday(int year, int month, int day, bool expected)
        {
            var rule = new NotRule
            {
                ReferencedRule = new DayOfWeekRule()
                {
                    DayOfWeek = DayOfWeek.Monday
                }
            };

            Process(rule).IsMatch(new DateTime(year, month, day))
            .Should().Be(expected);
        }
 public void ResultIsNegationOfInnerRuleResult()
 {
     var innerRule = new Mock<IRule<string>>();
     innerRule.Setup(r => r.IsValid(bool.TrueString)).Returns(true);
     innerRule.Setup(r => r.IsValid(bool.FalseString)).Returns(false);
     var rule = new NotRule<string>(innerRule.Object);
     var candidate1 = rule.IsValid(bool.TrueString);
     var candidate2 = rule.IsValid(bool.FalseString);
     Assert.IsFalse(candidate1);
     Assert.IsTrue(candidate2);
     innerRule.Verify(r => r.IsValid(bool.TrueString), Times.Once());
     innerRule.Verify(r => r.IsValid(bool.FalseString), Times.Once());
 }
Ejemplo n.º 8
0
        public void ResultIsNegationOfInnerRuleResult()
        {
            var innerRule = new Mock <IRule <string> >();

            innerRule.Setup(r => r.IsValid(bool.TrueString)).Returns(true);
            innerRule.Setup(r => r.IsValid(bool.FalseString)).Returns(false);
            var rule       = new NotRule <string>(innerRule.Object);
            var candidate1 = rule.IsValid(bool.TrueString);
            var candidate2 = rule.IsValid(bool.FalseString);

            Assert.IsFalse(candidate1);
            Assert.IsTrue(candidate2);
            innerRule.Verify(r => r.IsValid(bool.TrueString), Times.Once());
            innerRule.Verify(r => r.IsValid(bool.FalseString), Times.Once());
        }
Ejemplo n.º 9
0
        public void EmptyArrayIsTrue()
        {
            var rule = new NotRule(JsonDocument.Parse("[]").RootElement);

            JsonAssert.IsTrue(rule.Apply());
        }
Ejemplo n.º 10
0
        public void NullIsTrue()
        {
            var rule = new NotRule(JsonDocument.Parse("null").RootElement);

            JsonAssert.IsTrue(rule.Apply());
        }
Ejemplo n.º 11
0
        public void ObjectThrowsError()
        {
            var rule = new NotRule(JsonDocument.Parse("{}").RootElement);

            Assert.Throws <JsonLogicException>(() => rule.Apply());
        }
Ejemplo n.º 12
0
        public void FalseIsTrue()
        {
            var rule = new NotRule(false);

            JsonAssert.IsTrue(rule.Apply());
        }
Ejemplo n.º 13
0
        public void TrueIsFalse()
        {
            var rule = new NotRule(true);

            JsonAssert.IsFalse(rule.Apply());
        }
Ejemplo n.º 14
0
        public void ZeroIsTrue()
        {
            var rule = new NotRule(0);

            JsonAssert.IsTrue(rule.Apply());
        }
Ejemplo n.º 15
0
        public void NonZeroIsFalse()
        {
            var rule = new NotRule(1);

            JsonAssert.IsFalse(rule.Apply());
        }
Ejemplo n.º 16
0
        protected override string DescribeNotRule(NotRule <T> rule)
        {
            var result = DescribeResult(rule.IsTrueFor(evaluateWith));

            return(string.Format("NOT ({0})[{1}]", Describe(rule.Rule), result));
        }
 protected abstract string DescribeNotRule(NotRule <T> rule);
Ejemplo n.º 18
0
 protected override string DescribeNotRule(NotRule <T> rule)
 {
     return(string.Format("NOT ({0})", Describe(rule.Rule)));
 }
Ejemplo n.º 19
0
 public virtual void Visit(NotRule visitee) => visitee.Rule.Accept(this);
Ejemplo n.º 20
0
        private Rule Interpret(Grammar grammar, ISemanticNode node)
        {
            Rule rule = null;

            if (node is BranchSemanticNode branch)
            {
                switch ((EbnfNodeType)branch.NodeType)
                {
                case EbnfNodeType.Group:
                    rule = Interpret(grammar, branch.Children[0]);
                    break;

                case EbnfNodeType.Repeat:
                    rule = new RepeatRule(grammar, Interpret(grammar, branch.Children[0]));
                    break;

                case EbnfNodeType.Optional:
                    rule = new OptionalRule(grammar, Interpret(grammar, branch.Children[0]));
                    break;

                case EbnfNodeType.Not:
                    rule = new NotRule(grammar, Interpret(grammar, branch.Children[0]));
                    break;

                case EbnfNodeType.And:
                    rule = new AndRule(grammar, branch.Children.Select(child => Interpret(grammar, child)));
                    break;

                case EbnfNodeType.Or:
                    rule = new OrRule(grammar, branch.Children.Select(child => Interpret(grammar, child)));
                    break;

                case EbnfNodeType.None:
                    rule = Interpret(grammar, branch.Children.Single());
                    break;

                case EbnfNodeType.Root:
                case EbnfNodeType.Rule:
                case EbnfNodeType.Token:
                default:
                    throw new Exception();
                }
            }
            else if (node is LeafSemanticNode leaf)
            {
                switch ((EbnfNodeType)leaf.NodeType)
                {
                case EbnfNodeType.Identifier:
                    rule = grammar.ReferenceRule(leaf.Value);
                    break;

                case EbnfNodeType.String:
                case EbnfNodeType.Regex:
                    break;

                default:
                    throw new Exception();
                }
            }

            if (rule == null)
            {
                throw new Exception();
            }
            else
            {
                return(rule);
            }
        }
 public void DefaultMessageIsEmpty()
 {
     var innerRule = new Mock<IRule<string>>();
     var rule = new NotRule<string>(innerRule.Object);
     Assert.IsTrue(string.IsNullOrEmpty(rule.Message));
 }
Ejemplo n.º 22
0
        public void EmptyStringIsTrue()
        {
            var rule = new NotRule("");

            JsonAssert.IsTrue(rule.Apply());
        }
Ejemplo n.º 23
0
        public void NonEmptyStringIsFalse()
        {
            var rule = new NotRule("foo");

            JsonAssert.IsFalse(rule.Apply());
        }
 public override void Visit(NotRule visitee)
 {
     visitee.Rule.Accept(this);
 }