/// <summary> /// Merges the specified from vote into the specified to vote, assuming the votes aren't the same. /// Moves the voters from the from vote into the to vote list, and removes the from vote's key. /// </summary> /// <param name="fromVote">Vote that is being merged.</param> /// <param name="toVote">Vote that is being merged into.</param> /// <returns>Returns true if there were any changes.</returns> private bool MergeRanks(string fromVote, string toVote) { var votes = GetVotesCollection(VoteType.Rank); Dictionary <KeyValuePair <string, HashSet <string> >, string> mergedVotes = new Dictionary <KeyValuePair <string, HashSet <string> >, string>(); foreach (var vote in votes) { if (VoteString.CondenseVote(vote.Key) == fromVote) { string toContent = VoteString.GetVoteContent(toVote, VoteType.Rank); string toTask = VoteString.GetVoteTask(toVote, VoteType.Rank); string revisedKey = VoteString.ModifyVoteLine(vote.Key, task: toTask, content: toContent); mergedVotes.Add(vote, revisedKey); } } if (mergedVotes.Count > 0) { var voters = GetVotersCollection(VoteType.Rank); UndoBuffer.Push(new UndoAction(UndoActionType.Merge, VoteType.Rank, voters, mergedVotes)); foreach (var merge in mergedVotes) { Rename(merge.Key, merge.Value, VoteType.Rank); } return(true); } return(false); }
public void CondenseVoteTest2() { // Shouldn't be able to generate this working string anymore: string input = "『b』[1] Vote for stuff『/b』"; string expected = "[] "; Assert.AreEqual(expected, VoteString.CondenseVote(input)); }
/// <summary> /// Determines whether the provided vote string can be found in /// condensed form in the rank votes. /// </summary> /// <param name="rankVote">The vote to check for.</param> /// <returns>Returns true if found.</returns> private bool HasCondensedRankVote(string rankVote) { foreach (var vote in RankedVotesWithSupporters) { if (VoteString.CondenseVote(vote.Key) == rankVote) { return(true); } } return(false); }
/// <summary> /// Delete a vote from the vote list specified. /// </summary> /// <param name="vote">The vote to remove.</param> /// <param name="voteType">The type of vote to remove.</param> /// <returns>Returns true if a vote was removed.</returns> public bool Delete(string vote, VoteType voteType, bool suppressUndo = false) { if (string.IsNullOrEmpty(vote)) { return(false); } bool removed = false; var votes = GetVotesCollection(voteType); Dictionary <string, HashSet <string> > deletedVotes = new Dictionary <string, HashSet <string> >(); foreach (var v in votes) { if (v.Key == vote || (voteType == VoteType.Rank && VoteString.CondenseVote(v.Key) == vote)) { deletedVotes.Add(v.Key, v.Value); } } if (deletedVotes.Count > 0) { if (!suppressUndo) { UndoBuffer.Push(new UndoAction(UndoActionType.Delete, voteType, GetVotersCollection(voteType), deletedVotes)); } foreach (var del in deletedVotes) { removed = votes.Remove(del.Key) || removed; } } foreach (var v in deletedVotes) { foreach (var voter in v.Value) { TrimVoter(voter, voteType); } } OnPropertyChanged("VoteCounter"); return(removed); }
public void CondenseVoteTest1() { string input = "[x] Vote for stuff"; string expected = "[] Vote for stuff"; Assert.AreEqual(expected, VoteString.CondenseVote(input)); input = "[1] Vote for stuff"; expected = "[] Vote for stuff"; Assert.AreEqual(expected, VoteString.CondenseVote(input)); input = "[1][Major] Vote for stuff"; expected = "[Major] Vote for stuff"; Assert.AreEqual(expected, VoteString.CondenseVote(input)); input = "[1][Major] 『b』Vote for stuff『/b』"; expected = "[Major] 『b』Vote for stuff『/b』"; Assert.AreEqual(expected, VoteString.CondenseVote(input)); }
/// <summary> /// Gets a list of ranking votes in condensed form. /// </summary> /// <returns>Returns a list of ranking votes in condensed form.</returns> public List <string> GetCondensedRankVotes() { var condensed = RankedVotesWithSupporters.Keys.Select(k => VoteString.CondenseVote(k)).Distinct().ToList(); return(condensed); }
public HashSet <string> GetVoterListForVote(string vote, VoteType voteType) { var votes = VoteCounter.GetVotesCollection(voteType); if (votes.ContainsKey(vote)) { return(votes[vote]); } if (voteType == VoteType.Rank) { var condensedVoters = votes.Where(k => Agnostic.StringComparer.Equals(VoteString.CondenseVote(k.Key), vote)).Select(k => k.Value); HashSet <string> condensedHash = new HashSet <string>(); foreach (var cond in condensedVoters) { condensedHash.UnionWith(cond); } return(condensedHash); } return(null); }