当前位置: 首页>>代码示例>>C#>>正文


C# List.Shuffle方法代码示例

本文整理汇总了C#中NUnit.Framework.List.Shuffle方法的典型用法代码示例。如果您正苦于以下问题:C# List.Shuffle方法的具体用法?C# List.Shuffle怎么用?C# List.Shuffle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NUnit.Framework.List的用法示例。


在下文中一共展示了List.Shuffle方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Shuffling_the_same_list_more_than_once_gives_different_results

        public void Shuffling_the_same_list_more_than_once_gives_different_results()
        {
            var list = new List<int>
            {
                0,1,2,3,4,5,6,7,8,9
            };
            var stringRepresentation = StringRepresentation(list);

            Assert.AreNotEqual(StringRepresentation(list.Shuffle()), StringRepresentation(list.Shuffle()));
        }
开发者ID:immeraufdemhund,项目名称:StoneAge,代码行数:10,代码来源:ShuffleTest.cs

示例2: SignatureParameterShouldSortByNameAndValueUsingAscendingByteValueOrdering

        public void SignatureParameterShouldSortByNameAndValueUsingAscendingByteValueOrdering()
        {
            List<BaseStringParameter> sortedParameters = new List<BaseStringParameter>()
            {
                new BaseStringParameter("a2", "r%20b"),
                new BaseStringParameter("a3", "2%20q"),
                new BaseStringParameter("a3", "a"),
                new BaseStringParameter("b5", "%3D%253D"),
                new BaseStringParameter("c%40", ""),
                new BaseStringParameter("c2", ""),
                new BaseStringParameter("oauth_consumer_key", "9djdj82h48djs9d2"),
                new BaseStringParameter("oauth_nonce", "7d8f3e4a"),
                new BaseStringParameter("oauth_signature_method", "HMAC-SHA1"),
                new BaseStringParameter("oauth_timestamp", "137131201"),
                new BaseStringParameter("oauth_token", "kkk9d7dh3k39sjv7")
            };

            List<BaseStringParameter> parameters = new List<BaseStringParameter>(sortedParameters);
            parameters.Shuffle();

            parameters.Sort(new BaseStringParameterComparer());

            // Since version 2.2, NUnit has been able to compare two single-dimensioned arrays.
            // Two arrays or collections will be treated as equal by Assert.AreEqual if they
            // have the same dimensions and if each of the corresponding elements is equal.
            Assert.That(parameters, Is.EqualTo(sortedParameters));
        }
开发者ID:MathieuTurcotte,项目名称:CSharp-OAuth-Client-Library,代码行数:27,代码来源:BaseStringParameterComparerTest.cs

示例3: can_shuffle

 public void can_shuffle()
 {
     var ints = new List<int>();
     1.UpTo(500, ints.Add);
     ints.Shuffle();
     (ints[0] == 1 && ints[1] == 2 && ints.Last() == 500).ShouldBeFalse();
     ints.Distinct().Count().ShouldEqual(500);
 }
开发者ID:ignu,项目名称:ruebee,代码行数:8,代码来源:EnumerableSpecs.cs

示例4: ShuffleShouldReturnAllOfTheGivenElements

 public void ShuffleShouldReturnAllOfTheGivenElements()
 {
     var list = new List<int> { int.MinValue, -1, 0, 1, 100, int.MaxValue };
     var shuffledList = list.Shuffle().ToList();
     Assert.AreEqual(list.Count, shuffledList.Count);
     foreach (var item in list)
     {
         Assert.IsTrue(shuffledList.Contains(item));
     }
 }
开发者ID:dtopalov,项目名称:TexasHoldemGameEngine,代码行数:10,代码来源:EnumerableExtensionsTests.cs

示例5: Shuffles_10_numbers

        public void Shuffles_10_numbers()
        {
            var list = new List<int>
            {
                0,1,2,3,4,5,6,7,8,9
            };
            var stringRepresentation = StringRepresentation(list);

            Assert.IsNotEmpty(list.Shuffle());
            Assert.AreNotEqual(stringRepresentation, StringRepresentation(list));
        }
