public void AskingChild(
            string childAnswer,
            IEvaluationEngine parentEngine,
            IEvaluationEngine childEngine)
        {
            "establish an hierarchical evaluation engine"._(() =>
            {
                parentEngine = new EvaluationEngine();
                childEngine  = new EvaluationEngine(parentEngine);

                parentEngine.Solve <Question, string>()
                .AggregateWithExpressionAggregator(ParentAggregator, (aggregate, value) => aggregate + value)
                .ByEvaluating((q, p) => ParentExpression);

                childEngine.Solve <Question, string>()
                .AggregateWithExpressionAggregator(ChildAggregator, (aggregate, value) => aggregate + value)
                .ByEvaluating((q, p) => ChildExpression);
            });

            "when calling answer on a child evaluation engine"._(() =>
            {
                childAnswer = childEngine.Answer(new Question());
            });

            "it should override parent aggregator with child aggregator"._(() =>
            {
                childAnswer.Should().Contain(ChildAggregator);
            });

            "it should use expressions from child and parent"._(() =>
            {
                childAnswer
                .Should().Contain(ParentExpression)
                .And.Contain(ChildExpression);
            });

            "it should evaluate expressions from parent first"._(() =>
            {
                childAnswer.EndsWith(ParentExpression + ChildExpression, StringComparison.Ordinal)
                .Should().BeTrue();
            });
        }
Exemple #2
0
        public void Constraints(
            IEvaluationEngine engine,
            string answer)
        {
            const string NoConstraint        = "N";
            const string WithTrueConstraint  = "T";
            const string WithFalseConstraint = "F";

            "establish a solving strategy with constraints"._(() =>
            {
                engine = new EvaluationEngine();

                engine.Solve <WhatIsTheText, string>()
                .AggregateWithExpressionAggregator(string.Empty, (aggregate, value) => aggregate + value)
                .ByEvaluating((q, p) => NoConstraint)
                .When(q => false)
                .ByEvaluating((q, p) => WithFalseConstraint)
                .When(q => true)
                .ByEvaluating((q, p) => WithTrueConstraint);
            });

            "when calling answer"._(() =>
            {
                answer = engine.Answer(new WhatIsTheText());
            });

            "it should evaluate expressions without constraints"._(() =>
            {
                answer.Should().Contain(NoConstraint);
            });

            "it should evaluate expressions with fulfilled constraints"._(() =>
            {
                answer.Should().Contain(WithTrueConstraint);
            });

            "it should ignore expressions with constraints that are not fulfilled"._(() =>
            {
                answer.Should().NotContain(WithFalseConstraint);
            });
        }
Exemple #3
0
        public void CustomStrategy(
            IEvaluationEngine engine,
            int answer)
        {
            "establish an evaluatione engine"._(() =>
            {
                engine = new EvaluationEngine();
            });

            "when defining an own strategy"._(() =>
            {
                engine.Solve <HowManyFruitsAreThere, int>()
                .With(new SpecialStrategy());

                answer = engine.Answer(new HowManyFruitsAreThere());
            });

            "it should use own strategy instead of default strategy to answer the question"._(() =>
            {
                answer.Should().Be(TheAnswer);
            });
        }
Exemple #4
0
        public void MissingAggregator()
        {
            IEvaluationEngine engine = null;

            Exception exception = null;

            "establish"._(() =>
            {
                engine = new EvaluationEngine();

                engine.Solve <HowManyFruitsAreThere, int>();
            });

            "when calling answer on evaluation engine and no aggregator is specified"._(() =>
            {
                exception = Catch.Exception(() => engine.Answer(new HowManyFruitsAreThere()));
            });

            "it should throw invalid operation exception"._(() =>
            {
                exception.Should().BeOfType <InvalidOperationException>();
            });
        }
        public void CustomAggregator(
            EvaluationEngine engine,
            string answer)
        {
            "establish an evaluation engine"._(() =>
            {
                engine = new EvaluationEngine();
            });

            "when defining an own aggregator"._(() =>
            {
                engine.Solve <MyQuestion, string>()
                .AggregateWith(new MyAggregator())
                .ByEvaluating((q, p) => "hello")
                .ByEvaluating((q, p) => "world");

                answer = engine.Answer(new MyQuestion());
            });

            "it should use own aggregator to aggregate expression results"._(() =>
            {
                answer.Should().Be(" hello world");
            });
        }