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) { } }
public override Ref Put(string keyName, Ref value) { string name = ToRefName(keyName); if (!name.Equals(value.GetName())) { throw new ArgumentException(); } if (!resolved.IsEmpty()) { // Collapse the resolved list into the loose list so we // can discard it and stop joining the two together. foreach (Ref @ref in resolved) { loose = loose.Put(@ref); } resolved = RefList.EmptyList(); } int idx = loose.Find(name); if (0 <= idx) { Ref prior = loose.Get(name); loose = loose.Set(idx, value); return(prior); } else { Ref prior = Get(keyName); loose = loose.Add(idx, value); sizeIsValid = false; return(prior); } }
/// <summary>Construct an empty map with a small initial capacity.</summary> /// <remarks>Construct an empty map with a small initial capacity.</remarks> public RefMap() { prefix = string.Empty; packed = RefList.EmptyList(); loose = RefList.EmptyList(); resolved = RefList.EmptyList(); }
public virtual void TestRemoveMakesEmpty() { RefList <Ref> one = ToList(REF_A); RefList <Ref> two = one.Remove(1); NUnit.Framework.Assert.AreNotSame(one, two); NUnit.Framework.CollectionAssert.AreEquivalent(two, RefList.EmptyList <Ref>()); }
public override void Clear() { this._enclosing.packed = RefList.EmptyList(); this._enclosing.loose = RefList.EmptyList(); this._enclosing.resolved = RefList.EmptyList(); this._enclosing.size = 0; this._enclosing.sizeIsValid = true; }
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) { } }
public virtual void SetUp() { packed = RefList.EmptyList(); loose = RefList.EmptyList(); resolved = RefList.EmptyList(); }