Пример #1
0
        public void Pop_ThrowsIndexOutOfRangeException_OnZeroSize()
        {
            var    stack  = new HashStack <int>();
            Action action = () => stack.Pop();

            action.Should().Throw <IndexOutOfRangeException>();
        }
Пример #2
0
        private string GetStringRepresentation(object obj, int nestingLevel)
        {
            if (obj == null)
            {
                return(NullRepresentation);
            }

            if (serializingObjects.Contains(obj))
            {
                throw new FormatException("Found circular reference. Please specify custom serialization for circular reference types." +
                                          $"Found object: {obj}, with type {obj.GetType()}");
            }
            serializingObjects.Push(obj);

            if (TryGetPrimitiveTypesAsString(obj, out var primitiveAsString))
            {
                return(primitiveAsString);
            }

            var sb   = new StringBuilder();
            var type = obj.GetType();

            sb.AppendLine(type.Name);

            sb.Append(IsEnumerableType(type)
                ? GetCollectionAsString(obj as IEnumerable, nestingLevel)
                : GetClassAsString(type, obj, nestingLevel));

            serializingObjects.Pop();
            return(sb.ToString());
        }
Пример #3
0
        public void Clear_RemovesAllElements()
        {
            var stack = new HashStack <int>();

            stack.Push(10);
            stack.Push(20);
            stack.Push(40);
            stack.Clear();
            Action action = () => stack.Pop();

            action.Should().Throw <IndexOutOfRangeException>();
        }
Пример #4
0
        public void PushAndPop_ReturnsCorrectElementsInCorrectOrder(params int[] elements)
        {
            var stack = new HashStack <int>();

            foreach (var element in elements)
            {
                stack.Push(element);
            }
            foreach (var element in elements.Reverse())
            {
                stack.Pop().Should().Be(element);
            }
        }
Пример #5
0
        /// <summary>
        /// Blocks the current thread until the condition is signaled.
        /// </summary>
        public void Await()
        {
            _waitingThreads.Add(ThreadHelper.CurrentThreadId);

            // Wait until signaled, at which time, we check to see if the signal
            // for the released thread matches this condition's id, and if so, the
            // thread is no longer in the waiting state
            string signal = null;

            while (signal != _signalId)
            {
                _monitor.Wait();

                signal = _threadSignals.Pop(ThreadHelper.CurrentThreadId);
            }

            // If we've made it this far, the current thread is no longer waiting
            _waitingThreads.Remove(ThreadHelper.CurrentThreadId);
        }
Пример #6
0
        public void HashStack_PopWithNoElements_Throws()
        {
            var s = new HashStack <int>();

            Assert.ThrowsException <InvalidOperationException>(() => s.Pop());
        }
Пример #7
0
 public void HashStack_PopWithNoElements_Throws()
 {
     var s = new HashStack<int>();
     Assert.Throws<InvalidOperationException>(()=> s.Pop());
 }
Пример #8
0
 public void HashStack_PopWithNoElements_Throws()
 {
     var s = new HashStack<int>();
     s.Pop();
 }
Пример #9
0
        public void HashStack_PopWithNoElements_Throws()
        {
            var s = new HashStack <int>();

            s.Pop();
        }