Example #1
0
        /// <summary>
        ///UnionWith 的测试
        ///</summary>
        public void UnionWithTestHelper <KeyT>()
        {
            SafeHashSet <KeyT> target = new SafeHashSet <KeyT>(); // TODO: 初始化为适当的值
            IEnumerable <KeyT> other  = null;                     // TODO: 初始化为适当的值

            target.UnionWith(other);
            Assert.Inconclusive("无法验证不返回值的方法。");
        }
Example #2
0
        public void SafeHashSet依照帶入參數執行聯集操作_執行成功_結果應是SafeHashSet與參數的聯集()
        {
            var safeHashSet = new SafeHashSet <int> {
                1, 2, 3
            };
            var param = Enumerable.Range(0, 5);

            safeHashSet.UnionWith(param);
            var expectedResult = new List <int> {
                1, 2, 3, 0, 4
            };

            safeHashSet.SequenceEqual(expectedResult).Should().Be(true);
        }
Example #3
0
        public void 繞行SafeHashSet操作集合_不同執行緒同時對SafeHashSet操作新增與刪除_不應擲出例外()
        {
            var safeHashSet = new SafeHashSet <int> {
                1, 2, 3, 4, 5
            };

            Task.Run(() =>
            {
                while (true)
                {
                    safeHashSet.Add(0);
                }
            });

            Task.Run(() =>
            {
                while (true)
                {
                    safeHashSet.Remove(0);
                }
            });

            Task.Run(() =>
            {
                while (true)
                {
                    safeHashSet.Clear();
                }
            });

            Task.Run(() =>
            {
                while (true)
                {
                    safeHashSet.IntersectWith(Enumerable.Range(0, 3));
                }
            });

            Task.Run(() =>
            {
                while (true)
                {
                    safeHashSet.UnionWith(Enumerable.Range(0, 3));
                }
            });

            Action action = () => IterateCollection(safeHashSet).Wait();

            action.Should().NotThrow();
        }