private RefList <Ref> ToList(params Ref[] refs) { RefListBuilder <Ref> b = new RefListBuilder <Ref>(refs.Length); b.AddAll(refs, 0, refs.Length); return(b.ToRefList()); }
/// <summary> /// Obtain a builder initialized with the first /// <code>n</code> /// elements. /// <p> /// Copies the first /// <code>n</code> /// elements from this list into a new builder, /// which can be used by the caller to add additional elements. /// </summary> /// <param name="n">the number of elements to copy.</param> /// <returns> /// a new builder with the first /// <code>n</code> /// elements already added. /// </returns> public RefListBuilder <T> Copy(int n) { RefListBuilder <T> r = new RefListBuilder <T>(Math.Max(16, n)); r.AddAll(list, 0, n); return(r); }
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)); }
public virtual void TestBuilder_Remove() { RefListBuilder <Ref> builder = new RefListBuilder <Ref>(); builder.Add(REF_A); builder.Add(REF_B); builder.Remove(0); NUnit.Framework.Assert.AreEqual(1, builder.Size()); NUnit.Framework.Assert.AreSame(REF_B, builder.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 TestBuilder_ToString() { StringBuilder exp = new StringBuilder(); exp.Append("["); exp.Append(REF_A); exp.Append(", "); exp.Append(REF_B); exp.Append("]"); RefListBuilder <Ref> list = new RefListBuilder <Ref>(); list.Add(REF_A); list.Add(REF_B); NUnit.Framework.Assert.AreEqual(exp.ToString(), list.ToString()); }
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 TestEmptyBuilder() { RefList <Ref> list = new RefListBuilder <Ref>().ToRefList(); NUnit.Framework.Assert.AreEqual(0, list.Size()); 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")); NUnit.Framework.Assert.IsTrue(list.AsList().IsEmpty()); NUnit.Framework.Assert.AreEqual("[]", list.ToString()); // default array capacity should be 16, with no bounds checking. NUnit.Framework.Assert.IsNull(list.Get(16 - 1)); try { list.Get(16); NUnit.Framework.Assert.Fail("default RefList should have 16 element array"); } catch (IndexOutOfRangeException) { } }