Пример #1
0
        public void OptimizeCaseDeleteFirst()
        {
            var str1 = "aaa";
            var str2 = "bbb";

            /*
             *  obj1  a a a
             *  obj2      b b b
             *        - - M + +
             */
            var results = DiffUtil.Diff(str1, str2);

            results = DiffUtil.Order(results, DiffOrderType.GreedyDeleteFirst);
            results = DiffUtil.OptimizeCaseDeletedFirst(results);
            Assert.AreEqual(DiffStatus.Deleted, results.ElementAt(0).Status);
            Assert.AreEqual(DiffStatus.Deleted, results.ElementAt(1).Status);
            Assert.AreEqual(DiffStatus.Modified, results.ElementAt(2).Status);
            Assert.AreEqual(DiffStatus.Inserted, results.ElementAt(3).Status);
            Assert.AreEqual(DiffStatus.Inserted, results.ElementAt(4).Status);


            /*
             *  obj1      a a a
             *  obj2  b b b
             + + M - -
             */
            results = DiffUtil.Diff(str1, str2);
            results = DiffUtil.Order(results, DiffOrderType.GreedyInsertFirst);
            results = DiffUtil.OptimizeCaseInsertedFirst(results);
            Assert.AreEqual(DiffStatus.Inserted, results.ElementAt(0).Status);
            Assert.AreEqual(DiffStatus.Inserted, results.ElementAt(1).Status);
            Assert.AreEqual(DiffStatus.Modified, results.ElementAt(2).Status);
            Assert.AreEqual(DiffStatus.Deleted, results.ElementAt(3).Status);
            Assert.AreEqual(DiffStatus.Deleted, results.ElementAt(4).Status);


            /*
             *  obj1  a a a
             *  obj2  b b b
             *        M M M
             */
            results = DiffUtil.Diff(str1, str2);
            results = DiffUtil.Order(results, DiffOrderType.LazyDeleteFirst);
            results = DiffUtil.OptimizeCaseDeletedFirst(results);
            Assert.AreEqual(DiffStatus.Modified, results.ElementAt(0).Status);
            Assert.AreEqual(DiffStatus.Modified, results.ElementAt(1).Status);
            Assert.AreEqual(DiffStatus.Modified, results.ElementAt(2).Status);

            /*
             *  obj1  a a a
             *  obj2  b b b
             *        M M M
             */
            results = DiffUtil.Diff(str1, str2);
            results = DiffUtil.Order(results, DiffOrderType.LazyInsertFirst);
            results = DiffUtil.OptimizeCaseInsertedFirst(results);
            Assert.AreEqual(DiffStatus.Modified, results.ElementAt(0).Status);
            Assert.AreEqual(DiffStatus.Modified, results.ElementAt(1).Status);
            Assert.AreEqual(DiffStatus.Modified, results.ElementAt(2).Status);
        }
Пример #2
0
        List <DiffResult <string> > DiffSheetRow(ISheet sheet1, int row1, ISheet sheet2, int row2, SheetDiffStatus status)
        {
            var list1 = new List <string>();
            var list2 = new List <string>();

            if (sheet1.GetRow(row1) != null)
            {
                var row         = sheet1.GetRow(row1);
                var columnCount = books["src"].SheetValideColumn[sheet1.SheetName];
                for (int i = 0; i < columnCount; ++i)
                {
                    list1.Add(Util.GetCellValue(row.GetCell(i)));
                }
            }

            if (sheet2.GetRow(row2) != null)
            {
                var row         = sheet2.GetRow(row2);
                var columnCount = books["dst"].SheetValideColumn[sheet2.SheetName];
                for (int i = 0; i < columnCount; ++i)
                {
                    list2.Add(Util.GetCellValue(row.GetCell(i)));
                }
            }
            var diff = DiffUtil.Diff(list1, list2);
            //var optimized = diff.ToList();// DiffUtil.OptimizeCaseDeletedFirst(diff);
            var optimized = DiffUtil.OptimizeCaseDeletedFirst(diff);

            optimized = DiffUtil.OptimizeCaseInsertedFirst(optimized);

            return(optimized.ToList());
        }
Пример #3
0
        List <DiffResult <string> > DiffSheetRow(ISheet sheet1, int row1, ISheet sheet2, int row2, SheetDiffStatus status, out int maxLineCount)
        {
            var list1 = new List <string>();
            var list2 = new List <string>();

            maxLineCount = 0;
            if (sheet1.GetRow(row1) != null)
            {
                var row         = sheet1.GetRow(row1);
                var columnCount = books["src"].SheetValideColumn[sheet1.SheetName];
                for (int i = 0; i < columnCount; ++i)
                {
                    var value = Util.GetCellValue(row.GetCell(i));
                    maxLineCount = Math.Max(maxLineCount, value.Count((c) => { return(c == '\n'); }) + 1);

                    list1.Add(value);
                }
            }

            if (sheet2.GetRow(row2) != null)
            {
                var row         = sheet2.GetRow(row2);
                var columnCount = books["dst"].SheetValideColumn[sheet2.SheetName];
                for (int i = 0; i < columnCount; ++i)
                {
                    var value = Util.GetCellValue(row.GetCell(i));
                    maxLineCount = Math.Max(maxLineCount, value.Count((c) => { return(c == '\n'); }) + 1);
                    list2.Add(value);
                }
            }
            var diff = DiffUtil.Diff(list1, list2);
            //var optimized = diff.ToList();// DiffUtil.OptimizeCaseDeletedFirst(diff);
            var optimized = DiffUtil.OptimizeCaseDeletedFirst(diff);

            optimized = DiffUtil.OptimizeCaseInsertedFirst(optimized);
            var tlist = optimized.ToList();

            optimized = DiffUtil.OptimizeShift(tlist, false);
            optimized = DiffUtil.OptimizeShift(optimized, true);

            return(optimized.ToList());
        }