public void EmptyListSucceeds()
        {
            IList <int> list = new SortedLinkedList <int>();

            list.AddItem(16);

            Assert.IsTrue(list.Contains(16));

            list.Empty();

            Assert.IsFalse(list.Contains(16));
        }
        public void RemoveNotPresentElementFromList()
        {
            const string elementToRemove = "NOT Present";
            var          list            = new SortedLinkedList <string>((a, b) => a.CompareTo(b));

            list.Add("An element");
            list.Add("Present");
            list.Add("Another LMNT");

            Assert.Equal(list.Count, 3);
            Assert.False(list.Contains(elementToRemove));

            list.Remove(elementToRemove);
            Assert.Equal(list.Count, 3);
            Assert.False(list.Contains(elementToRemove));
        }
Пример #3
0
        public bool Contains(string value)
        {
            int hash = HashFunction.Hash(value);

            if (string.IsNullOrEmpty(_table[hash]))
            {
                return(false);
            }

            return(_table[hash].Equals(value) || _sll.Contains(value));
        }
        public void ClearElementsFromListThenAdd()
        {
            var list = new SortedLinkedList <string>((a, b) => a.CompareTo(b));

            list.Add("A");
            list.Add("B");
            list.Add("C");

            Assert.Equal(list.Count, 3);

            list.Clear();
            Assert.Empty(list);

            list.Add("Z");

            Assert.Equal(list.Count, 1);
            Assert.True(list.Contains("Z"));
        }
Пример #5
0
        // Creates WeighedBlocks only for the positions checked.
        public void FindPath()
        {
            FindStartAndEnd();

            // Now we need to weigh the blocks starting from the Start block
            _queue.SortedAddFront(_start);
            bool atEnd = false;

            while (_queue.Count > 0)
            {
                /* For debugging purposes.
                 * Console.Clear();
                 * Console.WriteLine($"Cleared screen! {_queue.Count}");
                 * foreach (var b in _queue)
                 * {
                 *  var prev = b.PrevBlock != null ? b.PrevBlock.Position.ToString() : "null";
                 *  Console.WriteLine($"Pos: {b.Position}, Prev: {prev}, Step: {b.StepWeight}, Dist: {b.DistanceWeight}, Total: {b.TotalWeight}");
                 * }
                 * /**/

                var block = _queue.PopFront();

                // Now we get the surrounding blocks
                var positions = block.GetSurroundingLocations();
                var sizeX     = _map.GetLength(1);
                var sizeY     = _map.GetLength(0);

                foreach (var pos in positions)
                {
                    // Skips the positions outside our map
                    if (pos.x < 0 || pos.x >= sizeX)
                    {
                        continue;
                    }
                    if (pos.y < 0 || pos.y >= sizeY)
                    {
                        continue;
                    }

                    // Skips the previous block that this block is linked to
                    if (block.PrevBlock != null && pos == block.PrevBlock.Position)
                    {
                        continue;
                    }

                    // Skips walls
                    var mapValue = _map[pos.y, pos.x];
                    if (mapValue.Equals('W'))
                    {
                        continue;
                    }

                    // Breaks out of this for loop when one of the neighboring
                    // blocks is the end block.
                    if (mapValue.Equals('E'))
                    {
                        Console.WriteLine("Found end!\n");
                        _end.StepWeight = block.StepWeight + 1;
                        _end.PrevBlock  = block;
                        atEnd           = true;
                        break;
                    }

                    // Skips if the new block has already been processed
                    // or is in the queue of being processed.
                    var newBlock = new WeighedBlock(pos, _end);
                    if (_finishedBlocks.Contains(newBlock))
                    {
                        continue;
                    }
                    if (_queue.Contains(newBlock))
                    {
                        continue;
                    }

                    newBlock.StepWeight = block.StepWeight + 1;
                    newBlock.PrevBlock  = block;

                    _queue.SortedAddFront(newBlock);
                }

                if (atEnd)
                {
                    break;
                }

                _finishedBlocks.Add(block);
            }

            TracePath();
        }
Пример #6
0
 public void ContainsTest()
 {
     Assert.True(LList.Contains("Frank"));
 }