Exemple #1
0
        /// <summary>
        /// The first half of tallying posts involves doing the preprocessing
        /// work on the plans in the post list.
        /// </summary>
        public async Task <IDictionary <string, VoteLineBlock> > PreprocessPosts(CancellationToken token)
        {
            if (voteCounter.Quest is null)
            {
                return(new Dictionary <string, VoteLineBlock>(StringComparer.Ordinal));
            }

            foreach (var post in voteCounter.Posts)
            {
                // Reset the processed state of all the posts.
                post.Processed           = false;
                post.ForceProcess        = false;
                post.WorkingVoteComplete = false;
                post.WorkingVote.Clear();
                voteCounter.AddReferenceVoter(post.Origin);
            }

            List <(bool asBlocks, Func <IEnumerable <VoteLine>, (bool isPlan, bool isImplicit, string planName)> isPlanFunction)> planProcesses =
                new List <(bool asBlocks, Func <IEnumerable <VoteLine>, (bool isPlan, bool isImplicit, string planName)> isPlanFunction)>()
            {
                (asBlocks : true, isPlanFunction : VoteBlocks.IsBlockAProposedPlan),
                (asBlocks : true, isPlanFunction : VoteBlocks.IsBlockAnExplicitPlan),
                (asBlocks : false, isPlanFunction : VoteBlocks.IsBlockAnImplicitPlan),
                (asBlocks : false, isPlanFunction : VoteBlocks.IsBlockASingleLinePlan)
            };

            // Run the above series of preprocessing functions to extract plans from the post list.
            var allPlans = RunPlanPreprocessing(voteCounter.Posts, voteCounter.Quest, planProcesses, token);

            await Task.FromResult(0).ConfigureAwait(false);

            return(allPlans);
        }
        public void Simple_Reference()
        {
            quest.PartitionMode     = PartitionMode.ByLine;
            quest.DisableProxyVotes = false;
            voteCounter.Quest       = quest;

            string voteText1 = oneLine;
            string voteText2 = refKinematics;
            Post   post1     = GetPostFromKinematics1(voteText1);
            Post   post2     = GetPostFromAtreya(voteText2);

            List <Post> posts = new List <Post>()
            {
                post1, post2
            };

            voteCounter.AddPosts(posts);
            voteCounter.AddReferenceVoter(post1.Origin);
            voteCounter.AddReferenceVoter(post2.Origin);

            var results1 = voteConstructor.ProcessPostGetVotes(post1, quest);

            if (results1 != null)
            {
                voteCounter.AddVotes(results1, post1.Origin);

                var results2 = voteConstructor.ProcessPostGetVotes(post2, quest);

                if (results2 != null)
                {
                    Assert.IsTrue(results1[0].Lines[0] == results2[0].Lines[0]);

                    voteCounter.AddVotes(results2, post2.Origin);

                    Assert.AreEqual(2, voteCounter.VoteStorage.GetSupportCountFor(results1[0]));
                }

                Assert.IsFalse(results2 == null);
            }

            Assert.IsFalse(results1 == null);
        }