public given_CTB_Assessment_when_Nationality_eq_UK_and_UkPart_eq_England() { // get a decisionTree with lambdas... _q = QuestionnaireFactory.GetCtbQuestionnaire(); // get the next question, which is the first question var d1 = _q.GetNext(_q) as NationalityDecision; // poke UK answer on the mutator d1.Mutator(d1, new NationalityDecision { NationalityEnum = NationalityEnum.UK, Amount = 0.0f, Result = 1 }); // get next question given the current state the assessment var d2 = _q.GetFollowOnDecisionBranch(_q.Result); // poke UK answer on the mutator d2.Mutator(d2, new UkPartDecision { UkPartEnum = UkPartEnum.England, Amount = 0.0f, Result = 1 }); // get next question given the current state the assessment nxt = d2.GetFollowOnDecisionBranch(_q.Result); ///////////////////////////////// // REFACTOR : asserting on d2 here but should be asserting on 1 ?.... }
public IDecision EvaluateNextOneGetFollowOnBranch(IDecision questionnaire) { IDecision q = questionnaire; if (q.Result == 0) { q.Mutator(q, null); } var nxt = q.GetFollowOnDecisionBranch(q.Result); q = nxt; return(q); }
public given_CTB_Assessment_when_Nationality_eq_UK() { // get a decisionTree with lambdas... _q = QuestionnaireFactory.GetCtbQuestionnaire(); // get the next question, which is the first question var d1 = _q.GetNext(_q) as NationalityDecision; // poke answer on the mutator d1.Mutator(d1, new NationalityDecision { NationalityEnum = NationalityEnum.UK, Amount = 0.0f, Result = 1 }); // get next question given the current state the assessment nxt = _q.GetFollowOnDecisionBranch(_q.Result); }
private static void doCornerShopQuestionnaireDemo() { // get a decisionTree with lambdas... var questionnaire = CornerShopQuestionnaireFactory.GetCornerShopQuestionnaire(); #region Commented : setting a 'canned' answer on the root of the questionnaire //var startDecision = questionnaire.GetNext(questionnaire) as CornerShopStartDecision; //if (startDecision != null) //{ // startDecision.Result = 1; //} #endregion Commented : setting a 'canned' answer on the root of the questionnaire Console.ReadLine(); #region Evaluation at the console // 1. Evaluate all at the console ... //questionnaire.Evaluate(); #endregion Evaluation at the console #region Evaluation at the console 1-by-1 // 2. Evaluate current and then next one until no more next ones ... //IDecision q = questionnaire; //while ( q != null) //{ // q = q.EvaluateNextOneGetFollowOnBranch(q); //} #endregion Evaluation at the console 1-by-1 #region Evaluation at the console // 3. Evaluating one at a time, with access to the mutator IDecision q = questionnaire; while (q != null) { if (q.Result == 0) { q.Mutator(q, null); } var nxt = q.GetFollowOnDecisionBranch(q.Result); q = nxt; } #endregion Evaluation at the console #region Explanation of the choices // cw summary of the users answers to the questions var explanation = questionnaire.Explantion(); Console.WriteLine("{0}", explanation); #endregion Explanation of the choices #region Cost associated with the questionnaire user choices // cw the cost associated with answers to the questions var chosenOnes = questionnaire.ChosenOnes(null); var cost = chosenOnes.Aggregate(0.0f, (current, chosenOne) => current + chosenOne.Amount); Console.WriteLine("cost: {0}", cost); #endregion Cost associated with the questionnaire user choices // press a key to continue Console.ReadLine(); }