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


C# List.Min方法代码示例

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


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

示例1: AllComputationsOfMinMaxTaskSolverAreCorrect

        public void AllComputationsOfMinMaxTaskSolverAreCorrect()
        {
            var numbersCount = 1000*1000;
            var threadsCount = 10;

            var formatter = new BinaryFormatter();
            var rand = new Random();

            var stopwatch = new Stopwatch();
            stopwatch.Start();

            var numbers = new List<int>(numbersCount);
            for (var i = 0; i < numbersCount; i++)
            {
                numbers.Add(rand.Next(int.MinValue, int.MaxValue));
            }
            Debug.WriteLine(stopwatch.ElapsedMilliseconds/1000.0 + ": " + numbersCount + " numbers generated ");

            var expectedMinimum = numbers.Min();
            var expectedMaximum = numbers.Max();
            Debug.WriteLine(stopwatch.ElapsedMilliseconds/1000.0 + ": " + " expected results found");

            var problem = new MmProblem(numbers);
            Debug.WriteLine(stopwatch.ElapsedMilliseconds/1000.0 + ": " + "problem created ");

            byte[] problemData;
            using (var memoryStream = new MemoryStream())
            {
                formatter.Serialize(memoryStream, problem);
                problemData = memoryStream.ToArray();
            }
            Debug.WriteLine(stopwatch.ElapsedMilliseconds/1000.0 + ": " + "problem serialized");

            var taskSolver = new MmTaskSolver(problemData);
            var partialProblemsData = taskSolver.DivideProblem(threadsCount);
            Debug.WriteLine(stopwatch.ElapsedMilliseconds/1000.0 + ": " + "problem divided; threadsCount=" +
                            threadsCount);

            var partialSolutionsData = new List<byte[]>(partialProblemsData.Length);
            foreach (var partialProblemData in partialProblemsData)
            {
                var partialSolutionData = taskSolver.Solve(partialProblemData, new TimeSpan());
                partialSolutionsData.Add(partialSolutionData);
            }
            Debug.WriteLine(stopwatch.ElapsedMilliseconds/1000.0 + ": " + "partial solutions solved");

            var finalSolutionData = taskSolver.MergeSolution(partialSolutionsData.ToArray());
            Debug.WriteLine(stopwatch.ElapsedMilliseconds/1000.0 + ": " + "problems merged");

            using (var memoryStream = new MemoryStream(finalSolutionData))
            {
                var finalSolution = (MmSolution) formatter.Deserialize(memoryStream);
                Assert.AreEqual(finalSolution.Min, expectedMinimum);
                Assert.AreEqual(finalSolution.Max, expectedMaximum);
            }
            Debug.WriteLine(stopwatch.ElapsedMilliseconds/1000.0 + ": " + "final solution deserialized");

            stopwatch.Stop();
        }
开发者ID:progala2,项目名称:DVRP,代码行数:59,代码来源:MMTaskSolverTests.cs

示例2: GenericComparerAsIComparer

        public void GenericComparerAsIComparer()
        {
            List<int> ints = new List<int>(new[] { 10, 5, 2, 23, 7, 5, 3, 45, 23, 64, 25 });

            ints.Sort(new GenericComparer<int>());

            Assert.AreEqual(ints.Min(), ints.First());
            Assert.AreEqual(ints.Max(), ints.Last());

            ints.Sort(new GenericComparer<int>((i, i1) => Math.Sin(i) > Math.Sin(i1) ? -1 : Math.Sin(i) < Math.Sin(i1) ? 1 : 0));

            Assert.AreEqual(64, ints.First());
            Assert.AreEqual(5, ints.Last());
        }
开发者ID:radicalgeek,项目名称:Common,代码行数:14,代码来源:GenericComparerTests.cs

