Esempio n. 1
0
        public virtual void TestAddTwo()
        {
            Edit     e1 = new Edit(1, 2, 1, 1);
            Edit     e2 = new Edit(8, 8, 8, 12);
            EditList l  = new EditList();

            Extensions.AddItem(l, e1);
            Extensions.AddItem(l, e2);
            NUnit.Framework.Assert.AreEqual(2, l.Count);
            NUnit.Framework.Assert.AreSame(e1, l[0]);
            NUnit.Framework.Assert.AreSame(e2, l[1]);
            Iterator <Edit> i = Extensions.Iterator(l);

            NUnit.Framework.Assert.AreSame(e1, i.Next());
            NUnit.Framework.Assert.AreSame(e2, i.Next());
            NUnit.Framework.Assert.AreEqual(l, l);
            NUnit.Framework.Assert.IsFalse(l.Equals(new EditList()));
            EditList l2 = new EditList();

            Extensions.AddItem(l2, e1);
            Extensions.AddItem(l2, e2);
            NUnit.Framework.Assert.AreEqual(l2, l);
            NUnit.Framework.Assert.AreEqual(l, l2);
            NUnit.Framework.Assert.AreEqual(AList <Edit> .GetHashCode(l), AList <Edit> .GetHashCode(l2));
        }
Esempio n. 2
0
        public virtual void TestSet()
        {
            Edit     e1 = new Edit(1, 2, 1, 1);
            Edit     e2 = new Edit(3, 4, 3, 3);
            EditList l  = new EditList();

            Extensions.AddItem(l, e1);
            NUnit.Framework.Assert.AreSame(e1, l[0]);
            NUnit.Framework.Assert.AreSame(e1, Extensions.Set(l, 0, e2));
            NUnit.Framework.Assert.AreSame(e2, l[0]);
        }
Esempio n. 3
0
        public virtual void TestRemove()
        {
            Edit     e1 = new Edit(1, 2, 1, 1);
            Edit     e2 = new Edit(8, 8, 8, 12);
            EditList l  = new EditList();

            Extensions.AddItem(l, e1);
            Extensions.AddItem(l, e2);
            l.Remove(e1);
            NUnit.Framework.Assert.AreEqual(1, l.Count);
            NUnit.Framework.Assert.AreSame(e2, l[0]);
        }
Esempio n. 4
0
            internal virtual void DiffReplace(Edit r)
            {
                Edit lcs = new HistogramDiffIndex <S>(this._enclosing.maxChainLength, this.cmp, this
                                                      .a, this.b, r).FindLongestCommonSequence();

                if (lcs != null)
                {
                    // If we were given an edit, we can prove a result here.
                    //
                    if (lcs.IsEmpty())
                    {
                        // An empty edit indicates there is nothing in common.
                        // Replace the entire region.
                        //
                        Extensions.AddItem(this.edits, r);
                    }
                    else
                    {
                        this.Diff(r.Before(lcs));
                        this.Diff(r.After(lcs));
                    }
                }
                else
                {
                    if (this._enclosing.fallback is LowLevelDiffAlgorithm)
                    {
                        LowLevelDiffAlgorithm fb = (LowLevelDiffAlgorithm)this._enclosing.fallback;
                        fb.DiffNonCommon(this.edits, this.cmp, this.a, this.b, r);
                    }
                    else
                    {
                        if (this._enclosing.fallback != null)
                        {
                            SubsequenceComparator <HashedSequence <S> > cs  = this.Subcmp();
                            Subsequence <HashedSequence <S> >           @as = Subsequence <S> .A(this.a, r);

                            Subsequence <HashedSequence <S> > bs = Subsequence <S> .B(this.b, r);

                            EditList res = this._enclosing.fallback.DiffNonCommon(cs, @as, bs);
                            Sharpen.Collections.AddAll(this.edits, Subsequence <S> .ToBase(res, @as, bs));
                        }
                        else
                        {
                            Extensions.AddItem(this.edits, r);
                        }
                    }
                }
            }
Esempio n. 5
0
        public virtual void TestAddOne()
        {
            Edit     e = new Edit(1, 2, 1, 1);
            EditList l = new EditList();

            Extensions.AddItem(l, e);
            NUnit.Framework.Assert.AreEqual(1, l.Count);
            NUnit.Framework.Assert.IsFalse(Extensions.IsEmpty(l));
            NUnit.Framework.Assert.AreSame(e, l[0]);
            NUnit.Framework.Assert.AreSame(e, Extensions.Iterator(l).Next());
            NUnit.Framework.Assert.AreEqual(l, l);
            NUnit.Framework.Assert.IsFalse(l.Equals(new EditList()));
            EditList l2 = new EditList();

            Extensions.AddItem(l2, e);
            NUnit.Framework.Assert.AreEqual(l2, l);
            NUnit.Framework.Assert.AreEqual(l, l2);
            NUnit.Framework.Assert.AreEqual(AList <Edit> .GetHashCode(l), AList <Edit> .GetHashCode(l2));
        }
Esempio n. 6
0
            private void Diff(Edit r)
            {
                switch (r.GetType())
                {
                case Edit.Type.INSERT:
                case Edit.Type.DELETE:
                {
                    Extensions.AddItem(this.edits, r);
                    break;
                }

                case Edit.Type.REPLACE:
                {
                    this.DiffReplace(r);
                    break;
                }

                case Edit.Type.EMPTY:
                default:
                {
                    throw new InvalidOperationException();
                }
                }
            }
Esempio n. 7
0
 /// <summary>Construct an edit list containing a single edit.</summary>
 /// <remarks>Construct an edit list containing a single edit.</remarks>
 /// <param name="edit">the edit to return in the list.</param>
 /// <returns>
 /// list containing only
 /// <code>edit</code>
 /// .
 /// </returns>
 public static NGit.Diff.EditList Singleton(Edit edit)
 {
     NGit.Diff.EditList res = new NGit.Diff.EditList(1);
     Extensions.AddItem(res, edit);
     return(res);
 }