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)); }
public virtual void TestPut_NoPrefix() { 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(string.Empty, packed, loose, resolved); NUnit.Framework.Assert.AreSame(refA_one, map.Get(refA_one.GetName())); NUnit.Framework.Assert.AreSame(refA_one, map.Put(refA_one.GetName(), refA_two)); // map changed, but packed, loose did not NUnit.Framework.Assert.AreSame(refA_two, map.Get(refA_one.GetName())); NUnit.Framework.Assert.AreSame(refA_one, packed.Get(0)); NUnit.Framework.Assert.AreEqual(0, loose.Size()); NUnit.Framework.Assert.AreSame(refA_two, map.Put(refA_one.GetName(), refA_one)); NUnit.Framework.Assert.AreSame(refA_one, map.Get(refA_one.GetName())); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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) { } }