public static void ClassInit(TestContext context)
        {
            serviceProvider = TestStartup.ConfigureServices();

            voteConstructor = serviceProvider.GetRequiredService <VoteConstructor>();
            voteCounter     = serviceProvider.GetRequiredService <IVoteCounter>();
        }
        public void ProcessPostContentsLineTest()
        {
            string testVote = @"[x] Text Nagisa's uncle about her visiting today. Establish a specific time. (Keep in mind Sayaka's hospital visit.)
[x] Telepathy Oriko and Kirika. They probably need to pick up some groceries at this point. It should be fine if you go with them. And of course, you can cleanse their gems too.
[x] Head over to Oriko's.
-[x] 20 minutes roof hopping practice. Then fly the rest of the way.
-[x] Cleansing.
-[x] Take both of them food shopping (or whoever wants to go.)
-[x] Light conversation. No need for serious precog questions right now.";

            string author = "Muramasa";
            string postId = "123456";

            sampleQuest.PartitionMode = PartitionMode.ByLine;
            PostComponents p = new PostComponents(author, postId, testVote);

            p.SetWorkingVote(VoteConstructor.GetWorkingVote);

            VoteConstructor.ProcessPost(p, sampleQuest, CancellationToken.None);

            var votes  = VoteCounter.Instance.GetVotesCollection(VoteType.Vote);
            var voters = VoteCounter.Instance.GetVotersCollection(VoteType.Vote);

            Assert.IsTrue(votes.Count == 7);
            Assert.IsTrue(voters.Count == 1);
        }
Exemple #3
0
        /// <summary>
        /// The second half of tallying the posts involves cycling through for
        /// as long as future references need to be handled.
        /// </summary>
        private async Task ProcessPosts(CancellationToken token)
        {
            var unprocessed = PostsList;

            // Loop as long as there are any more to process.
            while (unprocessed.Any())
            {
                token.ThrowIfCancellationRequested();

                // Get the list of the ones that were processed.
                var processed = unprocessed.Where(p => VoteConstructor.ProcessPost(p, Quest, token) == true).ToList();

                // As long as some got processed, remove those from the unprocessed list
                // and let the loop run again.
                if (processed.Any())
                {
                    unprocessed = unprocessed.Except(processed).ToList();
                }
                else
                {
                    // If none got processed (and there must be at least some waiting on processing),
                    // Set the ForceProcess flag on them to avoid pending FutureReference waits.
                    foreach (var p in unprocessed)
                    {
                        p.ForceProcess = true;
                    }
                }
            }

            await Task.FromResult(0);
        }
        public void TestPartitionPlanBlock()
        {
            string testVote =
                @"[X][Action] Plan One
-[X] Ambush
-[X][Decision] Kill
-[X] Run
[X] Plan Two
-[X] Report";

            List <string> expected = new List <string>(3)
            {
                @"[X][Action] Ambush",
                @"[X][Decision] Kill",
                @"[X][Action] Run",
                @"[X] Report"
            };

            sampleQuest.PartitionMode = PartitionMode.ByBlockAll;
            string         author = "Me";
            string         postId = "123456";
            PostComponents p1     = new PostComponents(author, postId, testVote);

            VoteConstructor.PreprocessPlansWithContent(p1, sampleQuest);
            p1.SetWorkingVote(VoteConstructor.GetWorkingVote);

            VoteConstructor.ProcessPost(p1, sampleQuest, CancellationToken.None);
            var votes = VoteCounter.Instance.GetVotesCollection(VoteType.Vote);

            Assert.IsTrue(votes.Keys.SequenceEqual(expected, Agnostic.StringComparer));
        }
Exemple #5
0
        public static void ClassInit(TestContext context)
        {
            Agnostic.HashStringsUsing(UnicodeHashFunction.HashFunction);

            sampleQuest = new Quest();

            ViewModelService.Instance.Build();

            voteConstructor = ViewModelService.MainViewModel.VoteCounter.VoteConstructor;
        }
