示例#1
0
            public void Will_return_empty_modifications_for_empty_strings()
            {
                var differ = new TestableDiffer();
                var a      = new ModificationData("");
                var b      = new ModificationData("");

                a.HashedPieces  = new int[0];
                b.HashedPieces  = new int[0];
                a.Modifications = new bool[a.HashedPieces.Length];
                b.Modifications = new bool[b.HashedPieces.Length];

                differ.TestBuildModificationData(a, b);

                Assert.Empty(a.Modifications);
                Assert.Empty(b.Modifications);
            }
示例#2
0
            public void Will_return_correct_modifications_count_for_random_data(int[] aLines, int[] bLines, int editLength)
            {
                var differ = new TestableDiffer();
                var a      = new ModificationData("");
                var b      = new ModificationData("");

                a.HashedPieces  = aLines;
                b.HashedPieces  = bLines;
                a.Modifications = new bool[aLines.Length];
                b.Modifications = new bool[bLines.Length];

                differ.TestBuildModificationData(a, b);

                int modCount = a.Modifications.Count(x => x == true) + b.Modifications.Count(x => x == true);

                Assert.Equal(editLength, modCount);
            }
示例#3
0
            public void Will_return_all_modifications_for_non_empty_vs_empty_string()
            {
                var differ = new TestableDiffer();
                var a      = new ModificationData("cat\nhat\npat\nmatt");
                var b      = new ModificationData("");

                a.HashedPieces  = new[] { 1, 2, 3, 4 };
                b.HashedPieces  = new int[] { };
                a.Modifications = new bool[a.HashedPieces.Length];
                b.Modifications = new bool[b.HashedPieces.Length];

                differ.TestBuildModificationData(a, b);

                foreach (var mod in a.Modifications)
                {
                    Assert.True(mod);
                }
            }
示例#4
0
            public void Will_return_correct_modifications_for_strings_with_two_differences()
            {
                var differ = new TestableDiffer();
                var a      = new ModificationData("cat\nfat\ntac");
                var b      = new ModificationData("cat\nmatt\ntac");

                a.HashedPieces  = new[] { 1, 2, 3 };
                b.HashedPieces  = new[] { 1, 4, 3 };
                a.Modifications = new bool[a.HashedPieces.Length];
                b.Modifications = new bool[b.HashedPieces.Length];

                differ.TestBuildModificationData(a, b);

                Assert.False(a.Modifications[0]);
                Assert.True(a.Modifications[1]);
                Assert.False(a.Modifications[2]);

                Assert.False(b.Modifications[0]);
                Assert.True(b.Modifications[1]);
                Assert.False(b.Modifications[2]);
            }
示例#5
0
            public void Will_return_correct_modifications_two_partially_similar_strings()
            {
                var differ = new TestableDiffer();
                var a      = new ModificationData("cat\nhat\npat\nmatt");
                var b      = new ModificationData("cat\nmatt\ntac");

                a.HashedPieces  = new[] { 1, 2, 3, 4 };
                b.HashedPieces  = new[] { 1, 4, 5 };
                a.Modifications = new bool[a.HashedPieces.Length];
                b.Modifications = new bool[b.HashedPieces.Length];

                differ.TestBuildModificationData(a, b);

                Assert.False(a.Modifications[0]);
                Assert.True(a.Modifications[1]);
                Assert.True(a.Modifications[2]);
                Assert.False(a.Modifications[3]);

                Assert.False(b.Modifications[0]);
                Assert.False(b.Modifications[1]);
                Assert.True(b.Modifications[2]);
            }
示例#6
0
            public void Will_return_all_modifications_for_unique_strings()
            {
                var differ = new TestableDiffer();
                var a      = new ModificationData("cat\nhat\npat\nmatt");
                var b      = new ModificationData("door\nfloor\nbore\nmore");

                a.HashedPieces  = new[] { 1, 2, 3, 4 };
                b.HashedPieces  = new[] { 5, 6, 7, 8 };
                a.Modifications = new bool[a.HashedPieces.Length];
                b.Modifications = new bool[b.HashedPieces.Length];

                differ.TestBuildModificationData(a, b);

                foreach (var mod in a.Modifications)
                {
                    Assert.True(mod);
                }
                foreach (var mod in b.Modifications)
                {
                    Assert.True(mod);
                }
            }
示例#7
0
            public void Will_return_no_modifications_for_same_strings()
            {
                var differ = new TestableDiffer();
                var a      = new ModificationData("cat\nhat\npat\nmatt");
                var b      = new ModificationData("cat\nhat\npat\nmatt");

                a.HashedPieces  = new[] { 1, 2, 3, 4 };
                b.HashedPieces  = new[] { 1, 2, 3, 4 };
                a.Modifications = new bool[a.HashedPieces.Length];
                b.Modifications = new bool[b.HashedPieces.Length];

                differ.TestBuildModificationData(a, b);

                foreach (var mod in a.Modifications)
                {
                    Assert.False(mod);
                }
                foreach (var mod in b.Modifications)
                {
                    Assert.False(mod);
                }
            }