示例3: TestMemory

 public void TestMemory()
 {
     Process currentProcess = System.Diagnostics.Process.GetCurrentProcess();
     long initial = currentProcess.WorkingSet64;
     List<long> measurements = new List<long>() { initial };
     List<Model> models = new List<Model>();
     for (var i = 0; i < 15; i++)
     {
         models.Add(Load());
         measurements.Add(currentProcess.WorkingSet64);
     }
     var peak = currentProcess.PeakWorkingSet64;
     var min = measurements.Min();
     var max = measurements.Max();
     var final = currentProcess.WorkingSet64;
 }
开发者ID:danielwerthen,项目名称:Funcis-Sharp,代码行数:16,代码来源:TestSomethings.cs

示例4: CompareTo_TestWithListOfMinAndMax

        public void CompareTo_TestWithListOfMinAndMax()
        {
            List<RoadType> MinMaxList = new List<RoadType>();

            MinMaxList.Add(new RoadType("Motorvej", 100));
            MinMaxList.Add(new RoadType("MiscVej", 60));
            MinMaxList.Add(new RoadType("VillaVej", 20));
            MinMaxList.Add(new RoadType("MotorTrafikVej", 90));
            MinMaxList.Add(new RoadType("Racerbane", 250));

            RoadType min = MinMaxList.Min();
            RoadType max = MinMaxList.Max();

            Assert.AreSame(min, MinMaxList[2]);
            Assert.AreSame(max, MinMaxList[4]);
            
        }
开发者ID:Stg3orge,项目名称:P2-Simulering,代码行数:17,代码来源:RoadTypeTests.cs

示例5: RollBetweenOneAndTwelve

        public void RollBetweenOneAndTwelve()
        {
            var dice = new MonopolyDice();
            var rolls = new List<Int32>();

            for (var i = 0; i < 1000000; i++)
            {
                dice.RollTwoDice();
                rolls.Add(dice.Value);
            }

            var max = rolls.Max();
            var min = rolls.Min();

            Assert.IsTrue(min > 0);
            Assert.IsTrue(max <= 12);
        }
开发者ID:cidthecoatrack,项目名称:Monopoly-Kata,代码行数:17,代码来源:DiceTests.cs

示例6: GenerateUniqueId

        public void GenerateUniqueId()
        {
            List<string> list = new List<string>();
            for (int i = 0; i < 100; i++)
            {
                list.Add(DataUtils.GenerateUniqueId());
            }

            int maxLength = list.Max(str => str.Length);
            int minLength = list.Min(str => str.Length);
            int negVals = list.Where(str => str.StartsWith("-")).Count();
            this.TestContext.WriteLine("Min Length: {0}, Max: {1}, Neg: {2}", minLength, maxLength, negVals);

            Assert.IsTrue(list.Distinct().Count() == 100, "Didn't create 100 unique entries");
        }
开发者ID:RickStrahl,项目名称:WestwindToolkit,代码行数:15,代码来源:StringUtilsTests.cs

示例7: MinTest

        public void MinTest()
        {
            List<int> posIntList = new List<int>();
            List<int> intList = new List<int>();
            List<decimal> posDecimalList = new List<decimal>();
            List<decimal> decimalList = new List<decimal>();
            int sign = -1;

            for (int i = 0; i < 10; i++)
            {
                posIntList.Add(i + 1);
                intList.Add((i + 1) * sign);
                posDecimalList.Add((i + 1) / 10m);
                decimalList.Add(((i + 1) / 10m) * sign);
                sign *= -1;
            }

            Assert.AreEqual(1, posIntList.Min());
            Assert.AreEqual(-9, intList.Min());
            Assert.AreEqual(.1m, posDecimalList.Min());
            Assert.AreEqual(-.9m, decimalList.Min());
        }
开发者ID:Velmond,项目名称:TelerikAcademy-CSharp,代码行数:22,代码来源:IEnumerableTExtensionsTests.cs

示例8: Min_abnormal

        public void Min_abnormal()
        {
            // arrange
            List<int> listInt = new List<int>();
            Func<int, int> func = null;

            // act and assert
            try
            {
                listInt.Min(func);
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.IsTrue(e is ArgumentNullException);
            }
            try
            {
                listInt.Min(x => x);
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.IsTrue(e is InvalidOperationException);
            }
        }