Exemple #6
0
        public Tally(IServiceProvider serviceProvider, VoteConstructor constructor,
                     IVoteCounter counter, IGeneralOutputOptions options, ILogger <Tally> logger)
        {
            this.serviceProvider = serviceProvider;
            voteConstructor      = constructor;
            voteCounter          = counter;
            outputOptions        = options;
            this.logger          = logger;

            // Hook up to event notifications
            outputOptions.PropertyChanged += Options_PropertyChanged;
        }
        public static void ClassInit(TestContext context)
        {
            serviceProvider = TestStartup.ConfigureServices();

            voteCounter     = serviceProvider.GetRequiredService <IVoteCounter>();
            tally           = serviceProvider.GetRequiredService <Tally>();
            voteConstructor = serviceProvider.GetRequiredService <VoteConstructor>();
            agnostic        = serviceProvider.GetRequiredService <IAgnostic>();

            IQuest quest = new Quest();

            agnostic.ComparisonPropertyChanged(quest, new System.ComponentModel.PropertyChangedEventArgs(nameof(quest.CaseIsSignificant)));
        }
        public async Task ProcessPostContentsWholeWithReferralTest1()
        {
            sampleQuest.PartitionMode = PartitionMode.None;

            string         testVote   = @"[x] Text Nagisa's uncle about her visiting today. Establish a specific time. (Keep in mind Sayaka's hospital visit.)
[x] Telepathy Oriko and Kirika. They probably need to pick up some groceries at this point. It should be fine if you go with them. And of course, you can cleanse their gems too.
[x] Head over to Oriko's.
-[x] 20 minutes roof hopping practice. Then fly the rest of the way.
-[x] Cleansing.
-[x] Take both of them food shopping (or whoever wants to go.)
-[x] Light conversation. No need for serious precog questions right now.";
            string         author     = "Muramasa";
            string         postId     = "123456";
            int            postNumber = 100;
            PostComponents p1         = new PostComponents(author, postId, testVote, postNumber);

            p1.SetWorkingVote(VoteConstructor.GetWorkingVote);

            VoteConstructor.ProcessPost(p1, sampleQuest, CancellationToken.None);

            string         referralVote = @"[x] Muramasa";
            string         refAuthor    = "Gerbil";
            string         refID        = "123457";
            int            refPostNum   = 101;
            PostComponents p2           = new PostComponents(refAuthor, refID, referralVote, refPostNum);

            VoteCounter.Instance.PostsList.Add(p1);
            VoteCounter.Instance.PostsList.Add(p2);

            List <PostComponents> posts = new List <PostComponents>();

            posts.Add(p1);
            posts.Add(p2);

            await VoteCounter.Instance.TallyPosts(posts, sampleQuest, CancellationToken.None);

            var votes  = VoteCounter.Instance.GetVotesCollection(VoteType.Vote);
            var voters = VoteCounter.Instance.GetVotersCollection(VoteType.Vote);

            Assert.IsTrue(votes.Count == 1);
            Assert.IsTrue(votes.All(v => v.Value.Count == 2));
            Assert.IsTrue(voters.Count == 2);
        }
