示例#1
0
 public void TestExplicitCreation1()
 {
     var p = new Person(0);
     Assert.AreEqual(1, p.FullRanking().Count(), "single candidate, not ranked");
     Assert.AreEqual(0, p.FullRanking().First().candidate, "first candidate");
     Assert.AreEqual(0, p.FullRanking().First().ranking, "first candidate ranking");
     Assert.AreEqual(0, p.Ranking(0), "first candidate direct ranking");
 }
示例#2
0
        private static void TestFullRankingWithOneGoneParameterized(Person p)
        {
            var fr = p.FullRanking(new int[] { 1 }).ToArray();
            Assert.AreEqual(2, fr.Length, "Incorrect number came back");
            CheckContiguous(fr.Select(c => c.ranking).ToArray(), 2);
            var s = new SortedSet<int>(fr.Select(c => c.candidate));
            Assert.IsFalse(s.Contains(1), "candidate 1 should not be in there");

            var fullOrdering = (from c in p.FullRanking()
                                orderby c.ranking ascending
                                select c).ToArray();
            var partialOrdering = (from c in fr
                                   orderby c.ranking ascending
                                   select c).ToArray();

            int i_p = 0;
            for (int i_f = 0; i_f < fullOrdering.Length; i_f++)
            {
                if (fullOrdering[i_f].candidate != 1)
                {
                    if (fullOrdering[i_f].candidate == partialOrdering[i_p].candidate)
                    {
                        i_p++;
                    }
                }
            }
            Assert.AreEqual(partialOrdering.Length, i_p, "Partial list not ordered correctly");
        }
示例#3
0
        public void TestFullRankingWithOneGone2()
        {
            var p = new Person(2, 1, 0);
            Assert.AreEqual(0, p.Ranking(0), "Rank for 0");
            Assert.AreEqual(2, p.Ranking(2), "Rank for 0");
            var ranking = p.FullRanking(1).ToArray();
            Assert.AreEqual(2, ranking.Length, "# of ranked outputs");

            var c0 = ranking.Where(c => c.candidate == 0).First().ranking;
            var c2 = ranking.Where(c => c.candidate == 2).First().ranking;

            Assert.AreEqual(0, c0, "Ranking for candidate 0");
            Assert.AreEqual(1, c2, "Ranking for candidate 2");
        }
示例#4
0
 public void TestFullRankingWithTwoGone()
 {
     var p = new Person(3, new Random());
     var fr = p.FullRanking(new int[] { 1, 0 }).ToArray();
     Assert.AreEqual(1, fr.Length, "Incorrect number came back");
     CheckContiguous(fr.Select(c => c.ranking).ToArray(), 1);
     var s = new SortedSet<int>(fr.Select(c => c.candidate));
     Assert.IsFalse(s.Contains(1), "candidate 1 should not be in there");
     Assert.IsFalse(s.Contains(3), "candidate 3 should not be in there");
 }
示例#5
0
 public void TestFullRanking()
 {
     var p = new Person(3, new Random());
     var fr = p.FullRanking().ToArray();
     CheckContiguous(fr.Select(c => c.ranking).ToArray(), 3);
     CheckContiguous(fr.Select(c => c.candidate).ToArray(), 3);
 }