开发者ID:jlinqer,项目名称:jLinqer,代码行数:26,代码来源:EnumerableAbnormalTest.cs

示例9: PerfomanceCreateTest

        public async Task PerfomanceCreateTest()
        {
            System.Diagnostics.Debug.Print("Start " + DateTime.Now.ToShortTimeString());

            Stopwatch stopwatch = new Stopwatch();
            var watch = new List<TimeSpan>();

            System.Linq.Enumerable.Range(0, 1000).ToList().ForEach(r => {
                stopwatch.Start();
                PostTest();

                stopwatch.Stop();
                watch.Add(stopwatch.Elapsed);
                stopwatch.Reset();
            });

            var avg = watch.Average(r => r.Milliseconds);
            var min = watch.Min(r => r.Milliseconds);
            var max = watch.Max(r => r.Milliseconds);

            System.Diagnostics.Debug.Print("avg: {0}, min: {1}, max: {2} ", avg, min, max);
            System.Diagnostics.Debug.Print("End " + DateTime.Now.ToShortTimeString());
        }
开发者ID:SergeyDushkin,项目名称:test,代码行数:23,代码来源:CategoryTreeMicroserviceTest.cs

示例10: ListExtensions_Min_ReturnsMinValue

        public void ListExtensions_Min_ReturnsMinValue()
        {
            var list = new List<Int32>() { 4, 5, 6, 99, 10, 1, 12, 45 };

            var result = list.Min();

            TheResultingValue(result).ShouldBe(1);
        }
开发者ID:prshreshtha,项目名称:ultraviolet,代码行数:8,代码来源:ListExtensionsTest.cs

示例11: AssertGeneralStuff

        private void AssertGeneralStuff(List<Player> players, int howManyPlayers)
        {
            // Assert the expected number of players.
             Assert.IsNotNull(players);
             Assert.AreEqual(14, players.Count);

             // Assert the TeamOrder is unique for each player.
             var uniqueTeamOrder = players.Select(p => p.TeamOrder).Distinct().ToList();
             Assert.AreEqual(howManyPlayers, uniqueTeamOrder.Count);

             // Assert the player list is ordered on the TeamOrder property.
             int minimumTeamOrder = players.Min(p => p.TeamOrder);
             var firstPlayer = players[0];
             Assert.AreEqual(minimumTeamOrder, firstPlayer.TeamOrder);
             int maximumTeamOrder = players.Max(p => p.TeamOrder);
             var lastPlayer = players[howManyPlayers - 1];
             Assert.AreEqual(maximumTeamOrder, lastPlayer.TeamOrder);

             // Assert the player list is also ordered on the rating.
             decimal maxRating = players.Max(p => p.Rating);
             var bestPlayer = players[0];
             Assert.AreEqual(maxRating, bestPlayer.Rating);
             decimal minRating = players.Min(p => p.Rating);
             var worstPlayer = players[howManyPlayers - 1];
             Assert.AreEqual(minRating, worstPlayer.Rating);
        }
开发者ID:bouwe77,项目名称:fmg,代码行数:26,代码来源:StartingLineupGeneratorTest.cs

示例12: TestTupleVertexIndexes

        public void TestTupleVertexIndexes()
        {
            VoronoiWrapper vw = new VoronoiWrapper();
            vw.AddSegment(0, 0, 0, 10);
            vw.AddSegment(0, 10, 10, 10);
            vw.AddSegment(10, 10, 10, 0);
            vw.AddSegment(10, 0, 0, 0);
            vw.AddSegment(0, 0, 5, 5);
            vw.AddSegment(5, 5, 10, 10);
            vw.ConstructVoronoi();

            List<Tuple<double, double>> vertices = vw.GetVertices();
            List<Tuple<int, int, int, int, Tuple<bool, bool, bool, int, int>>> edges = vw.GetEdges();

            List<int> vertexIndexes = new List<int>();

            foreach (var e in edges)
            {
                if(!vertexIndexes.Exists(v=> v==e.Item2))
                    vertexIndexes.Add(e.Item2);

                if (!vertexIndexes.Exists(v => v == e.Item3))
                    vertexIndexes.Add(e.Item3);
            }

            vertexIndexes.Remove(-1);
            vertexIndexes.Sort();
            int minIndex = vertexIndexes.Min();
            int maxIndex = vertexIndexes.Max();

            Assert.AreEqual(0, minIndex);
            Assert.AreEqual(vertices.Count - 1, maxIndex);
        }
