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


C# List.Distinct方法代码示例

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


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

示例1: CheckStringsDeclared

        public void CheckStringsDeclared()
        {
            var names = new List<string>();
            checker.GetAllResourceReferences(names);
            Assert.Greater(names.Count, 600, "Должно быть много ресурсных строчек");
            // убрать исключения и повторы
            names = names.Distinct().Where(n => !exceptionString.Contains(n)).ToList();

            // проверить, есть ли они в файлах ресурсов
            var errorsInFile = new Dictionary<string, List<string>>();
            var resxFileNames = Directory.GetFiles(codeBase + @"\TradeSharp.Localisation\Properties", "*.resx");
            
            foreach (var resxFileName in resxFileNames)
            {
                if (excludedResourcesFiles.Contains(resxFileName.Split('\\').Last())) continue;

                var errors = checker.GetNamesLackInResxFile(resxFileName, names);
                if (errors.Count > 0)
                    errorsInFile.Add(Path.GetFileName(resxFileName), errors);
            }

            if (errorsInFile.Count > 0)
            {
                var errorStr = string.Join("\n", errorsInFile.Select(e => e.Key + ": " + string.Join(", ", e.Value)));
                Assert.Fail(errorStr);
            }
        }
开发者ID:johnmensen,项目名称:TradeSharp,代码行数:27,代码来源:NuCheckAllResourcesExist.cs

示例2: ShouldProcessOnMultipleThreads

        public void ShouldProcessOnMultipleThreads()
        {
            // Arrange
            var breaker = new CircuitBreaker();
            var source = Enumerable.Range(0, 100).ToArray();

            // Act
            var usedThreadIds = new List<int>();
            Reliable.ParallelForEach(
                breaker,
                source,
                elements => usedThreadIds.Add(Thread.CurrentThread.ManagedThreadId),
                new RetryOptions
                {
                    AllowedRetries = 5,
                    RetryInterval = TimeSpan.Zero
                },
                new ParallelOptions
                {
                    MaxDegreeOfParallelism = 100
                });

            // Assert
            if (usedThreadIds.Distinct().Count() == 1)
                Assert.Inconclusive("This test relies on multiple threads, however only one was ever spawned.");
        }
开发者ID:neilcampbell,项目名称:reliability-patterns,代码行数:26,代码来源:ReliableParallelForEachTests.cs

示例3: ShouldIterateOverEveryPixel

 public void ShouldIterateOverEveryPixel()
 {
     var image = new Bitmap(100, 100);
     var pixels = new List<Tuple<int,int>>();
     image.ForEachPixel((x, y) => pixels.Add(Tuple.Create(x, y)));
     pixels.Distinct().Should().HaveCount(100 * 100);
 }
开发者ID:ctekempel,项目名称:ImageComparison,代码行数:7,代码来源:ImageExtensionTests.cs

示例4: CheckStringsDeclared

        public void CheckStringsDeclared()
        {
            var names = new List<string>();
            checker.GetAllResourceReferences(names);
            Assert.Greater(names.Count, 400, "Должно быть много ресурсных строчек");

            // убрать исключения и повторы
            names = names.Distinct().ToList();
            names.Remove("ResourceManager");

            // проверить, есть ли они в файлах ресурсов
            var errorsInFile = new Dictionary<string, List<string>>();
            var resxFileNames = Directory.GetFiles(codeBase + @"\TradeSharp.AdminSite\App_GlobalResources", "*.resx");

            foreach (var resxFileName in resxFileNames)
            {
                var errors = checker.GetNamesLackInResxFile(resxFileName, names);
                if (errors.Count > 0)
                    errorsInFile.Add(Path.GetFileName(resxFileName), errors);
            }

            if (errorsInFile.Count > 0)
            {
                var errorStr = string.Join("\n", errorsInFile.Select(e => e.Key + ": " + string.Join(", ", e.Value)));
                Assert.Fail(errorStr);
            }
        }
开发者ID:johnmensen,项目名称:TradeSharp,代码行数:27,代码来源:NuCheckAllResourcesExist.cs

示例5: AssertThatDistinctWorks

        public void AssertThatDistinctWorks()
        {
            // Just a quick test of the de-duplication of a list of objects based on an object property value.
            // See JsModuleViewModel.Equals() override.
            // Without the override the items below wouldn't be considered duplicates because by default the equality is based on reference to objects.

            // Arrange
            List<JsModuleViewModel> totalRazorLines = new List<JsModuleViewModel>
            {
                new JsModuleViewModel {OriginalRazorText = "'@serverVariable1'", JavaScriptName = "serverVariable1"},
                new JsModuleViewModel {OriginalRazorText = "'@serverVariable1'", JavaScriptName = "serverVariable1"},
                new JsModuleViewModel {OriginalRazorText = "'@serverVariable2'", JavaScriptName = "serverVariable2"},
                new JsModuleViewModel {OriginalRazorText = "'@serverVariable3'", JavaScriptName = "serverVariable3"},
                new JsModuleViewModel {OriginalRazorText = "'@serverVariable2'", JavaScriptName = "serverVariable2"}
            };

            // Act
            totalRazorLines = totalRazorLines.Distinct().ToList();

            // Assert
            // To illustrate, without the equals override, this wouldn't work because although the values match they are different objects.
            Assert.IsTrue(totalRazorLines.Contains(new JsModuleViewModel { OriginalRazorText = "'@serverVariable2'", JavaScriptName = "serverVariable2" }));

            Assert.AreEqual(3, totalRazorLines.Count);
            Assert.AreEqual(totalRazorLines[0].JavaScriptName, "serverVariable1");
            Assert.AreEqual(totalRazorLines[1].JavaScriptName, "serverVariable2");
            Assert.AreEqual(totalRazorLines[2].JavaScriptName, "serverVariable3");
        }
