Beispiel #1
0
        public virtual void TestBuilder_AddAll()
        {
            RefListBuilder <Ref> builder = new RefListBuilder <Ref>(1);

            Ref[] src = new Ref[] { REF_A, REF_B, REF_c, REF_A };
            builder.AddAll(src, 1, 2);
            RefList <Ref> list = builder.ToRefList();

            NUnit.Framework.Assert.AreEqual(2, list.Size());
            NUnit.Framework.Assert.AreSame(REF_B, list.Get(0));
            NUnit.Framework.Assert.AreSame(REF_c, list.Get(1));
        }
Beispiel #2
0
        public virtual void TestAddToEndOfList()
        {
            RefList <Ref> one = ToList(REF_A);
            RefList <Ref> two = one.Add(1, REF_B);

            NUnit.Framework.Assert.AreNotSame(one, two);
            // one is not modified, but two is
            NUnit.Framework.Assert.AreEqual(1, one.Size());
            NUnit.Framework.Assert.AreSame(REF_A, one.Get(0));
            NUnit.Framework.Assert.AreEqual(2, two.Size());
            NUnit.Framework.Assert.AreSame(REF_A, two.Get(0));
            NUnit.Framework.Assert.AreSame(REF_B, two.Get(1));
        }
Beispiel #3
0
        public virtual void TestCopyLeadingPrefix()
        {
            RefList <Ref> one = ToList(REF_A, REF_B, REF_c);
            RefList <Ref> two = one.Copy(2).ToRefList();

            NUnit.Framework.Assert.AreNotSame(one, two);
            NUnit.Framework.Assert.AreEqual(3, one.Size());
            NUnit.Framework.Assert.AreSame(REF_A, one.Get(0));
            NUnit.Framework.Assert.AreSame(REF_B, one.Get(1));
            NUnit.Framework.Assert.AreSame(REF_c, one.Get(2));
            NUnit.Framework.Assert.AreEqual(2, two.Size());
            NUnit.Framework.Assert.AreSame(REF_A, two.Get(0));
            NUnit.Framework.Assert.AreSame(REF_B, two.Get(1));
        }
Beispiel #4
0
        public virtual void TestRemoveEndOfList()
        {
            RefList <Ref> one = ToList(REF_A, REF_B, REF_c);
            RefList <Ref> two = one.Remove(2);

            NUnit.Framework.Assert.AreNotSame(one, two);
            NUnit.Framework.Assert.AreEqual(3, one.Size());
            NUnit.Framework.Assert.AreSame(REF_A, one.Get(0));
            NUnit.Framework.Assert.AreSame(REF_B, one.Get(1));
            NUnit.Framework.Assert.AreSame(REF_c, one.Get(2));
            NUnit.Framework.Assert.AreEqual(2, two.Size());
            NUnit.Framework.Assert.AreSame(REF_A, two.Get(0));
            NUnit.Framework.Assert.AreSame(REF_B, two.Get(1));
        }
Beispiel #5
0
        public virtual void TestPutNewEntry()
        {
            RefList <Ref> one = ToList(REF_A, REF_c);
            RefList <Ref> two = one.Put(REF_B);

            NUnit.Framework.Assert.AreNotSame(one, two);
            // one is not modified, but two is
            NUnit.Framework.Assert.AreEqual(2, one.Size());
            NUnit.Framework.Assert.AreSame(REF_A, one.Get(0));
            NUnit.Framework.Assert.AreSame(REF_c, one.Get(1));
            NUnit.Framework.Assert.AreEqual(3, two.Size());
            NUnit.Framework.Assert.AreSame(REF_A, two.Get(0));
            NUnit.Framework.Assert.AreSame(REF_B, two.Get(1));
            NUnit.Framework.Assert.AreSame(REF_c, two.Get(2));
        }
