コード例 #1
0
        public void TestCompareMaxStars(int s1, int s2, int expected)
        {
            var firstScore  = new Score(new PlayerScore(10), new PlayerScore(15, s1));
            var secondScore = new Score(new PlayerScore(10), new PlayerScore(15, s2));

            foreach (ScoreStrategy scoreStrategy in Enum.GetValues(typeof(ScoreStrategy)))
            {
                foreach (WordStrategy wordStrategy in Enum.GetValues(typeof(WordStrategy)))
                {
                    foreach (bool vortex in new[] { false, true })
                    {
                        foreach (Fix oneFixes in new[] { Fix.None, Fix.All })
                        {
                            foreach (Fix twoMoreFixes in new[] { Fix.None, Fix.All })
                            {
                                var comparer = new PlayInfoComparer(scoreStrategy, wordStrategy);
                                var first    = new PlayInfo(vortex, firstScore, oneFixes, twoMoreFixes);
                                var second   = new PlayInfo(vortex, secondScore, oneFixes, twoMoreFixes);
                                Assert.AreEqual(expected, comparer.Compare(first, second));
                                Assert.AreEqual(-expected, comparer.Compare(second, first));
                                TestSort(comparer, first, second, expected);
                            }
                        }
                    }
                }
            }
        }
コード例 #2
0
 private static void TestSort(PlayInfoComparer comparer, PlayInfo first, PlayInfo second, int expected)
 {
     if (expected != 0)
     {
         var list = new List <PlayInfo> {
             first, second
         };
         list.Sort(comparer);
         list.Reverse();
         Assert.IsTrue(ReferenceEquals(expected < 0 ? second : first, list[0]));
         Assert.IsTrue(ReferenceEquals(expected < 0 ? first : second, list[1]));
     }
 }
コード例 #3
0
        [Test] public void TestCompareWordsNoFixes([Values(false, true)] bool vortex1,
                                                   [Values(false, true)] bool vortex2,
                                                   [Values(Fix.None, Fix.Prefix)] Fix one1,
                                                   [Values(Fix.None, Fix.Prefix)] Fix two1,
                                                   [Values(Fix.None, Fix.Prefix)] Fix one2,
                                                   [Values(Fix.None, Fix.Prefix)] Fix two2)
        {
            var score = new Score(new PlayerScore(10), new PlayerScore(15));

            foreach (ScoreStrategy scoreStrategy in Enum.GetValues(typeof(ScoreStrategy)))
            {
                var comparer = new PlayInfoComparer(scoreStrategy, WordStrategy.NoFixes);
                var first    = new PlayInfo(vortex1, score, one1, two1);
                var second   = new PlayInfo(vortex2, score, one2, two2);
                int expected = GetExpected(vortex1, vortex2, first.HasFixes, second.HasFixes);
                Assert.AreEqual(expected, comparer.Compare(first, second));
                Assert.AreEqual(-expected, comparer.Compare(second, first));
                TestSort(comparer, first, second, expected);
            }
        }
コード例 #4
0
 [Test] public void TestCompareWinsEquals([Values(false, true)] bool vortex1,
                                          [Values(false, true)] bool vortex2,
                                          [Values(Fix.None, Fix.Prefix)] Fix one1,
                                          [Values(Fix.None, Fix.Prefix)] Fix two1,
                                          [Values(Fix.None, Fix.Prefix)] Fix one2,
                                          [Values(Fix.None, Fix.Prefix)] Fix two2)
 {
     foreach (ScoreStrategy score in Enum.GetValues(typeof(ScoreStrategy)))
     {
         foreach (WordStrategy word in Enum.GetValues(typeof(WordStrategy)))
         {
             var firstScore  = new Score(new PlayerScore(PlayerScore.WinPoints - 5), new PlayerScore(PlayerScore.WinPoints));
             var first       = new PlayInfo(vortex1, firstScore, one1, two1);
             var secondScore = new Score(new PlayerScore(PlayerScore.WinPoints - 6), new PlayerScore(PlayerScore.WinPoints + 1));
             var second      = new PlayInfo(vortex2, secondScore, one2, two2);
             var comparer    = new PlayInfoComparer(score, word);
             Assert.AreEqual(-1, comparer.Compare(first, second));
             Assert.AreEqual(1, comparer.Compare(second, first));
             TestSort(comparer, first, second, -1);
         }
     }
 }
コード例 #5
0
 [Test] public void TestCompareWinsFirst([Values(false, true)] bool vortex1,
                                         [Values(false, true)] bool vortex2,
                                         [Values(Fix.None, Fix.Prefix)] Fix one1,
                                         [Values(Fix.None, Fix.Prefix)] Fix two1,
                                         [Values(Fix.None, Fix.Prefix)] Fix one2,
                                         [Values(Fix.None, Fix.Prefix)] Fix two2)
 {
     foreach (ScoreStrategy score in Enum.GetValues(typeof(ScoreStrategy)))
     {
         foreach (WordStrategy word in Enum.GetValues(typeof(WordStrategy)))
         {
             var wonScore   = new Score(new PlayerScore(PlayerScore.WinPoints - 5), new PlayerScore(PlayerScore.WinPoints));
             var won        = new PlayInfo(vortex1, wonScore, one1, two1);
             var otherScore = new Score(new PlayerScore(PlayerScore.WinPoints - 5), new PlayerScore(PlayerScore.WinPoints - 1));
             var other      = new PlayInfo(vortex2, otherScore, one2, two2);
             var comparer   = new PlayInfoComparer(score, word);
             Assert.Less(0, comparer.Compare(won, other));
             Assert.Greater(0, comparer.Compare(other, won));
             TestSort(comparer, won, other, 1);
         }
     }
 }
コード例 #6
0
        [Test] public void TestCompareWordsNone([Values(Fix.None, Fix.Prefix)] Fix one1,
                                                [Values(Fix.None, Fix.Prefix)] Fix two1,
                                                [Values(Fix.None, Fix.Prefix)] Fix one2,
                                                [Values(Fix.None, Fix.Prefix)] Fix two2)
        {
            var score = new Score(new PlayerScore(10), new PlayerScore(15));

            foreach (bool vortex1 in new[] { false, true })
            {
                foreach (bool vortex2 in new[] { false, true })
                {
                    foreach (ScoreStrategy scoreStrategy in Enum.GetValues(typeof(ScoreStrategy)))
                    {
                        var comparer = new PlayInfoComparer(scoreStrategy, WordStrategy.None);
                        var first    = new PlayInfo(vortex1, score, one1, two1);
                        var second   = new PlayInfo(vortex2, score, one2, two2);
                        Assert.AreEqual(0, comparer.Compare(first, second));
                        Assert.AreEqual(0, comparer.Compare(second, first));
                        TestSort(comparer, first, second, 0);
                    }
                }
            }
        }