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 TestAddingValueWhichShouldBeAddedBetweenTwoValuesInFullBucketAfterWhichIsAnotherFullBucket() { int SIZE_OF_BUCKET = 3; SortedDeque<double> sortedDeque = new SortedDeque<double>(SIZE_OF_BUCKET); List<double> valuesToAddToFirstBucket = new List<double> { 1, 2, 3 }; for (int i = 0; i < valuesToAddToFirstBucket.Count; ++i) sortedDeque.Insert(valuesToAddToFirstBucket[i]); List<double> valuesToAddToSecondBucket = new List<double> { 5, 6, 7 }; for (int i = 0; i < valuesToAddToSecondBucket.Count; ++i) sortedDeque.Insert(valuesToAddToSecondBucket[i]); double valueWhichShouldBeAddedBetweenTwoFullBuckets = 2.78; sortedDeque.Insert(valueWhichShouldBeAddedBetweenTwoFullBuckets); ///////////////////////////////////////////////////////// List<double> allValues = new List<double>(); allValues.AddRange(valuesToAddToFirstBucket); allValues.AddRange(valuesToAddToSecondBucket); allValues.Add(valueWhichShouldBeAddedBetweenTwoFullBuckets); allValues = allValues.OrderBy(x => x).ToList(); for (int i = 0; i < allValues.Count; ++i) { Assert.AreEqual(allValues.ElementAt(i), sortedDeque.ElementAt(i)); } ///////////////////////////////////////////////////////// int expectedTotalNumberOfElements = valuesToAddToFirstBucket.Count + 1 + valuesToAddToSecondBucket.Count; Assert.AreEqual(expectedTotalNumberOfElements, sortedDeque.SizeTotal); Assert.AreEqual(expectedTotalNumberOfElements, sortedDeque.SizeUnique); Assert.AreEqual(3 * SIZE_OF_BUCKET, sortedDeque.Capacity); Assert.AreEqual(3, sortedDeque.NumberOfBuckets); }
public void TestAddingValueWhichShouldBeAddedBetweenTwoFullBuckets() { int SIZE_OF_BUCKET = 3; SortedDeque<int> sortedDeque = new SortedDeque<int>(SIZE_OF_BUCKET); List<int> valuesToAddToFirstBucket = new List<int>{ 1, 2, 3 }; for (int i = 0; i < valuesToAddToFirstBucket.Count; ++i) sortedDeque.Insert(valuesToAddToFirstBucket[i]); List<int> valuesToAddToSecondBucket = new List<int> { 5, 6, 7 }; for (int i = 0; i < valuesToAddToSecondBucket.Count; ++i) sortedDeque.Insert(valuesToAddToSecondBucket[i]); int valueWhichShouldBeAddedBetweenTwoFullBuckets = 4; sortedDeque.Insert(valueWhichShouldBeAddedBetweenTwoFullBuckets); ///////////////////////////////////////////////////////// int expectedTotalNumberOfElements = valuesToAddToFirstBucket.Count + 1 + valuesToAddToSecondBucket.Count; Assert.AreEqual(expectedTotalNumberOfElements, sortedDeque.SizeTotal); Assert.AreEqual(expectedTotalNumberOfElements, sortedDeque.SizeUnique); Assert.AreEqual(3 * SIZE_OF_BUCKET, sortedDeque.Capacity); Assert.AreEqual(3, sortedDeque.NumberOfBuckets); }