开发者ID:immeraufdemhund,项目名称:StoneAge,代码行数:11,代码来源:ShuffleTest.cs

示例6: ShuffleShouldNotChangeOriginalObjectItemsOrder

 public void ShuffleShouldNotChangeOriginalObjectItemsOrder()
 {
     var list = new List<int> { int.MinValue, -1, 0, 1, 100, int.MaxValue };
     list.Shuffle();
     Assert.AreEqual(int.MinValue, list[0]);
     Assert.AreEqual(-1, list[1]);
     Assert.AreEqual(0, list[2]);
     Assert.AreEqual(1, list[3]);
     Assert.AreEqual(100, list[4]);
     Assert.AreEqual(int.MaxValue, list[5]);
 }
开发者ID:dtopalov,项目名称:TexasHoldemGameEngine,代码行数:11,代码来源:EnumerableExtensionsTests.cs

示例7: Shuffle_WorksFine

        public void Shuffle_WorksFine()
        {
            //arrange
            var list1 = new List<int>
                            {
                                1,2,3,4,5,6,7,8,9,0,11,12,13,14,15,16
                            };
            var list2 = new List<int>
                            {
                                1,2,3,4,5,6,7,8,9,0,11,12,13,14,15,16
                            };
            //assume
            CollectionAssert.AreEqual(list1,list2);

            //act
            list1.Shuffle();
            list2.Shuffle();

            //assert
            CollectionAssert.AreEqual(list1, list2);
        }
开发者ID:danielfishr,项目名称:DotNetExtensions,代码行数:21,代码来源:ListExtensionTest.cs

示例8: Test_Shuffle_On_List

 public void Test_Shuffle_On_List()
 {
     bool different = false;
     var array1 = new List<char> {'a', 'b', 'c', 'd'};
     var array2 = array1.Shuffle();
     for (int i = 0; i < array1.Count; i++)
     {
         different = array1[i] == array2[i];
         if (different)
         {
             break;
         }
     }
     Assert.IsTrue(different);
 }
开发者ID:WhallaLabs,项目名称:couchbase-net-client,代码行数:15,代码来源:ArrayExtensionsTests.cs

示例9: Empty_list_does_not_throw

        public void Empty_list_does_not_throw()
        {
            var list = new List<int>();

            Assert.IsEmpty(list.Shuffle());
        }
开发者ID:immeraufdemhund,项目名称:StoneAge,代码行数:6,代码来源:ShuffleTest.cs

示例10: Can_remove_all_4_Players_in_any_order

        public void Can_remove_all_4_Players_in_any_order()
        {
            var ids = new List<Guid>();
            var player1 = game.AddPlayer().Value;
            ids.Add(player1);
            var player2 = game.AddPlayer().Value;
            ids.Add(player2);
            var player3 = game.AddPlayer().Value;
            ids.Add(player3);
            var player4 = game.AddPlayer().Value;
            ids.Add(player4);
            ids.Shuffle();

            foreach (var id in ids)
            {
                var result = game.RemovePlayer(id);
                Assert.IsTrue(result.Successful);
            }
        }
开发者ID:immeraufdemhund,项目名称:StoneAge,代码行数:19,代码来源:GameTest.cs

示例11: TestShuffle

        public void TestShuffle()
        {
            Assert.Throws<ArgumentNullException>(() => { CollectionExtensions.Shuffle<string>(null); });

            var list = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            Assert.DoesNotThrow(() => { { list.Shuffle(); };});
            Assert.AreEqual(10, list.Count);
            for (int i = 1; i <= 10; i++)
                Assert.IsTrue(list.Contains(i));
        }
开发者ID:RT-Projects,项目名称:RT.Util,代码行数:10,代码来源:CollectionExtensionsTests.cs

