public void AddRemoveWorks() { var c = new FastCollection<int> { 1, 2, 3, 4, 5 }; Assert.True(c.SequenceEqual(new[] { 1, 2, 3, 4, 5 })); Assert.Equal(5, c.Count); var originalCapacity = c.Capacity; Assert.InRange(originalCapacity, 5, int.MaxValue); Assert.True(c.Remove(5)); AssertEquals(c, new[] { 1, 2, 3, 4 }); Assert.InRange(c.Capacity, 4, originalCapacity); c.RemoveAt(3); AssertEquals(c, new[] { 1, 2, 3 }); Assert.InRange(c.Capacity, 3, originalCapacity); Assert.True(c.Remove(1)); AssertEquals(c, new[] { 2, 3 }); Assert.InRange(c.Capacity, 2, originalCapacity); Assert.False(c.Remove(1)); var oneEl = c[1]; c.RemoveAt(0); Assert.Equal(oneEl, c[0]); Assert.Equal(1, c.Count); c.Add(4); AssertEquals(c, new[] { oneEl, 4 }); c.Clear(); Assert.True(c.SequenceEqual(new int[0])); Assert.Equal(0, c.Count); }
public void Remove() { IList b = new List <int>(); var fc = new FastCollection <IList>(); fc.Add(b, 2); Assert.AreEqual(1, b.Count); fc.Remove(b, 2); Assert.AreEqual(0, b.Count); }
public void ContainsWorks() { var c = new FastCollection<int> { 1, 2, 3 }; Assert.True(c.Contains(1)); Assert.True(c.Contains(2)); Assert.True(c.Contains(3)); Assert.False(c.Contains(4)); c.Remove(1); Assert.False(c.Contains(1)); Assert.True(c.Contains(2)); Assert.True(c.Contains(3)); Assert.False(c.Contains(4)); c.Clear(); Assert.False(c.Contains(1)); Assert.False(c.Contains(2)); Assert.False(c.Contains(3)); c.Add(3); Assert.False(c.Contains(1)); Assert.False(c.Contains(2)); Assert.True(c.Contains(3)); }
public void IndexOfWorks() { var c = new FastCollection<int> { 1, 2, 3 }; Assert.Equal(1, c[c.IndexOf(1)]); Assert.Equal(2, c[c.IndexOf(2)]); Assert.Equal(3, c[c.IndexOf(3)]); Assert.Equal(-1, c.IndexOf(4)); c.Remove(1); Assert.Equal(2, c[c.IndexOf(2)]); Assert.Equal(3, c[c.IndexOf(3)]); Assert.Equal(-1, c.IndexOf(1)); c.Clear(); Assert.Equal(-1, c.IndexOf(1)); Assert.Equal(-1, c.IndexOf(2)); Assert.Equal(-1, c.IndexOf(3)); c.Add(3); Assert.Equal(-1, c.IndexOf(1)); Assert.Equal(-1, c.IndexOf(2)); Assert.Equal(0, c.IndexOf(3)); Assert.Equal(3, c[0]); }
public void DoesntHoldReferences() { var wr1 = new WeakReference(new object()); var wr2 = new WeakReference(new object()); var c = new FastCollection<object> { wr1.Target, wr2.Target }; GC.Collect(); //GC.WaitForFullGCComplete(); Assert.Equal(2, c.Count); Assert.True(wr1.IsAlive); Assert.True(wr2.IsAlive); c.Remove(wr1.Target); GC.Collect(); //GC.WaitForFullGCComplete(); Assert.Equal(1, c.Count); Assert.False(wr1.IsAlive); Assert.True(wr2.IsAlive); c.Clear(); GC.Collect(); //GC.WaitForFullGCComplete(); Assert.Equal(0, c.Count); Assert.False(wr1.IsAlive); Assert.False(wr2.IsAlive); }