Exemple #9
0
        /// <summary>
        /// The first half of tallying posts involves doing the preprocessing
        /// work on the plans in the post list.
        /// </summary>
        private async Task PreprocessPlans(CancellationToken token)
        {
            token.ThrowIfCancellationRequested();

            // Preprocessing Phase 1 (Only plans with contents are counted as plans.)
            foreach (var post in PostsList)
            {
                ReferenceVoters.Add(post.Author);
                ReferenceVoterPosts[post.Author] = post.ID;
                VoteConstructor.PreprocessPlansWithContent(post, Quest);
            }

            token.ThrowIfCancellationRequested();

            // Preprocessing Phase 2 (Full-post plans may be named (ie: where the plan name has no contents).)
            // Total vote must have multiple lines.
            foreach (var post in PostsList)
            {
                VoteConstructor.PreprocessPlanLabelsWithContent(post, Quest);
            }

            token.ThrowIfCancellationRequested();

            // Preprocessing Phase 3 (Full-post plans may be named (ie: where the plan name has no contents).)
            // Total vote may be only one line.
            foreach (var post in PostsList)
            {
                VoteConstructor.PreprocessPlanLabelsWithoutContent(post, Quest);
            }

            token.ThrowIfCancellationRequested();

            // Once all the plans are in place, set the working votes for each post.
            foreach (var post in PostsList)
            {
                post.SetWorkingVote(p => VoteConstructor.GetWorkingVote(p));
            }

            await Task.FromResult(0);
        }
        public void ProcessPostContentsTallyTest()
        {
            string testVote = @"『b』Vote Tally『/b』
『color=transparent』##### NetTally 1.0『/color』
[x] Text Nagisa's uncle about her visiting today. Establish a specific time. (Keep in mind Sayaka's hospital visit.)
[x] Telepathy Oriko and Kirika. They probably need to pick up some groceries at this point. It should be fine if you go with them. And of course, you can cleanse their gems too.
[x] Head over to Oriko's.
-[x] 20 minutes roof hopping practice. Then fly the rest of the way.
-[x] Cleansing.
-[x] Take both of them food shopping (or whoever wants to go.)
-[x] Light conversation. No need for serious precog questions right now.";

            string author = "Muramasa";
            string postId = "123456";

            PostComponents p = new PostComponents(author, postId, testVote);

            p.SetWorkingVote(VoteConstructor.GetWorkingVote);

            Assert.IsFalse(p.IsVote);

            VoteConstructor.ProcessPost(p, sampleQuest, CancellationToken.None);
        }
Exemple #11
0
 public VoteCounter()
 {
     VoteConstructor = new VoteConstructor(this);
 }
Exemple #12
0
        /// <summary>
        /// Partitions the child components of a vote into separate vote entries, passing
        /// the voters into those child entries and removing the original.
        /// </summary>
        /// <param name="vote">The vote to partition.</param>
        /// <param name="voteType">The type of vote.</param>
        /// <returns>Returns true if the process was completed, or false otherwise.</returns>
        public bool PartitionChildren(string vote, VoteType voteType)
        {
            if (string.IsNullOrEmpty(vote))
            {
                return(false);
            }

            // No point in partitioning rank votes
            if (voteType == VoteType.Rank)
            {
                return(false);
            }

            // Make sure the provided vote exists
            string voteKey = GetVoteKey(vote, voteType);
            var    votes   = GetVotesCollection(voteType);

            if (votes.ContainsKey(voteKey) == false)
            {
                return(false);
            }

            // Construct the new votes that the vote is being partitioned into.
            var voteLines = vote.GetStringLines();

            if (voteLines.Count < 2)
            {
                return(false);
            }

            var afterVoteLines = voteLines.Skip(1);

            int indentCount = afterVoteLines.Min(a => VoteString.GetVotePrefix(a).Length);

            var promotedVoteLines = afterVoteLines.Select(a => a.Substring(indentCount)).ToList();

            var partitionedVotes = VoteConstructor.PartitionVoteStrings(promotedVoteLines, Quest, PartitionMode.ByBlock);

            HashSet <string> addedVotes = new HashSet <string>();

            var  voters       = votes[voteKey];
            bool votesChanged = false;

            foreach (var v in partitionedVotes)
            {
                var key = GetVoteKey(v, voteType);

                if (!votes.ContainsKey(key))
                {
                    votes[key]   = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
                    votesChanged = true;
                }

                votes[key].UnionWith(voters);

                addedVotes.Add(key);
            }

            UndoBuffer.Push(new UndoAction(UndoActionType.PartitionChildren, voteType, GetVotersCollection(voteType), addedVotes, voteKey, voters));

            Delete(vote, voteType, true);

            if (votesChanged)
            {
                OnPropertyChanged("Votes");
            }

            OnPropertyChanged("VoteCounter");

            return(true);
        }