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); }
public void DefaultMessageIsEmpty() { var innerRule = new Mock <IRule <string> >(); var rule = new NotRule <string>(innerRule.Object); Assert.IsTrue(string.IsNullOrEmpty(rule.Message)); }
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); }
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)); }
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()); }
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()); }
public void EmptyArrayIsTrue() { var rule = new NotRule(JsonDocument.Parse("[]").RootElement); JsonAssert.IsTrue(rule.Apply()); }
public void NullIsTrue() { var rule = new NotRule(JsonDocument.Parse("null").RootElement); JsonAssert.IsTrue(rule.Apply()); }
public void ObjectThrowsError() { var rule = new NotRule(JsonDocument.Parse("{}").RootElement); Assert.Throws <JsonLogicException>(() => rule.Apply()); }
public void FalseIsTrue() { var rule = new NotRule(false); JsonAssert.IsTrue(rule.Apply()); }
public void TrueIsFalse() { var rule = new NotRule(true); JsonAssert.IsFalse(rule.Apply()); }
public void ZeroIsTrue() { var rule = new NotRule(0); JsonAssert.IsTrue(rule.Apply()); }
public void NonZeroIsFalse() { var rule = new NotRule(1); JsonAssert.IsFalse(rule.Apply()); }
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);
protected override string DescribeNotRule(NotRule <T> rule) { return(string.Format("NOT ({0})", Describe(rule.Rule))); }
public virtual void Visit(NotRule visitee) => visitee.Rule.Accept(this);
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)); }
public void EmptyStringIsTrue() { var rule = new NotRule(""); JsonAssert.IsTrue(rule.Apply()); }
public void NonEmptyStringIsFalse() { var rule = new NotRule("foo"); JsonAssert.IsFalse(rule.Apply()); }
public override void Visit(NotRule visitee) { visitee.Rule.Accept(this); }