public void AddTest() { var list = new IndexedLinkedList<int> { 1, 0, -1 }; Assert.AreEqual(3, list.Count, "Did not add the items"); list.Add(1); Assert.AreEqual(4, list.Count, "Did not add the item"); }
public void IndexerTest() { var list = new IndexedLinkedList<int> { 1, 0, -1 }; int expected = 1; int actual = list[0]; Assert.AreEqual(expected, actual, "Indexer does not work correctly"); }
public void Indexer_SetElement_Test() { var list = new IndexedLinkedList<int> { 1, 2, 3 }; int expected = 5; list[2] = 5; int actual = list[2]; Assert.AreEqual(expected, actual, "Indexer does not work correctly"); }
public void GetYieldBasedEnumeratorTest() { var list = new IndexedLinkedList<int> { 1, 0, -1, 44, 22, 22, 11, 2, 3, 4, 5 }; var expected = new int[] { 1, 0, -1, 44, 22, 22, 11, 2, 3, 4, 5 }; var actual = new System.Collections.Generic.List<int>(); foreach (var item in list) { actual.Add(item); } CollectionAssert.AreEqual(expected, actual, "The collections do not match"); }
public void CopyToTest() { var list = new IndexedLinkedList<int> { 1, 0, -1 }; var expected = new int[] { 1, 0, -1 }; var actual = new int[list.Count]; list.CopyTo(actual, 0); CollectionAssert.AreEqual(expected, actual, "The arrays do not match"); }
public void IndexedLinkedList_AddLast() { IndexedLinkedList<string> list = new IndexedLinkedList<string>(); list.AddLast("3"); list.AddLast("2"); list.AddLast("1"); Assert.AreEqual(3, list.Count); Assert.AreEqual("1", list.Last); }
public void IndexedLinkedList_Clear() { IndexedLinkedList<string> list = new IndexedLinkedList<string>(); list.AddFirst("3"); list.AddFirst("2"); list.AddFirst("1"); Assert.AreEqual(3, list.Count); list.Clear(); Assert.AreEqual(0, list.Count); Assert.IsNull(list.First); Assert.IsNull(list.Last); }
public void IndexedLinkedList_Remove() { IndexedLinkedList<string> list = new IndexedLinkedList<string>(); list.AddFirst("3"); list.AddFirst("2"); list.AddFirst("1"); Assert.AreEqual(3, list.Count); Assert.AreEqual("1", list.First); list.Remove("1"); Assert.AreEqual(2, list.Count); Assert.AreEqual("2", list.First); list.Remove("3"); Assert.AreEqual(1, list.Count); Assert.AreEqual("2", list.First); }
public void PerformanceComparism() { var simpleHeap = new BinaryMinHeap <Node>(new NodeComparer()); var indexedHeap = new IndexedLinkedList <Node>(new NodeComparer(), new NodeIndexer()); var count = 1000; this.PushNodes(simpleHeap, count); this.PushNodes(indexedHeap, count); var pushSimple = this.PushNodes(simpleHeap, count); var pushIndexed = this.PushNodes(indexedHeap, count); this.PopNodes(simpleHeap, count); this.PopNodes(indexedHeap, count); var popSimple = this.PopNodes(simpleHeap, count); var popIndexed = this.PopNodes(indexedHeap, count); Assert.Pass($"(PUSH) BinaryMinHeap: {pushSimple.Elapsed}, IndexedLinkedList: {pushIndexed.Elapsed}\r\n(POP) BinaryMinHeap: {popSimple.Elapsed}, IndexedLinkedList: {popIndexed.Elapsed}"); }
/// <summary> /// Initializes a new instance of the /// <see cref="LwtInMemoryStorage{TPersistence,TUnitOfWork,TStorage,TRepository,TKey,TEntity}"/> class. /// </summary> /// <param name="persistence">The owner persistence.</param> /// <param name="supportedRepositoryTypes">The repository types set that can be resolved with <c>this</c> plugin.</param> /// <param name="keysComparer">The keys comparer.</param> /// <param name="maxCapacity">The maximal capacity, most old entries are removed.</param> public LwtInMemoryStorage( TPersistence persistence, [Immutable] IReadOnlySet <Type> supportedRepositoryTypes, IComparer <TKey> keysComparer, int?maxCapacity = null) : base(persistence, supportedRepositoryTypes, false) { if (maxCapacity < 1) { throw new ArgumentException("Max capacity should be greater or equal than 1"); } _entities = new SortedDictionary <TKey, TEntity>(keysComparer); ////persistence.UnitOfWorkOpened += UnitOfWorkOpened; MaxCapacity = maxCapacity; if (MaxCapacity != null) { _gcFifoQueue = new IndexedLinkedList <TKey, VoidResult>(); } }
public void FindTest() { var list = new IndexedLinkedList<int> { 1, 0, -1 }; Assert.IsNotNull(list.Find(0), "The list does not contain the item"); }
public void ContainsTest() { var list = new IndexedLinkedList<int> { 1, 0, -1 }; Assert.IsTrue(list.Contains(0), "The list does not contain the item"); }
public void RemoveTest() { var list = new IndexedLinkedList<int> { 1, 0, -1 }; list.Remove(0); Assert.AreEqual(2, list.Count, "Remove failed, size does not match expected"); // Dump as array var expected = new int[] { 1, -1 }; var actual = new int[list.Count]; list.CopyTo(actual, 0); CollectionAssert.AreEqual(expected, actual, "Remove failed, The list does not match expected"); }
public void InsertTest() { var list = new IndexedLinkedList<int> { 1, 0, -1 }; list.Insert(1, 22); Assert.AreEqual(4, list.Count, "InsertAt failed, size does not match expected"); // Dump as array var expected = new int[] { 1, 22, 0, -1 }; var actual = new int[list.Count]; list.CopyTo(actual, 0); CollectionAssert.AreEqual(expected, actual, "InsertAt failed, The list does not match expected"); }
public ValueCollection(IndexedLinkedList <TKey, TValue> owner) { _owner = owner; }
public void IndexOfTest() { var list = new IndexedLinkedList<int> { 1, 0, -1 }; int expected = 1; int actual = list.IndexOf(0); Assert.AreEqual(expected, actual, "IndexOf did not return the correct index"); }
public void ClearTest() { var list = new IndexedLinkedList<int> { 1, 0, -1 }; list.Clear(); Assert.AreEqual(0, list.Count, "clearing the list failed"); }
public MovesLog(IEnumerable <IMove> moves) { movesSequence = new IndexedLinkedList <int, MoveSequenceItem>(p => p.SequenceNumber); AddMoves(moves); }