开发者ID:nathanmurados,项目名称:MetricsEvaluator,代码行数:28,代码来源:LinqTests.cs

示例6: RandomizedQueueTest

        public void RandomizedQueueTest()
        {
            for (var k = 0; k < 9; k++)
            {
                var q = new RandomizedQueue<string>();

                var items = new List<string>
                {
                    "0",
                    "1",
                    "2",
                    "3",
                    "4",
                    "5",
                    "6",
                    "7",
                    "8",
                    "9"
                };

                foreach (var item in items)
                {
                    q.Enqueue(item);
                }

                var array = new List<string>();
                for (var i = 0; i < k; i++)
                {
                    array.Add(q.Dequeue());
                }

                Assert.AreEqual(k, array.Distinct().Count());
            }
        }
开发者ID:polkhovskyi,项目名称:RandomizedQueuesAndDeques,代码行数:34,代码来源:RandomizedQueueTests.cs

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

示例8: DistinctOnTwoCardsReturnsLenghtOf1

        public void DistinctOnTwoCardsReturnsLenghtOf1()
        {
            var cards = new List<Card>() { new Card(CardSuit.Diamond, CardType.King), new Card(CardSuit.Diamond, CardType.King) };
            var comparer = new CardComparer();
            cards = cards.Distinct(comparer).ToList();

            Assert.AreEqual(1, cards.Count);
        }
开发者ID:RuzmanovDev,项目名称:TelerikAcademy,代码行数:8,代码来源:DeckTests.cs

示例9: ShouldIterateOverEveryPixelThatIsNotIgnored

        public void ShouldIterateOverEveryPixelThatIsNotIgnored()
        {
            var image = new Bitmap(100, 100);
            var pixels = new List<Tuple<int, int>>();
            image.ForEachPixel(
                (x, y) => pixels.Add(Tuple.Create(x, y)),
                new[] { new IgnoreMask(0, 0, 9, 9) });

            pixels.Distinct().Should().HaveCount((100 * 100) - (10 * 10));
        }
开发者ID:ctekempel,项目名称:ImageComparison,代码行数:10,代码来源:ImageExtensionTests.cs

示例10: TestRandomStringSuccess

        public void TestRandomStringSuccess()
        {
            List<string> generated = new List<string>();

            for (var count = 0; count < 20; count++) {
                generated.Add(Shared.Utils.StringExtensions.RandomString(30));
            }

            Assert.AreEqual(20, generated.Distinct().Count());
        }
开发者ID:EBassie,项目名称:Potato,代码行数:10,代码来源:StringExtensionsTest.cs

示例11: TestDifferentDiceRolls

        public void TestDifferentDiceRolls()
        {
            var input = "1d6";
            var results = new List<double>();

            for (var i = 0; i < 100; i++)
                results.Add(evaluator.Calculate(input));

            Assert.That(results.Distinct().Count(), Is.GreaterThan(1));
        }
开发者ID:neoprincie,项目名称:TheNewStringCalculator,代码行数:10,代码来源:CalculatorTests.cs

示例12: DistinctQueryReuse

        public void DistinctQueryReuse()
        {
            List<int> data = new List<int> { 1, 2, 2 };
            IEnumerable<int> enumerable = data.Distinct();

            enumerable.AssertEqual(1, 2);

            data.Add(3);
            enumerable.AssertEqual(1, 2, 3);
        }
开发者ID:barisertekin,项目名称:LINQlone,代码行数:10,代码来源:DistinctTests.cs

示例13: UpdateSelectedFilesAtErrorTest

        public void UpdateSelectedFilesAtErrorTest() {
            IOpenFileDialogService dialog = new TestFileDialogService();
            var selectedFilesList = new List<string>();

            int retryCount = 2;
            var dialogResult = dialog.ShowDialog(e => {
                selectedFilesList.Add(dialog.File.Name);
                e.Cancel = retryCount-- > 0;
            });
            Assert.AreEqual(3, selectedFilesList.Distinct().Count());
        }
开发者ID:sk8tz,项目名称:DevExpress.Mvvm.Free,代码行数:11,代码来源:FileDialogServicesTests.cs

示例14: Distinct_LinqExt

		public void Distinct_LinqExt ()
		{
			// Distinct group of numbers

			var numbers = new List<int> (){ 1,1,2,2,3,4,5 };

			var distinctNumbers = numbers.Distinct ();

			Assert.AreEqual (5, distinctNumbers.Count ());
			Assert.AreEqual (1, distinctNumbers.First ());
			Assert.AreEqual (5, distinctNumbers.Last ());
		}
开发者ID:caloggins,项目名称:DOT-NET-on-Linux,代码行数:12,代码来源:Set.cs

示例15: GetDistinctBranchesViaLinq

 public void GetDistinctBranchesViaLinq()
 {
     IList<Branch> branches = new List<Branch>();
     var branch1 = new Branch
     {
         Geometry = GeometryFromWKT.Parse("LINESTRING (0 0, 100 0)")
     };
     branches.Add(branch1);
     branches.Add(branch1);
     Assert.AreEqual(2, branches.Count);
     Assert.AreEqual(1, branches.Distinct().Count());
 }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:12,代码来源:BranchTest.cs


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