Beispiel #6
0
        public virtual void TestIterable()
        {
            RefList <Ref> list = ToList(REF_A, REF_B, REF_c);
            int           idx  = 0;

            foreach (Ref @ref in list)
            {
                NUnit.Framework.Assert.AreSame(list.Get(idx++), @ref);
            }
            NUnit.Framework.Assert.AreEqual(3, idx);
            Iterator <Ref> i = RefList.EmptyList().Iterator();

            try
            {
                i.Next();
                NUnit.Framework.Assert.Fail("did not throw NoSuchElementException");
            }
            catch (NoSuchElementException)
            {
            }
            // expected
            i = list.Iterator();
            NUnit.Framework.Assert.IsTrue(i.HasNext());
            NUnit.Framework.Assert.AreSame(REF_A, i.Next());
            try
            {
                i.Remove();
                NUnit.Framework.Assert.Fail("did not throw UnsupportedOperationException");
            }
            catch (NotSupportedException)
            {
            }
        }
Beispiel #7
0
        public virtual void TestPutReplaceEntry()
        {
            Ref otherc = NewRef(REF_c.GetName());

            NUnit.Framework.Assert.AreNotSame(REF_c, otherc);
            RefList <Ref> one = ToList(REF_A, REF_c);
            RefList <Ref> two = one.Put(otherc);

            NUnit.Framework.Assert.AreNotSame(one, two);
            // one is not modified, but two is
            NUnit.Framework.Assert.AreEqual(2, one.Size());
            NUnit.Framework.Assert.AreSame(REF_A, one.Get(0));
            NUnit.Framework.Assert.AreSame(REF_c, one.Get(1));
            NUnit.Framework.Assert.AreEqual(2, two.Size());
            NUnit.Framework.Assert.AreSame(REF_A, two.Get(0));
            NUnit.Framework.Assert.AreSame(otherc, two.Get(1));
        }
Beispiel #8
0
        public virtual void TestAddToMiddleOfListByInsertionPosition()
        {
            RefList <Ref> one = ToList(REF_A, REF_c);

            NUnit.Framework.Assert.AreEqual(-2, one.Find(REF_B.GetName()));
            RefList <Ref> two = one.Add(one.Find(REF_B.GetName()), REF_B);

            NUnit.Framework.Assert.AreNotSame(one, two);
            // one is not modified, but two is
            NUnit.Framework.Assert.AreEqual(2, one.Size());
            NUnit.Framework.Assert.AreSame(REF_A, one.Get(0));
            NUnit.Framework.Assert.AreSame(REF_c, one.Get(1));
            NUnit.Framework.Assert.AreEqual(3, two.Size());
            NUnit.Framework.Assert.AreSame(REF_A, two.Get(0));
            NUnit.Framework.Assert.AreSame(REF_B, two.Get(1));
            NUnit.Framework.Assert.AreSame(REF_c, two.Get(2));
        }
Beispiel #9
0
        public virtual void TestBuilder_AddThenSort()
        {
            RefListBuilder <Ref> builder = new RefListBuilder <Ref>(1);

            builder.Add(REF_B);
            builder.Add(REF_A);
            RefList <Ref> list = builder.ToRefList();

            NUnit.Framework.Assert.AreEqual(2, list.Size());
            NUnit.Framework.Assert.AreSame(REF_B, list.Get(0));
            NUnit.Framework.Assert.AreSame(REF_A, list.Get(1));
            builder.Sort();
            list = builder.ToRefList();
            NUnit.Framework.Assert.AreEqual(2, list.Size());
            NUnit.Framework.Assert.AreSame(REF_A, list.Get(0));
            NUnit.Framework.Assert.AreSame(REF_B, list.Get(1));
        }
Beispiel #10
0
        public virtual void TestCopyConstructorReusesArray()
        {
            RefListBuilder <Ref> one = new RefListBuilder <Ref>();

            one.Add(REF_A);
            RefList <Ref> two = new RefList <Ref>(one.ToRefList());

            one.Set(0, REF_B);
            NUnit.Framework.Assert.AreSame(REF_B, two.Get(0));
        }
