private static void ExerciseFullApi(ConcurrentHashSet <int> hashSet, int[] numbersToAdd)
        {
            dynamic _;

            foreach (var number in numbersToAdd)
            {
                hashSet.Add(number);
            }

            var index             = 0;
            var genericEnumerator = hashSet.GetEnumerator();

            while (index < numbersToAdd.Length && genericEnumerator.MoveNext())
            {
                _ = genericEnumerator.Current;
            }

            index = 0;
            var nongenericEnumerator = ((IEnumerable)hashSet).GetEnumerator();

            while (index < numbersToAdd.Length && nongenericEnumerator.MoveNext())
            {
                _ = nongenericEnumerator.Current;
            }

            _ = hashSet.Count;
            var destinationArray = new int[500];

            hashSet.CopyTo(destinationArray, 0);
            _ = hashSet.Contains(numbersToAdd.First());
            hashSet.Remove(numbersToAdd.First());
            hashSet.Clear();
        }
Пример #2
0
        public void GetEnumeratorTest()
        {
            var people = new ConcurrentHashSet <PersonProper>(RandomData.GeneratePersonRefCollection <PersonProper>(100));

            var result = people.GetEnumerator();

            Assert.IsNotNull(result);
        }
Пример #3
0
        public void GetEnumerator()
        {
            // Arrange
            var list = new ConcurrentHashSet <int>();

            // Act
            var actual = list.GetEnumerator();

            // Assert
            Assert.Equal(0, actual.Current);
            list.Dispose();
        }
        public void ConcurrentHashSet_FunctionsAsNormalHashSet_ForSingleThreadedAccess(params int[] numbersToAdd)
        {
            // Because we're not doing anything interesting with the hashset itself, it seems reasonable to just wrap all of the basic hashset API tests into one test
            var distinctNumbers = numbersToAdd.Distinct().ToList();

            // Add
            foreach (var number in numbersToAdd)
            {
                _concurrentHashSet.Add(number);
            }

            // GetEnumerator<T>
            var index             = 0;
            var genericEnumerator = _concurrentHashSet.GetEnumerator();

            while (index < numbersToAdd.Length && genericEnumerator.MoveNext())
            {
                Assert.AreEqual(distinctNumbers[index++], genericEnumerator.Current);
            }
            Assert.AreEqual(distinctNumbers.Count, index);

            // GetEnumerator
            index = 0;
            var nongenericEnumerator = ((IEnumerable)_concurrentHashSet).GetEnumerator();

            while (index < numbersToAdd.Length && nongenericEnumerator.MoveNext())
            {
                Assert.AreEqual(distinctNumbers[index++], nongenericEnumerator.Current);
            }
            Assert.AreEqual(distinctNumbers.Count, index);

            // Count
            Assert.AreEqual(_concurrentHashSet.Count, distinctNumbers.Count);

            // CopyTo
            var destinationArray = new int[distinctNumbers.Count];

            _concurrentHashSet.CopyTo(destinationArray, 0);
            Assert.True(distinctNumbers.SequenceEqual(destinationArray));

            // Contains
            Assert.True(distinctNumbers.All(_concurrentHashSet.Contains));

            // Remove
            _concurrentHashSet.Remove(distinctNumbers.First());
            Assert.False(_concurrentHashSet.Contains(distinctNumbers.First()));

            // Clear
            _concurrentHashSet.Clear();
            Assert.AreEqual(0, _concurrentHashSet.Count);
            Assert.False(distinctNumbers.Any(_concurrentHashSet.Contains));
        }
Пример #5
0
 public IEnumerator <string> GetEnumerator() => _namespaces.GetEnumerator();
Пример #6
0
 public IEnumerator <T> GetEnumerator() => ConcurrentHashSet.GetEnumerator();
 /// <inheritdoc />
 public IEnumerator <string> GetEnumerator() => _HashSet.GetEnumerator();
Пример #8
0
 public IEnumerator <int> GetEnumerator()
 {
     return(_ids.GetEnumerator());
 }