private static void PopulateCollection(PushOutCollection <int> collection, int count) { for (int i = 0; i < count; i++) { collection.Add(i); } }
public void PushOutFirstElement(int capacity, int extraElements, int[] expected) { // Arrange var collection = new PushOutCollection <int>(capacity); // Act for (int i = 0; i < capacity + extraElements; i++) { collection.Add(i); } // Assert Assert.Equal(expected, collection); }
public void IncreaseCount(int capacity, int newElements) { // Arrange var collection = new PushOutCollection <int>(capacity); // Act for (int i = 0; i < newElements; i++) { collection.Add(i); } // Assert Assert.Equal(newElements, collection.Count); }
public void NotExceedCapacity(int capacity, int newElements) { // Arrange var collection = new PushOutCollection <int>(capacity); // Act for (int i = 0; i < newElements; i++) { collection.Add(i); } // Assert Assert.Equal(capacity, collection.Count); Assert.Equal(capacity, collection.MaxCount); }
private bool TryAddSnapshotInternal(ref LineViewSnapshot snapshot) { if (EqualsToCurrentSnapshot(ref snapshot)) { return(false); } if (_iterator.HasNext()) { _snapshots.TrimTo(_iterator.Index + 1); } _snapshots.Add(snapshot); _iterator.MoveToLast(); return(true); }
public void AddCommand(string command) { EnsureCommandsLoaded(); if (String.IsNullOrWhiteSpace(command) || IsEqualsToLastCommand(command)) { _current = _commands.Count; return; } lock (_commandsWriteLock) { _commands.Add(command); _current = _commands.Count; } ScheduleSaveCommands(); }
private void EnsureCommandsLoaded() { if (_commands != null) { return; } lock (_commandsWriteLock) { if (_historyStorage == null) { _commands = new PushOutCollection <string>(MaxCount); } else { IReadOnlyList <string> loaded = null; lock (_historyStorage) { loaded = _historyStorage.Load(); } loaded = loaded.Where(_ => !String.IsNullOrWhiteSpace(_)).ToArray(); if (loaded.Count > MaxCount) { _commands = new PushOutCollection <string>(loaded.Skip(loaded.Count - MaxCount)); } else { _commands = new PushOutCollection <string>(MaxCount); for (int i = 0; i < loaded.Count; i++) { _commands.Add(loaded[i]); } } } _current = _commands.Count; } }