コード例 #1
0
        private void StrictSetIntersect <S1, S2>() where S1 : IStrictSet <int>, new() where S2 : IStrictSet <int>, new()
        {
            var origin = new S1();
            var other  = new S2();

            Fill(origin, 0, 5000);
            Fill(other, 4000, 5000);
            var result = origin.Intersect(other);

            Assert.Equal(1000, origin.Count);
            Assert.Equal(1000, result.Count);
            for (var i = 0; i < 4000; i++)
            {
                Assert.False(origin.Contains(i));
                Assert.False(result.Contains(i));
            }

            for (var i = 4000; i < 5000; i++)
            {
                Assert.True(origin.Contains(i));
                Assert.True(result.Contains(i));
            }

            for (var i = 5000; i < 9000; i++)
            {
                Assert.False(origin.Contains(i));
                Assert.False(result.Contains(i));
            }

            var third = new S1();

            foreach (var i in Enumerable.Range(5000, 1000))
            {
                third.Add(i);
            }

            origin.Intersect(third);

            Assert.Equal(0, origin.Count);
        }