开发者ID:fabanc,项目名称:SharpBoostVoronoi,代码行数:33,代码来源:TestTuples.cs

示例13: Min

        public void Min()
        {
            // arrange
            List<int> listInt = new List<int>() { 1, 2, 3 };
            List<long> listlong = new List<long>() { 1, 2, 3 };
            List<double> listdouble = new List<double>() { 1d, 2d, 3d };
            List<decimal> listdecimal = new List<decimal>(){
                new decimal(1d),
                new decimal(2d),
                new decimal(3d)
            };

            // act
            double actualInt = listInt.Min(x => x);
            double actuallong = listlong.Min(x => x);
            double actualdouble = listdouble.Min(x => x);
            decimal actualdecimal = listdecimal.Min(x => x);

            // assert
            Assert.AreEqual(1, actualInt, 0);
            Assert.AreEqual(1, actuallong, 0);
            Assert.AreEqual(1d, actualdouble, 0);
            Assert.AreEqual(1, actualdecimal);
        }
开发者ID:jlinqer,项目名称:jLinqer,代码行数:24,代码来源:EnumerableTest.cs

示例14: ListExtensions_Min_ThrowsExceptionIfListIsEmpty

        public void ListExtensions_Min_ThrowsExceptionIfListIsEmpty()
        {
            var list = new List<Int32>();

            list.Min();
        }
开发者ID:prshreshtha,项目名称:ultraviolet,代码行数:6,代码来源:ListExtensionsTest.cs

示例15: CrudTest

        static void CrudTest(ISimpleEmployeeRepository repo)
        {
            s_DataSource.Sql(@"DELETE FROM Sales.Customer;DELETE FROM HR.Employee;").Execute();

            //actual
            var spans = new List<double>(Iterations);
            for (var i = 0; i < Iterations; i++)
            {
                var sw = Stopwatch.StartNew();
                CrudTestCore(repo);
                sw.Stop();
                spans.Add(sw.Elapsed.TotalMilliseconds);
            }
            Trace.WriteLine("Run Duration: " + spans.Average().ToString("N2") + " ms per iteration. Min: " + spans.Min().ToString("N2") + " ms. Max: " + spans.Max().ToString("N2") + " ms.");

            Trace.WriteLine("");
            Trace.WriteLine("");
            //foreach (var span in spans)
            //    Trace.WriteLine("    " + span.ToString("N2"));

            if (DiscardHighLow && Iterations > 10)
            {
                //Remove the highest and lowest two to reduce OS effects
                spans.Remove(spans.Max());
                spans.Remove(spans.Max());
                spans.Remove(spans.Min());
                spans.Remove(spans.Min());
            }

            Trace.WriteLine("Run Duration: " + spans.Average().ToString("N2") + " ms per iteration. Min: " + spans.Min().ToString("N2") + " ms. Max: " + spans.Max().ToString("N2") + " ms.");

            long frequency = Stopwatch.Frequency;
            Trace.WriteLine($"  Timer frequency in ticks per second = {frequency}");
            long nanosecPerTick = (1000L * 1000L * 1000L) / frequency;
            Trace.WriteLine($"  Timer is accurate within {nanosecPerTick} nanoseconds");
        }
开发者ID:docevaad,项目名称:Chain,代码行数:36,代码来源:ComparisonTests.cs


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