Example #1
0
        public void Summing()
        {
            XorLinkedList list = new XorLinkedList(new MonitoredUnmanagedMemory());

            list.Prepend(1);
            list.Prepend(2);
            list.Prepend(3);
            Assert.Equal(6, list.Sum());
        }
        public void AddTest()
        {
            var sut = new XorLinkedList();

            for (int i = 0; i < TestValues1.Length; i++)
            {
                Assert.AreEqual(i, sut.add(TestValues1[i]));
            }
        }
Example #3
0
        public void Append()
        {
            XorLinkedList list = new XorLinkedList(new MonitoredUnmanagedMemory());

            list.Append(1);
            list.Append(2);
            list.Append(3);
            Assert.Null(list.GetAt(-1));
            Assert.Equal(1, list.GetAt(0));
            Assert.Equal(2, list.GetAt(1));
            Assert.Equal(3, list.GetAt(2));
            Assert.Null(list.GetAt(3));
        }
        public void GetTest()
        {
            var sut = new XorLinkedList();

            for (int i = 0; i < TestValues1.Length; i++)
            {
                sut.add(TestValues1[i]);
            }
            for (int i = 0; i < TestValues1.Length; i++)
            {
                Assert.AreEqual(TestValues1[i], sut.get(i));
            }
        }
Example #5
0
        public void DeleteAll()
        {
            MonitoredUnmanagedMemory mem = new MonitoredUnmanagedMemory();

            XorLinkedList list = new XorLinkedList(mem);

            list.Append(1);
            list.Append(2);
            list.Append(3);

            list.DeleteAll();

            Assert.Empty(mem.currentAllocations);
        }
Example #6
0
        public void AllocationFreeing()
        {
            MonitoredUnmanagedMemory mem  = new MonitoredUnmanagedMemory();
            XorLinkedList            list = new XorLinkedList(mem);

            list.Append(1);
            list.Append(2);
            list.Append(3);
            list.RemoveAt(0);
            Assert.Equal(2, mem.currentAllocations.Count);
            list.RemoveAt(0);
            Assert.Single(mem.currentAllocations);
            list.RemoveAt(0);
            Assert.Empty(mem.currentAllocations);
        }
Example #7
0
        private unsafe void Start(int[] array)
        {
            XorLinkedList xorLinkedList = new XorLinkedList(array[0]);

            for (int i = 1; i < array.Length; i++)
            {
                xorLinkedList.Add(array[i]);
            }

            Console.WriteLine("XorList values:");
            foreach (int value in xorLinkedList)
            {
                Console.WriteLine(value);
            }
            Console.WriteLine("Value at index 2 is: {0}", xorLinkedList.Get(2));
        }
Example #8
0
                public bool MoveNext()
                {
                    if (curr == null)
                    {
                        curr = head;
                        return(true);
                    }
                    if (curr == tail)
                    {
                        return(false);
                    }
                    XorLinkedListNode *old = curr;

                    curr = XorLinkedList.Xor(prev, old->GetBoth());
                    prev = old;
                    return(true);
                }
Example #9
0
        public void ResponsiveToGarbageCollection()
        {
            MonitoredUnmanagedMemory mem = new MonitoredUnmanagedMemory();

            void innerScope()
            {
                XorLinkedList list = new XorLinkedList(mem);

                list.Append(1);
                list.Append(2);
                list.Append(3);
                Assert.Equal(3, mem.currentAllocations.Count);
            }

            innerScope();

            GC.Collect();
            GC.WaitForPendingFinalizers();
            Assert.Empty(mem.currentAllocations);
        }