Exemplo n.º 1
0
        public void RespondentSatisfiesTwoTerm()
        {
            List <FilterInstruction> fl = new List <FilterInstruction>();

            FilterInstruction fi = new FilterInstruction()
            {
                VarName = "AA001",
                Oper    = Operation.Equals
            };

            fi.ValuesStr.Add("1");

            FilterInstruction fi2 = new FilterInstruction()
            {
                VarName = "AA002",
                Oper    = Operation.Equals
            };

            fi2.ValuesStr.Add("1");

            fl.Add(fi);
            fl.Add(fi2);



            Respondent r = new Respondent();

            r.AddResponse("AA001", "1");
            r.AddResponse("AA002", "1");

            Assert.IsTrue(r.RespondentSatisfiesFilter(fl));
        }
Exemplo n.º 2
0
        public void RespondentFailsNoAnswer()
        {
            LinkedQuestion q = new LinkedQuestion();

            q.PreP = "Ask if AA001=1 and AA002=1.";
            List <FilterInstruction> fl = new List <FilterInstruction>();

            FilterInstruction fi = new FilterInstruction()
            {
                VarName = "AA001",
                Oper    = Operation.Equals
            };

            fi.ValuesStr.Add("1");

            FilterInstruction fi2 = new FilterInstruction()
            {
                VarName = "AA002",
                Oper    = Operation.Equals
            };

            fi.ValuesStr.Add("1");

            fl.Add(fi);
            fl.Add(fi2);

            q.FilterList.Add(fl);

            Respondent r = new Respondent();

            r.AddResponse("AA001", "1");


            Assert.IsFalse(r.RespondentSatisfiesFilter(fl));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Returns true if the provided user should be asked the specified question. The user gets the question if their answers satisfy at least one of the question's
        /// filter scenarios, or if there are no filter scenarios (an Ask all).
        /// </summary>
        /// <param name="r"></param>
        /// <param name="lq"></param>
        /// <returns></returns>
        public bool UserGetsQuestion(Respondent r, LinkedQuestion lq)
        {
            // if there are no filter conditions, it is ask all, so any user gets this question
            if (lq.FilterList.Count == 0)
            {
                return(true);
            }

            if (lq.FilteredOnRtypeOnly())
            {
                return(true);
            }

            // if the VarName was skipped, the user does not get this question
            if (r.Responses.Any(x => x.VarName.Equals(lq.VarName.RefVarName) && x.Skipped))
            {
                return(false);
            }

            // if the respondent has an answer for this question, include it
            if (r.Responses.Any(x => x.VarName.Equals(lq.VarName.RefVarName) && !x.Skipped))
            {
                return(true);
            }

            // for each scenario, if it contains any of the respondent's answers, check them and if they are satisfactory, add to set
            // if there are none that match, add to set
            // if every scenario is not satisfied, skip the question
            int failed = 0;

            foreach (List <FilterInstruction> list in lq.FilterList)
            {
                List <FilterInstruction> f = new List <FilterInstruction>();
                foreach (Answer a in r.Responses)
                {
                    f.AddRange(list.Where(x => x.VarName.Equals(a.VarName)).ToList());
                }

                if (f.Count() == 0)
                {
                    failed++;
                }
                else if (r.RespondentSatisfiesFilter(f))
                {
                    return(true);
                }
                else
                {
                    failed++;
                }
            }

            // if all filter scenarios failed, user does not get the question, return false
            if (failed == lq.FilterList.Count())
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }