public void PreviousPointOfEndPoint() { var table = PieceTable.ForString("0"); var pointAfterLast = table[0].Next; Assert.AreEqual('0', pointAfterLast.Previous.GetValue()); }
public void InsertingAdjacentElementDoesNotCausePieceTableGrowth(string s, int index) { var v0 = PieceTable.ForString(s); var v1 = v0.Insert(index, '*'); var v2 = v1.Insert(index + 1, '-'); Assert.AreEqual(v1.PieceCount, v2.PieceCount); }
public void InsertFollowedByInsert(int index, string s) { var v0 = PieceTable.ForString(s); var v1 = v0.Insert(index, '*'); var v2 = v1.Insert(index + 1, '-'); Assert.AreEqual(s.Insert(index, "*-"), StringFor(v2)); }
public void Delete(int position, int length, string expectedString) { const string originalString = "0123"; var v0 = PieceTable.ForString(originalString); var v1 = v0.Delete(position, length); Assert.AreEqual(expectedString, StringFor(v1)); }
public void GetRangeAfterMultipleInserts(int position, int length, string expectedString) { const string originalString = "01234567"; var v0 = PieceTable.ForString(originalString); var v1 = v0.Insert(2, '*'); var v2 = v1.Insert(v1.Length - 2, '*'); Assert.AreEqual(expectedString, new string(v2.ToArray(position, length))); }
public void InsertPreservesOriginalVersion() { const string originalString = "01234567"; var v0 = PieceTable.ForString(originalString); var v1 = v0.Insert(2, '*'); Assert.AreEqual(originalString.Insert(2, "*"), StringFor(v1)); Assert.AreEqual(originalString, StringFor(v0)); }
public void DeleteAfterInsert(int position, int length, string expectedString) { const string originalString = "023"; var v0 = PieceTable.ForString(originalString); var v1 = v0.Insert(1, '1'); var v2 = v1.Delete(position, length); Assert.AreEqual(expectedString, StringFor(v2)); }
public void LengthAfterPrepending(int insertionCount) { var table = PieceTable.ForString(""); for (var i = 0; i < insertionCount; ++i) { table = table.Insert(0, ' '); } Assert.AreEqual(insertionCount, table.Length); }
public void DeletionPieceCountAfterInsert(int position, int length, int expectedPieceCount) { var v0 = PieceTable.ForString("02"); var v1 = v0.Insert(1, '1'); Assert.AreEqual(3, v1.PieceCount); var v2 = v1.Delete(position, length); Assert.AreEqual(expectedPieceCount, v2.PieceCount); }
public void SequentialAccessAfterManyDeletions() { const int numberOfDeletions = 100; const int numberOfCharacters = 500; const int iterations = 10 * 1000; var randomizer = new Randomizer(42); var table = PieceTable.ForString(new string(' ', 5 * 1024)); for (var i = 0; i < numberOfDeletions; ++i) { table = table.Delete(randomizer.Next(table.Length), 1); } Console.WriteLine("** CopyTo iteration **"); var buffer = new char[1]; var totalWithout = BenchmarkIterations(iterations, delegate { var position = randomizer.Next(table.Length - numberOfCharacters * 2) + numberOfCharacters; for (var i = 0; i < numberOfCharacters; ++i) { table.CopyTo(buffer, 0, position + i, 1); } for (var i = 0; i < numberOfCharacters; ++i) { table.CopyTo(buffer, 0, position - i, 1); } }); const int totalNumberOfOperations = iterations * numberOfCharacters; ReportTotalNumberOfOperations(totalWithout, totalNumberOfOperations); Console.WriteLine("** Point iteration **"); var totalWith = BenchmarkIterations(iterations, delegate { var position = randomizer.Next(table.Length - numberOfCharacters * 2) + numberOfCharacters; var pivot = table[position]; var current = pivot; for (var i = 0; i < numberOfCharacters; ++i) { current.GetValue(); current = current.Next; } current = pivot; for (var i = 0; i < numberOfCharacters; ++i) { current.GetValue(); current = current.Previous; } }); ReportTotalNumberOfOperations(totalWith, totalNumberOfOperations); }
public void LengthAfterSplittingAndAppending(int insertionCount) { const string originalString = "**"; var table = PieceTable.ForString(originalString); for (var i = 0; i < insertionCount; ++i) { table = table.Insert(1, ' ').Insert(2, ' '); } Assert.AreEqual(insertionCount * 2 + originalString.Length, table.Length); }