示例12: IsNotEqual

        public void IsNotEqual()
        {
            var range = new List<NumericValue>(_allNumericValues);
            range.Remove(NumericValue.Eight);

            var shuffledA = range.Shuffle(25);
            var shuffledB = range.Shuffle(890);
            shuffledB.RemoveAt(0);

            var cellA = Factory.Instance.CreateEmptyCell();
            var cellB = Factory.Instance.CreateEmptyCell();

            Assert.That(!cellA.Equals(null));

            foreach (var remove in shuffledA)
            {
                cellA = cellA.ExcludeValue(remove);
            }

            foreach (var remove in shuffledB)
            {
                cellB = cellB.ExcludeValue(remove);
            }

            Assume.That(!cellA.Equals(cellB));
        }
开发者ID:WinstonSmith77,项目名称:Sudoku,代码行数:26,代码来源:CellTests.cs

示例13: RandomGame1

        public void RandomGame1(int testCase, int gameIndex)
        {
            Random random;
            Game game;
            if (testCase == -1)
            {
                var seed = (int)(DateTime.UtcNow.ToFileTime() % int.MaxValue);
                random = new Random(seed);
                Console.WriteLine(seed);
            }
            else
            {
                random = new Random(testCase);
            }
            if (gameIndex == -1)
            {
                var deck = new List<Card> {
                    Card.B9, Card.B0, Card.BJ, Card.BQ, Card.BA,
                    Card.CQ, Card.CK, Card.CA, Card.T7, Card.TK,
                    Card.C7, Card.C8, Card.C9, Card.C0, Card.CJ,
                    Card.AJ, Card.T8,
                    Card.T9, Card.T0, Card.TJ, Card.TQ, Card.TA,
                    Card.A7, Card.A8, Card.A9, Card.A0, Card.BK,
                    Card.AQ, Card.AK, Card.AA, Card.B7, Card.B8
                };

                do
                {
                    deck.Shuffle(random);
                } while (deck[15].HasPoints() || deck[16].HasPoints() || deck[15] == Card.T7 || deck[16] == Card.T7);

                game = new Game(Player.P2, deck.ToArray());
            }
            else
            {
                game = games[gameIndex];
            }

            for (int turn = 0; turn < 30; turn++)
            {
                Console.WriteLine(game);
                var possibleTurns = game.PossibleTurns().ToList();
                Console.Write("Choices: ");
                for (int c = 0; c < possibleTurns.Count; c++)
                {
                    if (c != 0)
                    {
                        Console.Write(",");
                    }
                    var choice = possibleTurns[c];
                    Console.Write(choice.ToString());
                }
                Console.WriteLine();

                var next = random.Next(possibleTurns.Count);
                Card playedCard = possibleTurns[next];
                Console.WriteLine($"Choice: {playedCard}");
                Console.WriteLine();
                game = game.MakeTurn(playedCard);
            }
            Console.WriteLine(game);
        }
开发者ID:pavelsavara,项目名称:marias,代码行数:62,代码来源:RandomTest.cs

示例14: Test_Shuffle_On_List

        public void Test_Shuffle_On_List()
        {
            var savedRandom = ArrayExtensions.Random;
            try
            {
                // Use a random number generator with a known seed for consistency
                ArrayExtensions.Random = new Random(500);

                bool different = false;
                var array1 = new List<char> {'a', 'b', 'c', 'd'};
                var array2 = array1.Shuffle();
                for (int i = 0; i < array1.Count; i++)
                {
                    different = array1[i] == array2[i];
                    if (different)
                    {
                        break;
                    }
                }
                Assert.IsTrue(different);
            }
            finally
            {
                ArrayExtensions.Random = savedRandom;
            }
        }
开发者ID:brantburnett,项目名称:couchbase-net-client,代码行数:26,代码来源:ArrayExtensionsTests.cs


注:本文中的NUnit.Framework.List.Shuffle方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。