Example #1
0
        public void CreateListTest()
        {
            var item = new FixedIndexList <double>();

            Assert.AreEqual(0, item.Capacity);
            Assert.IsTrue(item.IndexUpperBound <= 0);
        }
Example #2
0
        public void CtorSetCapacityShouldNotNeedResize()
        {
            var list = new FixedIndexList <int>(10);

            Assert.AreEqual(10, list.Capacity);
            Enumerable.Range(0, 10).ForEach(i => list.Add(i));
        }
Example #3
0
        private static FixedIndexList <double> CreateList(int count)
        {
            var item = new FixedIndexList <double>();

            Enumerable.Range(0, count).ForEach(i => item.Add(i));
            return(item);
        }
Example #4
0
        public void RemoveAlreadyRemovedIndexShouldDoNothing()
        {
            var list  = new FixedIndexList <int>();
            var index = list.Add(0);

            list.RemoveAt(index);
            list.RemoveAt(index);
        }
Example #5
0
        public void ClearTest()
        {
            var list = new FixedIndexList <int>();

            Enumerable.Range(0, 10).ForEach(i => list.Add(i));
            list.Clear();
            Assert.AreEqual(0, list.Count);
        }
Example #6
0
        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));
        }
Example #7
0
 private static bool ForeachThrows <T>(FixedIndexList <T> list, Action <FixedIndexList <T> > ac)
 {
     return(ExceptionHelpers.Throws(() =>
     {
         foreach (var i in list)
         {
             ac(list);
         }
     }));
 }
Example #8
0
        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()));
        }
Example #9
0
        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);
        }
Example #10
0
        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 })));
        }
Example #11
0
        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);
        }
Example #12
0
 public Graph()
 {
     _nodes = new FixedIndexList <Node>();
     _edges = new FixedIndexList <Edge <TEdge> >();
 }
Example #13
0
 public Node(TNode value)
 {
     this.value = value;
     prev       = new FixedIndexList <int>();
     next       = new FixedIndexList <int>();
 }