public void CreateListTest() { var item = new FixedIndexList <double>(); Assert.AreEqual(0, item.Capacity); Assert.IsTrue(item.IndexUpperBound <= 0); }
public void CtorSetCapacityShouldNotNeedResize() { var list = new FixedIndexList <int>(10); Assert.AreEqual(10, list.Capacity); Enumerable.Range(0, 10).ForEach(i => list.Add(i)); }
private static FixedIndexList <double> CreateList(int count) { var item = new FixedIndexList <double>(); Enumerable.Range(0, count).ForEach(i => item.Add(i)); return(item); }
public void RemoveAlreadyRemovedIndexShouldDoNothing() { var list = new FixedIndexList <int>(); var index = list.Add(0); list.RemoveAt(index); list.RemoveAt(index); }
public void ClearTest() { var list = new FixedIndexList <int>(); Enumerable.Range(0, 10).ForEach(i => list.Add(i)); list.Clear(); Assert.AreEqual(0, list.Count); }
public void ReadItemCorrectnessTest() { var list = new FixedIndexList <double>(); var elem = Enumerable.Range(0, 100000); var indices = elem.Select(i => list.Add(i)); Assert.IsTrue(elem.Zip(indices, (item, index) => new { item, index }) .All(i => list[i.index] == i.item)); }
private static bool ForeachThrows <T>(FixedIndexList <T> list, Action <FixedIndexList <T> > ac) { return(ExceptionHelpers.Throws(() => { foreach (var i in list) { ac(list); } })); }
public void ForeachShouldThrowIfListChanged() { var list = new FixedIndexList <int>(); Enumerable.Range(0, 10).ForEach(i => list.Add(i)); Assert.IsTrue(ForeachThrows(list, lst => lst.Add(0))); Assert.IsTrue(ForeachThrows(list, lst => lst.RemoveAt(0))); Assert.IsTrue(ForeachThrows(list, lst => lst[2] = 0)); Assert.IsTrue(ForeachThrows(list, lst => lst.Clear())); }
public void InsertAfterRemovalTest() { var list = new FixedIndexList <int>(); var indices = Enumerable.Range(0, 10).Select(i => list.Add(i)).ToList(); list.RemoveAt(indices[5]); var i5 = list.Add(-1); Assert.IsTrue(indices.All((index, n) => n == 5 || index == n)); Assert.IsTrue(list[i5] == -1); }
public void ForeachTest() { var list = new FixedIndexList <int>(); var elem = Enumerable.Range(0, 10); var indices = elem.Select(i => list.Add(i)).ToList(); list.RemoveAt(indices[8]); var set = new HashSet <int>(); foreach (var i in list) { set.Add(i); } Assert.IsTrue(set.SetEquals(elem.Except(new[] { 8 }))); }
public void CountPropertyTest() { // New instance var list = new FixedIndexList <int>(); Assert.AreEqual(0, list.Count); // Add elements var indices = Enumerable.Repeat(0, 50).Select(i => list.Add(i)).ToList(); Assert.AreEqual(50, list.Count); // Remove elements indices.Take(20).ForEach(index => list.RemoveAt(index)); Assert.AreEqual(30, list.Count); // Add into previously removed spots Enumerable.Repeat(0, 10).ForEach(i => list.Add(i)); Assert.AreEqual(40, list.Count); }
public Graph() { _nodes = new FixedIndexList <Node>(); _edges = new FixedIndexList <Edge <TEdge> >(); }
public Node(TNode value) { this.value = value; prev = new FixedIndexList <int>(); next = new FixedIndexList <int>(); }