本文整理汇总了C#中Microsoft.VisualStudio.TestTools.UnitTesting.List.Distinct方法的典型用法代码示例。如果您正苦于以下问题:C# List.Distinct方法的具体用法?C# List.Distinct怎么用?C# List.Distinct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.VisualStudio.TestTools.UnitTesting.List
的用法示例。
在下文中一共展示了List.Distinct方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanITransformAWord
public void CanITransformAWord()
{
string word = "Bike";
if(word.Length == 0)
{
Assert.IsTrue(true);
return;
}
string transformedWord = word[0].ToString();
string remainingWord = word.Remove(0, 1);
if(remainingWord.Length == 0)
{
Assert.AreEqual(transformedWord, word);
return;
}
List<char> buffer = new List<char>();
if (remainingWord.Length > 1)
{
for (int i = 0; i < remainingWord.Length - 1; i++)
{
buffer.Add(remainingWord[i]);
}
}
transformedWord += buffer.Distinct().Count();
transformedWord += remainingWord[remainingWord.Length - 1];
Assert.AreEqual("B2e", transformedWord);
}
示例2: TestCoreDataIsNotDuplicatedIfIIndicatorAppearInMoreThanOneDomain
public void TestCoreDataIsNotDuplicatedIfIIndicatorAppearInMoreThanOneDomain()
{
var workbook = ProfileDataBuilderOfSingleRegionTest.GetWorkbookForProfile(
ProfileIds.SexualHealth);
var cells = workbook.Worksheets[ProfileDataBuilder.NationalLabel].Cells;
var lastData = string.Empty;
var dataList = new List<string>();
for (int rowIndex = 1; rowIndex < 1000; rowIndex++)
{
var name = cells[rowIndex, ExcelColumnIndexes.IndicatorName].Value;
var sex = cells[rowIndex, ExcelColumnIndexes.Sex].Value;
var age = cells[rowIndex, ExcelColumnIndexes.Age].Value;
var data = name + "-" + sex + "-" + age;
if (data != lastData)
{
dataList.Add(data);
lastData = data;
}
}
Assert.IsTrue(dataList.Count > 0);
Assert.AreEqual(dataList.Count,
dataList.Distinct().Count(), "Some core data rows are duplicated");
}
示例3: NodesDistinct
public void NodesDistinct()
{
Graph g = new Graph();
List<INode> test = new List<INode>()
{
g.CreateUriNode("rdf:type"),
g.CreateUriNode(new Uri("http://example.org")),
g.CreateBlankNode(),
g.CreateBlankNode(),
null,
g.CreateBlankNode("test"),
g.CreateLiteralNode("Test text"),
g.CreateLiteralNode("Test text", "en"),
g.CreateLiteralNode("Test text", new Uri(XmlSpecsHelper.XmlSchemaDataTypeString)),
g.CreateUriNode("rdf:type"),
null,
g.CreateUriNode(new Uri("http://example.org#test")),
g.CreateUriNode(new Uri("http://example.org"))
};
foreach (INode n in test.Distinct())
{
if (n != null)
{
Console.WriteLine(n.ToString());
}
else
{
Console.WriteLine("null");
}
}
}
示例4: TestFindShortestRouteBetweenAsyncProgress
public async Task TestFindShortestRouteBetweenAsyncProgress()
{
var cities = new Cities();
cities.ReadCities(CitiesTestFile);
var routes = new Routes(cities);
routes.ReadRoutes(LinksTestFile);
// do synchronous execution
var linksExpected = routes.FindShortestRouteBetween("Basel", "Zürich", TransportMode.Rail);
// do asynchronous execution
var messages = new List<string>();
var progress = new Progress<string>(msg => messages.Add(msg));
var linksActual = await routes.FindShortestRouteBetweenAsync("Basel", "Zürich", TransportMode.Rail, progress);
// let pending tasks execute
await Task.Yield();
// ensure that at least 5 progress calls are made
Assert.IsTrue(messages.Distinct().Count()>=5, "Less than 5 distinct progress messages");
// ensure that all progress messages end with " done"
Assert.IsTrue(messages.All(m => m.EndsWith(" done")),
string.Format("Progress message \"{0}\" does not end with \" done\"",
messages.FirstOrDefault(m => !m.EndsWith(" done"))));
}
示例5: DistinctGuidIdsForMultiThreads
public void DistinctGuidIdsForMultiThreads()
{
Thread[] threads = new Thread[HowManyThreads];
Guid[][] ids = new Guid[HowManyThreads][];
List<Guid> allIds = new List<Guid>(HowManyIds * HowManyThreads);
IIdGenerator<Guid> idGenerator = new IdGuidGenerator();
for (int i = 0; i < HowManyThreads; i++)
{
var threadId = i;
threads[i] = new Thread(() =>
{
ids[threadId] = idGenerator.Take(HowManyIds).ToArray();
});
threads[i].Start();
}
for (int i = 0; i < HowManyThreads; i++)
{
threads[i].Join();
Assert.IsTrue(AssertUtil.AreUnique(ids[i]), "All ids needs to be unique");
Assert.IsTrue(AssertUtil.AreSorted(ids[i]), "Ids array needs to be ordered");
allIds.AddRange(ids[i]);
}
Assert.AreEqual(
HowManyIds * HowManyThreads, allIds.Distinct().Count(),
"All ids needs to be unique");
}
示例6: DistinctTest
public void DistinctTest()
{
var list1 = new List<TestInfo>
{
new TestInfo { Id = new Guid("EDF61577-C9AA-46DE-8F1A-EAED37D5298F"), Name = "m" },
new TestInfo { Id = new Guid("EDF61577-C9AA-46DE-8F1A-EAED37D5298F"), Name = "b" },
new TestInfo { Id = new Guid("EDF61577-C9AA-46DE-8F1A-EAED37D5298F"), Name = "a" },
new TestInfo { Id = Guid.NewGuid(), Name = "w" },
new TestInfo { Id = Guid.NewGuid(), Name = "A" },
new TestInfo { Id = Guid.NewGuid(), Name = "a" },
};
var count = list1.Distinct(r => r.Name).Count();
Assert.AreEqual(count, 5);
count = list1.Distinct(r => r.Id).Count();
Assert.AreEqual(count, 4);
Assert.AreEqual(list1.Distinct(r => r.Id).First().Name, "m");
}
示例7: TestConstraintNameComparer
public void TestConstraintNameComparer()
{
var testData = new NoFuture.Hbm.DbQryContainers.SortedKeys();
var testOutput = new List<ColumnMetadata>();
var testInput = testData.GetKeyManyToOneColumns("dbo.TableWithCompositePk", ref testOutput);
foreach(var cd in testOutput)
System.Diagnostics.Debug.WriteLine(cd.constraint_name);
var testResult = testOutput.Distinct(new ConstraintNameComparer()).ToList();
Assert.AreEqual(1,testResult.Count);
}
示例8: BatchAddSettingValuesTest
public void BatchAddSettingValuesTest()
{
const EnumName name = EnumName.Locations;
IEnumerable<string> values = new List<string> { "value 1", "value 2", "value 3", "value 3" };
SettingsRepository.BatchAddSettingValues(name, values);
var actual = SettingsRepository.GetSettingValues(name);
Assert.IsTrue(actual.Count() == 3);
Assert.IsTrue(actual.SequenceEqual(values.Distinct()));
}
示例9: UpperAndLowerDieValuesAreRolled
public void UpperAndLowerDieValuesAreRolled()
{
IList<Int32> rolledValues = new List<Int32>();
for (Int32 i = 0; i < 100; i++)
{
rolledValues.Add(this.dice.Roll());
}
Assert.AreEqual(NumberOfPossibleRolledValues, rolledValues.Distinct().Count());
}
示例10: DistinctMethodTest
public void DistinctMethodTest()
{
List<int> ages = new List<int>() { 21, 46, 21, 46 };
IEnumerator<int> iter = ages.Distinct().GetEnumerator();
iter.MoveNext();
Assert.AreEqual(21, iter.Current);
iter.MoveNext();
Assert.AreEqual(46, iter.Current);
}
示例11: AllPossibleValuesAreRolled
public void AllPossibleValuesAreRolled()
{
var rolledValues = new List<Int32>();
for (var i = 0; i < 250; i++)
{
dice.Roll();
rolledValues.Add(dice.CurrentRoll);
}
Assert.AreEqual(11, rolledValues.Distinct().Count());
}
示例12: TestDistinct
public void TestDistinct()
{
var grouping2 = GetGrouping();
grouping2.IndicatorId = 10;
var groupings = new List<Grouping>
{
GetGrouping(),
grouping2,
GetGrouping()
};
Assert.AreEqual(2, groupings.Distinct(new DistinctGroupComparer()).Count());
}
示例13: DSet_Simple_AllNeighborsOfD_InG
public void DSet_Simple_AllNeighborsOfD_InG()
{
Graph<Node> g = GraphGenerator.GetGraph(Shape.Simple).Map(v => new Node {Label = v, Filled = false});
Graph<Node> d = g.GetDominatingSet();
List<Node> actual = new List<Node>();
foreach (var n in d.Vertices) {
actual.Add(n);
actual.AddRange(g.NeighborsOf(n));
actual = actual.Distinct().ToList();
}
CollectionAssert.AreEquivalent(g.Vertices.ToList(), actual);
}
示例14: DSet_K1_AllNeighborsOfD_InG
public void DSet_K1_AllNeighborsOfD_InG()
{
Graph<Node> g = new Graph<Node>();
g.Add(new Node { Label = "A", Filled = false });
Graph<Node> d = g.GetDominatingSet();
List<Node> actual = new List<Node>();
foreach (var n in d.Vertices) {
actual.Add(n);
actual.AddRange(g.NeighborsOf(n));
actual = actual.Distinct().ToList();
}
CollectionAssert.AreEquivalent(g.Vertices.ToList(), actual);
}
示例15: TestEquals
public void TestEquals()
{
var defaultaspx1 = new HyperLink(new Uri("http://about.me/"), "/default.aspx");
var defaultaspx2 = new HyperLink(new Uri("http://about.me/"), "default.aspx");
var defaultaspx3 = new HyperLink(new Uri("http://about.me/sub1/"), "../default.aspx");
Assert.IsTrue(defaultaspx1.Equals(defaultaspx2));
Assert.IsTrue(defaultaspx1.Equals(defaultaspx3));
var links = new List<HyperLink>() {defaultaspx1, defaultaspx2, defaultaspx3};
Assert.AreEqual(1, links.Distinct().Count());
}