Exemplo n.º 1
0
        public void DiffCleanupEfficiencyTest()
        {
            diff_match_patchTest dmp = new diff_match_patchTest();
              // Cleanup operationally trivial equalities.
              dmp.Diff_EditCost = 4;
              // Null case.
              List<Diff> diffs = new List<Diff> ();
              dmp.DiffCleanupEfficiency(diffs);
              CollectionAssert.AreEqual(new List<Diff>(), diffs);

              // No elimination.
              diffs = new List<Diff> {
              new Diff(Operation.DELETE, "ab"),
              new Diff(Operation.INSERT, "12"),
              new Diff(Operation.EQUAL, "wxyz"),
              new Diff(Operation.DELETE, "cd"),
              new Diff(Operation.INSERT, "34")};
              dmp.DiffCleanupEfficiency(diffs);
              CollectionAssert.AreEqual(new List<Diff> {
              new Diff(Operation.DELETE, "ab"),
              new Diff(Operation.INSERT, "12"),
              new Diff(Operation.EQUAL, "wxyz"),
              new Diff(Operation.DELETE, "cd"),
              new Diff(Operation.INSERT, "34")}, diffs);

              // Four-edit elimination.
              diffs = new List<Diff> {
              new Diff(Operation.DELETE, "ab"),
              new Diff(Operation.INSERT, "12"),
              new Diff(Operation.EQUAL, "xyz"),
              new Diff(Operation.DELETE, "cd"),
              new Diff(Operation.INSERT, "34")};
              dmp.DiffCleanupEfficiency(diffs);
              CollectionAssert.AreEqual(new List<Diff> {
              new Diff(Operation.DELETE, "abxyzcd"),
              new Diff(Operation.INSERT, "12xyz34")}, diffs);

              // Three-edit elimination.
              diffs = new List<Diff> {
              new Diff(Operation.INSERT, "12"),
              new Diff(Operation.EQUAL, "x"),
              new Diff(Operation.DELETE, "cd"),
              new Diff(Operation.INSERT, "34")};
              dmp.DiffCleanupEfficiency(diffs);
              CollectionAssert.AreEqual(new List<Diff> {
              new Diff(Operation.DELETE, "xcd"),
              new Diff(Operation.INSERT, "12x34")}, diffs);

              // Backpass elimination.
              diffs = new List<Diff> {
              new Diff(Operation.DELETE, "ab"),
              new Diff(Operation.INSERT, "12"),
              new Diff(Operation.EQUAL, "xy"),
              new Diff(Operation.INSERT, "34"),
              new Diff(Operation.EQUAL, "z"),
              new Diff(Operation.DELETE, "cd"),
              new Diff(Operation.INSERT, "56")};
              dmp.DiffCleanupEfficiency(diffs);
              CollectionAssert.AreEqual(new List<Diff> {
              new Diff(Operation.DELETE, "abxyzcd"),
              new Diff(Operation.INSERT, "12xy34z56")}, diffs);

              // High cost elimination.
              dmp.Diff_EditCost = 5;
              diffs = new List<Diff> {
              new Diff(Operation.DELETE, "ab"),
              new Diff(Operation.INSERT, "12"),
              new Diff(Operation.EQUAL, "wxyz"),
              new Diff(Operation.DELETE, "cd"),
              new Diff(Operation.INSERT, "34")};
              dmp.DiffCleanupEfficiency(diffs);
              CollectionAssert.AreEqual(new List<Diff> {
              new Diff(Operation.DELETE, "abwxyzcd"),
              new Diff(Operation.INSERT, "12wxyz34")}, diffs);
              dmp.Diff_EditCost = 4;
        }