public void Pop_ThrowsIndexOutOfRangeException_OnZeroSize() { var stack = new HashStack <int>(); Action action = () => stack.Pop(); action.Should().Throw <IndexOutOfRangeException>(); }
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()); }
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>(); }
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); } }
/// <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); }
public void HashStack_PopWithNoElements_Throws() { var s = new HashStack <int>(); Assert.ThrowsException <InvalidOperationException>(() => s.Pop()); }
public void HashStack_PopWithNoElements_Throws() { var s = new HashStack<int>(); Assert.Throws<InvalidOperationException>(()=> s.Pop()); }
public void HashStack_PopWithNoElements_Throws() { var s = new HashStack<int>(); s.Pop(); }
public void HashStack_PopWithNoElements_Throws() { var s = new HashStack <int>(); s.Pop(); }