本文整理汇总了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);
}
}
示例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.");
}
示例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);
}
示例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);
}
}
示例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");
}
示例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());
}
}
示例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);
}
示例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);
}
示例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));
}
示例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());
}
示例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));
}
示例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);
}
示例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());
}
示例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 ());
}
示例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());
}