public void TestAddingGreaterValueWhenFirstBucketIsFull() { int SIZE_OF_BUCKET = 3; SortedDeque<int> sortedDeque = new SortedDeque<int>(SIZE_OF_BUCKET); List<int> valuesToAdd = new List<int> { 2, 1, 9 }; for (int i = 0; i < valuesToAdd.Count; ++i) sortedDeque.Insert(valuesToAdd[i]); valuesToAdd = valuesToAdd.OrderBy(x => x).ToList(); for (int i = 0; i < valuesToAdd.Count; ++i) { Assert.AreEqual(valuesToAdd.ElementAt(i), sortedDeque.ElementAt(i)); } Assert.IsFalse(sortedDeque.Empty()); Assert.AreEqual(valuesToAdd.Count, sortedDeque.SizeTotal); Assert.AreEqual(valuesToAdd.Count, sortedDeque.SizeUnique); Assert.AreEqual(SIZE_OF_BUCKET, sortedDeque.Capacity); Assert.AreEqual(1, sortedDeque.NumberOfBuckets); ///////////////////////////////////////////////////////// const int valueGreaterThanPreviousValuesToAdd = 100; sortedDeque.Insert(valueGreaterThanPreviousValuesToAdd); Assert.IsTrue(sortedDeque.Back == valueGreaterThanPreviousValuesToAdd); Assert.IsFalse(sortedDeque.Empty()); Assert.AreEqual(valuesToAdd.Count + 1, sortedDeque.SizeTotal); Assert.AreEqual(valuesToAdd.Count + 1, sortedDeque.SizeUnique); Assert.AreEqual(2 * SIZE_OF_BUCKET, sortedDeque.Capacity); Assert.AreEqual(2, sortedDeque.NumberOfBuckets); }
public void TestAddingDuplicatedElements() { SortedDeque<int> sortedDeque = new SortedDeque<int>(); List<int> valuesToAdd = new List<int> { 2, 1, 9, 1, 5, 2, 9 }; for (int i = 0; i < valuesToAdd.Count; ++i) sortedDeque.Insert(valuesToAdd[i]); valuesToAdd = valuesToAdd.OrderBy(x => x).ToList(); List<int> uniqueValues = new List<int>(valuesToAdd).Distinct().ToList(); for (int i = 0; i < uniqueValues.Count; ++i) { Assert.AreEqual(uniqueValues.ElementAt(i), sortedDeque.At(i)); } Assert.IsFalse(sortedDeque.Empty()); Assert.AreEqual(valuesToAdd.Count, sortedDeque.SizeTotal); Assert.AreEqual(uniqueValues.Count, sortedDeque.SizeUnique); Assert.AreEqual(1, sortedDeque.NumberOfBuckets); }
public void TestSimpleAddingIntoSingleBucket() { List<int> valuesToAdd = new List<int> { 2, 0, 9, 1 }; int SIZE_OF_BUCKET = 10; SortedDeque<int> sortedDeque = new SortedDeque<int>(SIZE_OF_BUCKET); for (int i = 0; i < valuesToAdd.Count; ++i) sortedDeque.Insert(valuesToAdd[i]); valuesToAdd = valuesToAdd.OrderBy(x => x).ToList(); for (int i = 0; i < valuesToAdd.Count; ++i) { Assert.AreEqual(valuesToAdd.ElementAt(i), sortedDeque.ElementAt(i)); } Assert.IsFalse(sortedDeque.Empty()); Assert.AreEqual(valuesToAdd.Count, sortedDeque.SizeTotal); Assert.AreEqual(valuesToAdd.Count, sortedDeque.SizeUnique); Assert.AreEqual(SIZE_OF_BUCKET, sortedDeque.Capacity); Assert.AreEqual(1, sortedDeque.NumberOfBuckets); }
public void TestReserveWithSmallerNewCapacity() { int SIZE_OF_BUCKET = 3; SortedDeque<int> sortedDeque = new SortedDeque<int>(SIZE_OF_BUCKET); int capacityWhichIWant = SIZE_OF_BUCKET * 10; sortedDeque.Capacity = capacityWhichIWant; int capacityWhichIWant_new = SIZE_OF_BUCKET * 5; sortedDeque.Capacity = capacityWhichIWant; Assert.AreEqual(capacityWhichIWant / SIZE_OF_BUCKET, sortedDeque.NumberOfBuckets); Assert.AreEqual(capacityWhichIWant, sortedDeque.Capacity); Assert.IsTrue(sortedDeque.Empty()); Assert.AreEqual(0, sortedDeque.SizeTotal); Assert.AreEqual(0, sortedDeque.SizeUnique); }
public void TestReserve() { const int SIZE_OF_BUCKET = 3; SortedDeque<int> sortedDeque = new SortedDeque<int>(SIZE_OF_BUCKET); const int capacityWhichIWant = SIZE_OF_BUCKET * 10 + 1; sortedDeque.Capacity = capacityWhichIWant; int expectedNumberOfBuckets = (int)Math.Ceiling((double)(capacityWhichIWant) / (double)(SIZE_OF_BUCKET)); Assert.AreEqual(expectedNumberOfBuckets, sortedDeque.NumberOfBuckets); int expectedCapacity = expectedNumberOfBuckets * SIZE_OF_BUCKET; Assert.AreEqual(expectedCapacity, sortedDeque.Capacity); Assert.IsTrue(sortedDeque.Empty()); Assert.AreEqual(0, sortedDeque.SizeTotal); Assert.AreEqual(0, sortedDeque.SizeUnique); }
public void TestConstructionOfEmptyContainer() { SortedDeque<int> sortedDeque = new SortedDeque<int>(); Assert.IsTrue(sortedDeque.Empty()); Assert.AreEqual(0, sortedDeque.SizeTotal); Assert.AreEqual(0, sortedDeque.SizeUnique); Assert.AreEqual(0, sortedDeque.Capacity); }