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


C# List.Max方法代码示例

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


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

示例1: test_that_given_a_repository_with_many_changesets_the_latest_changeset_is_returned_by_get

        public void test_that_given_a_repository_with_many_changesets_the_latest_changeset_is_returned_by_get()
        {
            // arrange
            var changes = new List<SpeakerChange>
                              {
                                  new SpeakerChange() { Version = 1 },
                                  new SpeakerChange() { Version = 1 },
                                  new SpeakerChange() { Version = 2 }
                              };
            var mock = new Mock<ISpeakerChangeRepository>();
            mock.Setup(m => m.GetLatest()).Returns(() =>
                                                    {
                                                        int latestVersion = changes.Max(c => c.Version);
                                                        return changes.Where(c => c.Version == latestVersion).ToList();
                                                    });

            _container.Bind<ISpeakerChangeRepository>().ToConstant(mock.Object);

            // act
            var controller = (SpeakerChangeController)_container.Get<IHttpController>("SpeakerChange", new IParameter[0]);
            var result = controller.Get();

            // assert
            Assert.AreNotEqual(0, result.Count());
        }
开发者ID:xximjasonxx,项目名称:Codemash,代码行数:25,代码来源:SpeakerChangeControllerTests.cs

示例2: test_that_get_returns_only_the_latest_changeset

        public void test_that_get_returns_only_the_latest_changeset()
        {
            // arrange
            var changes = new List<SessionChange>
                               {
                                   new SessionChange {ActionType = ChangeAction.Add, SessionId = 123, Version = 1},
                                   new SessionChange
                                       {
                                           ActionType = ChangeAction.Modify,
                                           SessionId = 124,
                                           Key = "Title",
                                           Value = "new Title",
                                           Version = 1
                                       },
                                   new SessionChange {ActionType = ChangeAction.Delete, SessionId = 125, Version = 2},
                               };

            var mock = new Mock<ISessionChangeRepository>();
            mock.Setup(m => m.GetLatest()).Returns(() =>
                                                       {
                                                           int latestVersion = changes.Max(s => s.Version);
                                                           return changes.Where(sc => sc.Version == latestVersion).ToList();
                                                       });
            _container.Bind<ISessionChangeRepository>().ToConstant(mock.Object);

            // act
            var controller = (SessionChangeController)_container.Get<IHttpController>("SessionChange", new IParameter[0]);
            var result = controller.Get();

            // assert
            Assert.AreEqual(1, result.Count());
        }
开发者ID:xximjasonxx,项目名称:Codemash,代码行数:32,代码来源:SessionChangeControllerTests.cs

示例3: PrintSchedule

        private static void PrintSchedule(List<Employee> employees, List<Duty> duties)
        {
            var maxNameLength = employees.Max(x => x.Name.Length);

            duties = duties.OrderBy(x => x.Timeslot).ToList();

            Debug.Write(new string(' ', maxNameLength + Padding));
            Debug.Write(String.Join("  ", duties.Select(x => x.Timeslot)));
            Debug.WriteLine("");
            foreach (var employee in employees)
            {
                Debug.Write(employee.Name.PadRight(maxNameLength + Padding));

                foreach (var duty in duties)
                {
                    if (duty.Employee.Equals(employee))
                    {
                        Debug.Write("X");
                    }
                    else
                    {
                        Debug.Write(" ");
                    }
                    Debug.Write("  ");
                }

                Debug.Write("    ");
                PrintStatistics(employee, duties.Where(x => Equals(x.Employee, employee)).ToList());

                Debug.WriteLine("");
            }
        }
开发者ID:tincann,项目名称:NLZSupportPlanner,代码行数:32,代码来源:SchedulerTests.cs

示例4: 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

示例5: ProductControllerTest

        public ProductControllerTest()
        {
            // create some mock products to play with
            IList<Product> products = new List<Product>
            {
            new Product { ProductId = 1, ProductName = "Television",
                ProductDescription = "Sony", Price = 25000 },
            new Product { ProductId = 2, ProductName = "Computer",
                ProductDescription = "Dell", Price = 20000 },
            new Product { ProductId = 4, ProductName = "Table",
                ProductDescription = "Wooden", Price = 600 }
            };

            // Mock the Products Repository using Moq
            Mock<IProductRepository> mockProductRepository = new Mock<IProductRepository>();

            // Return all the products
            mockProductRepository.Setup(mr => mr.FindAll()).Returns(products);

            // return a product by Id

            mockProductRepository.Setup(mr => mr.FindById(It.IsAny<int>())).Returns((int i) => products.Where(x => x.ProductId == i).Single());

            // return a product by Name
            mockProductRepository.Setup(mr => mr.FindByName(It.IsAny<string>())).Returns((string s) => products.Where(x => x.ProductName == s).Single());

            // Allows us to test saving a product
            mockProductRepository.Setup(mr => mr.Save(It.IsAny<Product>())).Returns(
               (Product target) =>
               {
                   if (target.ProductId.Equals(default(int)))
                   {
                       target.ProductId = products.Max(q => q.ProductId) + 1;
                       //target.ProductId = products.Count() + 1;
                       products.Add(target);
                   }
                   else
                   {
                       var original = products.Where(q => q.ProductId == target.ProductId).SingleOrDefault();

                       if (original != null)
                       {
                           return false;
                       }

                       products.Add(target);
                   }

                   return true;
               });

            // Complete the setup of our Mock Product Repository
            this.MockProductsRepository = mockProductRepository.Object;
        }
开发者ID:Nagendra12122,项目名称:MVC3-Order-Management-System,代码行数:54,代码来源:ProductControllerTest.cs

示例6: 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

示例7: 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

示例8: TestMethod1

        public void TestMethod1()
        {
            int lenght = 5;
            string vs = "1 2 4 4 5";

            int[] values = new int[lenght];

            var tab = vs.Split(' ');
            for (int i = 0; i < tab.Length; i++)
            {
                var v = tab[i];
                values[i] = int.Parse(tab[i]);
            }

            int result = 0;
            int delta = 0;
            int refPos = 0;

            List<Element> sommets = new List<Element>();
            for (int i = 0; i < lenght; i++)
            {
                if (IsSommet(i, values))
                {

                    if (sommets.Count==0 || sommets[sommets.Count - 1].Value < values[i])
                    {
                        sommets.Add(new Element(i, 0, values[i]));
                    }
                }
                else
                {
                    int value = values[i];
                    sommets.ForEach(k =>
                    {
                        if (k.Value - value > k.Delta)
                        {
                            k.Delta = k.Value - value;
                        }
                    });
                }
            }

            if(sommets.Count>0)
                result = -sommets.Max(s => s.Delta);

               Assert.AreEqual(0,result);
        }
开发者ID:fathib,项目名称:akkaNet,代码行数:47,代码来源:CrachBoursier.cs

示例9: 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

示例10: 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

示例11: MaxTest

        public void MaxTest()
        {
            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(10, posIntList.Max());
            Assert.AreEqual(10, intList.Max());
            Assert.AreEqual(1.0m, posDecimalList.Max());
            Assert.AreEqual(1.0m, decimalList.Max());
        }
开发者ID:Velmond,项目名称:TelerikAcademy-CSharp,代码行数:22,代码来源:IEnumerableTExtensionsTests.cs

示例12: 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

示例13: 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

示例14: Max_abnormal

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

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

示例15: 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


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