Beispiel #11
0
        public virtual void TestEmpty()
        {
            RefList <Ref> list = RefList.EmptyList();

            NUnit.Framework.Assert.AreEqual(0, list.Size());
            NUnit.Framework.Assert.IsTrue(list.IsEmpty());
            NUnit.Framework.Assert.IsFalse(list.Iterator().HasNext());
            NUnit.Framework.Assert.AreEqual(-1, list.Find("a"));
            NUnit.Framework.Assert.AreEqual(-1, list.Find("z"));
            NUnit.Framework.Assert.IsFalse(list.Contains("a"));
            NUnit.Framework.Assert.IsNull(list.Get("a"));
            try
            {
                list.Get(0);
                NUnit.Framework.Assert.Fail("RefList.emptyList should have 0 element array");
            }
            catch (IndexOutOfRangeException)
            {
            }
        }
Beispiel #12
0
        public virtual void TestAddToEmptyList()
        {
            RefList <Ref> one = ToList();
            RefList <Ref> two = one.Add(0, REF_B);

            NUnit.Framework.Assert.AreNotSame(one, two);
            // one is not modified, but two is
            NUnit.Framework.Assert.AreEqual(0, one.Size());
            NUnit.Framework.Assert.AreEqual(1, two.Size());
            NUnit.Framework.Assert.IsFalse(two.IsEmpty());
            NUnit.Framework.Assert.AreSame(REF_B, two.Get(0));
        }
Beispiel #13
0
        public virtual void TestFindContainsGet()
        {
            RefList <Ref> list = ToList(REF_A, REF_B, REF_c);

            NUnit.Framework.Assert.AreEqual(0, list.Find("A"));
            NUnit.Framework.Assert.AreEqual(1, list.Find("B"));
            NUnit.Framework.Assert.AreEqual(2, list.Find("c"));
            NUnit.Framework.Assert.AreEqual(-1, list.Find("0"));
            NUnit.Framework.Assert.AreEqual(-2, list.Find("AB"));
            NUnit.Framework.Assert.AreEqual(-3, list.Find("a"));
            NUnit.Framework.Assert.AreEqual(-4, list.Find("z"));
            NUnit.Framework.Assert.AreSame(REF_A, list.Get("A"));
            NUnit.Framework.Assert.AreSame(REF_B, list.Get("B"));
            NUnit.Framework.Assert.AreSame(REF_c, list.Get("c"));
            NUnit.Framework.Assert.IsNull(list.Get("AB"));
            NUnit.Framework.Assert.IsNull(list.Get("z"));
            NUnit.Framework.Assert.IsTrue(list.Contains("A"));
            NUnit.Framework.Assert.IsTrue(list.Contains("B"));
            NUnit.Framework.Assert.IsTrue(list.Contains("c"));
            NUnit.Framework.Assert.IsFalse(list.Contains("AB"));
            NUnit.Framework.Assert.IsFalse(list.Contains("z"));
        }
        public virtual void TestPut_WithPrefix()
        {
            Ref refA_one = NewRef("refs/heads/A", ID_ONE);
            Ref refA_two = NewRef("refs/heads/A", ID_TWO);

            packed = ToList(refA_one);
            RefMap map = new RefMap("refs/heads/", packed, loose, resolved);

            NUnit.Framework.Assert.AreSame(refA_one, map.Get("A"));
            NUnit.Framework.Assert.AreSame(refA_one, map.Put("A", refA_two));
            // map changed, but packed, loose did not
            NUnit.Framework.Assert.AreSame(refA_two, map.Get("A"));
            NUnit.Framework.Assert.AreSame(refA_one, packed.Get(0));
            NUnit.Framework.Assert.AreEqual(0, loose.Size());
            NUnit.Framework.Assert.AreSame(refA_two, map.Put("A", refA_one));
            NUnit.Framework.Assert.AreSame(refA_one, map.Get("A"));
        }