本文整理汇总了C#中NUnit.Framework.List.Intersect方法的典型用法代码示例。如果您正苦于以下问题:C# List.Intersect方法的具体用法?C# List.Intersect怎么用?C# List.Intersect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NUnit.Framework.List
的用法示例。
在下文中一共展示了List.Intersect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanBeUsedByLinqSetOperatorsSuchAsIntersect
public void CanBeUsedByLinqSetOperatorsSuchAsIntersect()
{
IList<ConcreteEntityWithDomainSignatureProperties> objects1 =
new List<ConcreteEntityWithDomainSignatureProperties>();
var object1 = new ConcreteEntityWithDomainSignatureProperties { Name = "Billy McCafferty", };
EntityIdSetter.SetIdOf(object1, 2);
objects1.Add(object1);
IList<ConcreteEntityWithDomainSignatureProperties> objects2 =
new List<ConcreteEntityWithDomainSignatureProperties>();
var object2 = new ConcreteEntityWithDomainSignatureProperties { Name = "Jimi Hendrix", };
EntityIdSetter.SetIdOf(object2, 1);
objects2.Add(object2);
var object3 = new ConcreteEntityWithDomainSignatureProperties
{
Name =
"Doesn't Matter since the Id will match and the presedence of the domain signature will go overridden",
};
EntityIdSetter.SetIdOf(object3, 2);
objects2.Add(object3);
Assert.That(
objects1.Intersect(
objects2, new BaseObjectEqualityComparer<ConcreteEntityWithDomainSignatureProperties>()).Count(),
Is.EqualTo(1));
Assert.AreEqual(
objects1.Intersect(
objects2, new BaseObjectEqualityComparer<ConcreteEntityWithDomainSignatureProperties>()).First(),
object1);
Assert.AreEqual(
objects1.Intersect(
objects2, new BaseObjectEqualityComparer<ConcreteEntityWithDomainSignatureProperties>()).First(),
object3);
}
示例2: CanGetSingleDefinitionFromList
public void CanGetSingleDefinitionFromList()
{
var roles = new string[] {"everyone","users","publishers"};
var definitions = new List<AccessDefinition>()
{
new AccessDefinition(){RoleId ="administrator",CanRead =false,CanEdit = true,CanDelete = false,CanPublish = true},
new AccessDefinition(){RoleId ="users",CanRead =false,CanEdit = false,CanDelete = true,CanPublish = false},
new AccessDefinition(){RoleId ="everyone",CanRead =true,CanEdit = false,CanDelete = false,CanPublish = false}
};
var emptyDef = roles.Select(r => new AccessDefinition() {RoleId = r});
var ins = definitions.Intersect(emptyDef,new AccessDefinitionComparer());
var normalizedView = new AccessDefinition();
foreach (var ad in ins)
{
if (ad.CanRead)
normalizedView.CanRead = true;
if (ad.CanPublish)
normalizedView.CanPublish = true;
if (ad.CanEdit)
normalizedView.CanEdit = true;
if (ad.CanDelete)
normalizedView.CanDelete = true;
}
Assert.IsTrue(normalizedView.CanRead && normalizedView.CanDelete && !normalizedView.CanEdit && !normalizedView.CanPublish);
}
示例3: Test_equality_IEnumerable
public void Test_equality_IEnumerable()
{
var list1 = new List<Content> { new Content { Id = "1"} };
var list2 = new List<Content> { new Content { Id = "1" } };
//the intersections of these lists should have 1 element in it
Assert.Greater(list1.Intersect(list2).Count(), 0);
}
示例4: Serialization
public static void Serialization()
{
Assembly twitterizerAssembly = Assembly.GetAssembly(typeof(TwitterUser));
var objectTypesToCheck = from t in twitterizerAssembly.GetExportedTypes()
where !t.IsAbstract &&
!t.IsInterface &&
(
t.GetInterfaces().Contains(twitterizerAssembly.GetType("Twitterizer.Core.ITwitterObject")) ||
t.IsSubclassOf(twitterizerAssembly.GetType("Twitterizer.Entities.TwitterEntity"))
)
select t;
var interfacesToImplement = new List<Type>();
interfacesToImplement.Add(twitterizerAssembly.GetType("Twitterizer.Core.ICommand`1"));
interfacesToImplement.Add(twitterizerAssembly.GetType("Twitterizer.Core.ITwitterCommand`1"));
var baseClassesToInherit = new List<Type>();
baseClassesToInherit.Add(twitterizerAssembly.GetType("Twitterizer.Commands.PagedTimelineCommand`1"));
var commandTypesToCheck = from t in twitterizerAssembly.GetTypes()
where
(
interfacesToImplement.Intersect(t.GetInterfaces()).Count() > 0 ||
baseClassesToInherit.Any(t.IsSubclassOf)
)
select t;
var objects = objectTypesToCheck.Union(commandTypesToCheck).ToList();
foreach (Type type in objects)
{
Console.WriteLine(string.Format("Inspecting: {0}", type.FullName));
// Check that the object itself is marked as serializable
Assert.That(type.IsSerializable, string.Format("{0} is not marked as Serializable", type.Name));
// Get the parameter-less constructor, if there is one
ConstructorInfo constructor = type.GetConstructor(Type.EmptyTypes);
if (constructor == null)
Assert.Fail(string.Format("{0} does not have a public ctor", type.FullName));
// Instantiate the type by invoking the constructor
object objectToSerialize = constructor.Invoke(null);
try
{
using (MemoryStream ms = new MemoryStream())
{
// Serialize the object
new BinaryFormatter().Serialize(ms, objectToSerialize);
}
}
catch (Exception) // Catch any exceptions and assert a failure
{
Assert.Fail(string.Format("{0} could not be serialized", type.FullName));
}
}
}
示例5: Run_on_separate_thread
public void Run_on_separate_thread()
{
var frc = new FlowRuntimeConfiguration()
.AddStream(new Stream(".in", "serNop0"))
.AddStream(new Stream("serNop0", "serNop1"))
.AddStream(new Stream("serNop1", ".out"));
var asyncThreadIds0 = new List<long>();
frc.AddFunc<string, string>("serNop0", _ =>
{
lock (asyncThreadIds0)
{
Console.WriteLine("serNop0: {0} on {1}", _, Thread.CurrentThread.GetHashCode());
asyncThreadIds0.Add(Thread.CurrentThread.GetHashCode());
}
return _;
}).MakeSerial();
var asyncThreadIds1 = new List<long>();
frc.AddFunc<string, string>("serNop1", _ =>
{
lock (asyncThreadIds1)
{
Console.WriteLine("serNop1: {0} on {1}", _, Thread.CurrentThread.GetHashCode());
asyncThreadIds1.Add(Thread.CurrentThread.GetHashCode());
}
return _;
}).MakeSerial();
using (var sut = new FlowRuntime(frc))
{
const int N = 5;
var results = new List<IMessage>();
long runtimeThreadId = 0;
var are = new AutoResetEvent(false);
sut.Result += _ =>
{
lock (results)
{
Console.WriteLine("res {0} on {1}", _.Data, Thread.CurrentThread.GetHashCode());
runtimeThreadId = Thread.CurrentThread.GetHashCode();
results.Add(_);
if (results.Count == N) are.Set();
}
};
for (var i = 0; i < N; i++ )
sut.Process(new Message(".in", "x" + i));
Assert.IsTrue(are.WaitOne(10000));
Assert.AreEqual(N, results.Count);
Assert.That(results.Select(r => r.Data.ToString()).ToArray(), Is.EquivalentTo(new[]{"x0", "x1", "x2", "x3", "x4"}));
Assert.IsFalse(asyncThreadIds0.Contains(runtimeThreadId));
Assert.IsFalse(asyncThreadIds1.Contains(runtimeThreadId));
Assert.AreEqual(0, asyncThreadIds0.Intersect(asyncThreadIds1).Count());
}
}
示例6: CalculatePrimes
public void CalculatePrimes()
{
var expectedPrimes = new List<long> {
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97
};
var primes = Primes.CalculatePrimesBelow(100);
Assert.AreEqual(expectedPrimes.Count, primes.Count());
Assert.AreEqual(expectedPrimes.Count, expectedPrimes.Intersect(primes).Count());
}
示例7: Test_tag_equality_IEnumerable
public void Test_tag_equality_IEnumerable()
{
var list1 = new List<Tag> { new Tag { Id = "/Rupert" } };
var list2 = new List<Tag> { new Tag { Id = "/Rupert" } };
//the intersections of these lists should have 1 element in it
Assert.Greater(list1.Intersect(list2).Count(), 0);
//list2 should contain the first element of list1
Assert.Contains(list1[0], list2);
}
示例8: Returns_Three_Nearest_From_1_1
public void Returns_Three_Nearest_From_1_1()
{
var legalMoves = _piece.GetLegalMovesFromCoordinate(_startLocation, _board.BoardSize);
var corners = new List<BoardCoordinate>();
corners.Add(new BoardCoordinate(1, 2));
corners.Add(new BoardCoordinate(2, 2));
corners.Add(new BoardCoordinate(2, 1));
Assert.IsTrue(corners.Intersect(legalMoves).Count() == 3);
}
示例9: Returns_Three_Corners_From_8_8
public void Returns_Three_Corners_From_8_8()
{
var legalMoves = _piece.GetLegalMovesFromCoordinate(new BoardCoordinate(8, 8), _board.BoardSize);
var corners = new List<BoardCoordinate>();
corners.Add(new BoardCoordinate(1, 8));
corners.Add(new BoardCoordinate(1, 1));
corners.Add(new BoardCoordinate(8, 1));
Assert.IsTrue(corners.Intersect(legalMoves).Count() == 3);
}
示例10: Intersection
public void Intersection()
{
var a = new List<int> { 1, 2, 3 };
var b = new List<int> { 1, 2, 3, 4, 5, 6 };
var results = a.Intersect(b).ToList();
Assert.AreEqual(3, results.Count());
Assert.AreEqual(1, results[0]);
Assert.AreEqual(2, results[1]);
Assert.AreEqual(3, results[2]);
}
示例11: RandomShufflerShouldNotChangeReffernceTypeListContentOtherThanOrder
public void RandomShufflerShouldNotChangeReffernceTypeListContentOtherThanOrder()
{
const int listSize = 4;
var list = new List<string>()
{
"This",
"is",
"a",
"Test"
};
var listClone = new List<string>(list);
ListRandomShuffler.InPlaceShuffle(list);
var dupCount = list.Intersect(listClone).ToList().Count;
Assert.AreEqual(dupCount, listSize);
bool hasDifference = list.Except(listClone).ToList().Any();
Assert.IsFalse(hasDifference);
}
示例12: when_items_are_added_those_items_are_pumped_onto_AddedItemsCollectionChanged
public void when_items_are_added_those_items_are_pumped_onto_AddedItemsCollectionChanged()
{
var testSchedulerProvider = new TestDispatcherSchedulerProvider();
var results = new List<Guid>();
var bindableCollection = new BindableCollection<Guid>(testSchedulerProvider);
bindableCollection.AddedItemsCollectionChanged
.Subscribe(x => results.AddRange(x));
var items = Enumerable.Range(0, 10)
.Select(_ => Guid.NewGuid())
.ToList();
bindableCollection.AddRange(items);
var intersectionCount = results.Intersect(items).Count();
Assert.That(intersectionCount, Is.EqualTo(items.Count));
}
示例13: IntersectQueryReuse
public void IntersectQueryReuse()
{
List<int> first = new List<int> { 1, 2 };
List<int> second = new List<int> { 2, 4 };
IEnumerable<int> enumerable = first.Intersect(second);
enumerable.AssertEqual(2);
first.Add(3);
second.Add(3);
enumerable.AssertEqual(2, 3);
}
示例14: IntersectWithComparerQueryReuse
public void IntersectWithComparerQueryReuse()
{
List<int> first = new List<int> { 1, 2 };
List<int> second = new List<int> { 2, 4 };
IEnumerable<int> enumerable = first.Intersect(second, EqualityComparer<int>.Default);
enumerable.AssertEqual(2);
first.Add(3);
second.Add(3);
enumerable.AssertEqual(2, 3);
}
示例15: Intersect_LinqExt
public void Intersect_LinqExt ()
{
// Intersect; distinct union between two sets of data
var groupOne = new List<int> (){ 1,2,3,4,5};
var groupTwo = new List<int> (){4,5,6,7};
var groupInter = groupOne.Intersect (groupTwo).OrderBy (x => x);
Assert.AreEqual (2, groupInter.Count ());
Assert.AreEqual (4, groupInter.First ());
Assert.AreEqual (5, groupInter.Last ());
}