Esempio n. 1
0
        public static void TestFindOrderedListIntDesc()
        {
            var list = new OrderedList <int>(false);

            Assert.AreEqual(0, list.Count(), "TestFindOrderedListIntAsc orderedList size must be 0, but not");
            list.Add(4);
            list.Add(3);
            list.Add(2);
            list.Add(1);
            Assert.AreEqual(4, list.Count(), "TestFindOrderedListIntAsc orderedList size must be 4, but not");

            var found = list.Find(3);

            Assert.AreEqual(3, found.value);
            Assert.AreEqual(4, found.prev.value);
            Assert.AreEqual(2, found.next.value);

            found = list.Find(4);
            Assert.AreEqual(4, found.value);
            Assert.AreEqual(3, found.next.value);
            Assert.IsNull(found.prev);

            found = list.Find(1);
            Assert.AreEqual(1, found.value);
            Assert.AreEqual(2, found.prev.value);
            Assert.IsNull(found.next);
        }
Esempio n. 2
0
        public IEnumerable <AccessRule> GetAcls(string resource, string verb)
        {
            resource = GetAbsoluteResourcePath(verb, resource);

            OrderedList <string, AccessRule> acls = new OrderedList <string, AccessRule>();

            while (resource != string.Empty)
            {
                if (Denied.ContainsKey(resource))
                {
                    foreach (AccessRule acl in Denied[resource])
                    {
                        acls.Add(acl.Resource, acl);
                    }
                }
                if (Allowed.ContainsKey(resource))
                {
                    foreach (AccessRule acl in Allowed[resource])
                    {
                        acls.Add(acl.Resource, acl);
                    }
                }
                if (resource == AclManager.ROOT)
                {
                    break;
                }

                resource = resource.LastIndexOf(AclManager.ROOT) <= 0 ? AclManager.ROOT : resource.Substring(0, resource.LastIndexOf(AclManager.ROOT));
            }
            return(acls);
        }
        public void Test_Add_WhenAddedInTail()
        {
            var list = new OrderedList <int>(true);

            list.Add(1);
            list.Add(2);

            Assert.AreEqual("[1, 2]", list.ToString());
        }
        public void TestFindAsc_1()
        {
            OrderedList <int> ord = new OrderedList <int>(true);

            ord.Add(3);
            ord.Add(2);
            ord.Add(1);

            Assert.AreEqual(2, ord.Find(2).value);
        }
        public void Test_Add_WhenAddedExistingValueInMiddle()
        {
            var list = new OrderedList <int>(true);

            list.Add(1);
            list.Add(2);
            list.Add(2);

            Assert.AreEqual("[1, 2, 2]", list.ToString());
        }
        public void TestFindAsc_5()
        {
            OrderedList <string> ord = new OrderedList <string>(true);

            ord.Add("Crab");
            ord.Add("Raccoon");
            ord.Add("Cat");
            ord.Add("Fat man");

            Assert.AreEqual("Cat", ord.Find("Cat").value);
        }
        public void TestFindDes_1()
        {
            OrderedList <int> ord = new OrderedList <int>(false);

            ord.Add(5);
            ord.Add(4);
            ord.Add(2);
            ord.Add(1);

            Assert.AreEqual(null, ord.Find(3));
        }
        public void Test_Find_WhenNotFound()
        {
            var list = new OrderedList <int>(true);

            list.Add(1);
            list.Add(2);
            list.Add(3);
            var result = list.Find(4);

            Assert.AreEqual(null, result);
        }
        public void Test_Find_WhenFilledOut()
        {
            var list = new OrderedList <int>(true);

            list.Add(1);
            list.Add(2);
            list.Add(3);
            var result = list.Find(2);

            Assert.AreEqual(2, result.value);
        }
        public void Test_Add_WhenDeletedFromMiddle()
        {
            var list = new OrderedList <int>(true);

            list.Add(1);
            list.Add(2);
            list.Add(3);
            list.Delete(2);

            Assert.AreEqual("[1, 3]", list.ToString());
        }
        public void TestFindAsc_3()
        {
            OrderedList <int> ord = new OrderedList <int>(true);

            ord.Add(5);
            ord.Add(4);
            ord.Add(2);
            ord.Add(1);

            Assert.AreEqual(null, ord.Find(3));
        }
        public void Test_Count_WhenNotFound()
        {
            var list = new OrderedList <int>(true);

            list.Add(1);
            list.Add(2);
            list.Add(3);
            var result = list.Count();

            Assert.AreEqual(3, result);
        }
        public void TestAddStringAsc_5()
        {
            OrderedList <string> ord = new OrderedList <string>(true);

            ord.Add("");
            ord.Add("1");
            ord.Add("C");

            Assert.AreEqual("", ord.head.value);
            Assert.AreEqual("1", ord.head.next.value);
            Assert.AreEqual("C", ord.head.next.next.value);
        }
        public void TestAddStringDes_1()
        {
            OrderedList <string> ord = new OrderedList <string>(false);

            ord.Add("Ace");
            ord.Add("Button");
            ord.Add("Close");

            Assert.AreEqual("Close", ord.head.value);
            Assert.AreEqual("Button", ord.head.next.value);
            Assert.AreEqual("Ace", ord.head.next.next.value);
        }
Esempio n. 15
0
    public void TestIndexOf()
    {
        var test = new OrderedList <int>(new[] { 0, -1, -2 });

        Assert.AreEqual(0, test.IndexOf(-2));
        Assert.AreEqual(2, test.IndexOf(0));
        test.Add(-2);
        Assert.AreEqual(0, test.IndexOf(-2));
        Assert.AreEqual(1, test.LastIndexOf(-2));
        test.Add(0);
        Assert.AreEqual(3, test.IndexOf(0));
        Assert.AreEqual(4, test.LastIndexOf(0));
    }
Esempio n. 16
0
        public void Find_if_Elem_Is_not_Exists_in_Desc_List()
        {
            OrderedList <int> tList = new OrderedList <int>(false);

            tList.Add(12);
            tList.Add(48);
            tList.Add(35);
            tList.Add(-101);

            Node <int> actual = tList.Find(42);

            Assert.IsNull(actual);
        }
Esempio n. 17
0
        public void Find_if_Elem_Is_not_Exists_in_Asc_List()
        {
            OrderedList <int> tList = new OrderedList <int>(true);

            tList.Add(2);
            tList.Add(3);
            tList.Add(9);
            tList.Add(0);

            Node <int> actual = tList.Find(42);

            Assert.IsNull(actual);
        }
Esempio n. 18
0
        public static void TestRemoveOrderedListIntDesc()
        {
            var list = new OrderedList <int>(false);

            Assert.AreEqual(0, list.Count(), "TestRemoveOrderedListIntDesc orderedList size must be 0, but not");
            list.Add(4);
            list.Add(3);
            list.Add(2);
            list.Add(1);
            Assert.AreEqual(4, list.Count(), "TestRemoveOrderedListIntDesc orderedList size must be 4, but not");

            var counter = 4;
            var node    = list.head;

            while (node != null)
            {
                Assert.AreEqual(counter, node.value, "Test TestRemoveOrderedListIntDesc failed. List sequence is not correct");
                counter -= 1;
                node     = node.next;
            }

            list.Delete(3);
            Assert.AreEqual(3, list.Count(), "TestRemoveOrderedListIntDesc orderedList size must be 3, but not");
            list.Delete(2);
            Assert.AreEqual(2, list.Count(), "TestRemoveOrderedListIntDesc orderedList size must be 2, but not");
            counter = 4;
            node    = list.head;
            while (node != null)
            {
                Assert.AreEqual(counter, node.value, "Test TestRemoveOrderedListIntDesc failed. List sequence is not correct");
                counter -= 3;
                node     = node.next;
            }

            list.Delete(1);
            Assert.AreEqual(1, list.Count(), "TestRemoveOrderedListIntDesc orderedList size must be 1, but not");
            counter = 4;
            node    = list.head;
            while (node != null)
            {
                Assert.AreEqual(counter, node.value, "Test TestRemoveOrderedListIntDesc failed. List sequence is not correct");
                counter -= 1;
                node     = node.next;
            }

            list.Delete(4);
            Assert.AreEqual(0, list.Count(), "TestRemoveOrderedListIntDesc orderedList size must be 0, but not");

            list.Delete(4);
            Assert.AreEqual(0, list.Count(), "TestRemoveOrderedListIntAsc orderedList size must be 0, but not");
        }
        public void TestAddStringDes_2()
        {
            OrderedList <string> ord = new OrderedList <string>(false);

            ord.Add("Aces");
            ord.Add("Ace");
            ord.Add("Crow");
            ord.Add("Acer");

            Assert.AreEqual("Crow", ord.head.value);
            Assert.AreEqual("Aces", ord.head.next.value);
            Assert.AreEqual("Acer", ord.head.next.next.value);
            Assert.AreEqual("Ace", ord.head.next.next.next.value);
        }
        public void TestAddStringAsc_7()
        {
            OrderedList <string> ord = new OrderedList <string>(true);

            ord.Add(" Car ");
            ord.Add("Point");
            ord.Add("Car");
            ord.Add(" Point ");

            Assert.AreEqual(" Car ", ord.head.value);
            Assert.AreEqual("Car", ord.head.next.value);
            Assert.AreEqual("Point", ord.head.next.next.value);
            Assert.AreEqual(" Point ", ord.head.next.next.next.value);
        }
        public void TestAddIntegerDes_2()
        {
            OrderedList <int> ord = new OrderedList <int>(false);

            ord.Add(-1);
            ord.Add(0);
            ord.Add(-2);
            ord.Add(-3);

            Assert.AreEqual(-3, ord.tail.value);
            Assert.AreEqual(-2, ord.tail.prev.value);
            Assert.AreEqual(0, ord.head.value);
            Assert.AreEqual(-1, ord.head.next.value);
        }
        public void TestAddStringAsc_8()
        {
            OrderedList <string> ord = new OrderedList <string>(true);

            ord.Add("  Peace of cake  ");
            ord.Add("Peaceofcake");
            ord.Add("Peace of cake");



            Assert.AreEqual("  Peace of cake  ", ord.head.value);
            Assert.AreEqual("Peace of cake", ord.head.next.value);
            Assert.AreEqual("Peaceofcake", ord.head.next.next.value);
        }
        public void TestAddIntegerDes_1()
        {
            OrderedList <int> ord = new OrderedList <int>(false);

            ord.Add(4);
            ord.Add(3);
            ord.Add(2);
            ord.Add(1);

            Assert.AreEqual(1, ord.tail.value);
            Assert.AreEqual(2, ord.tail.prev.value);
            Assert.AreEqual(4, ord.head.value);
            Assert.AreEqual(3, ord.head.next.value);
        }
        public void TestFindDes_2()
        {
            OrderedList <int> ord = new OrderedList <int>(false);

            ord.Add(5);
            ord.Add(4);
            ord.Add(2);
            ord.Add(1);

            Assert.AreEqual(1, ord.Find(1).value);
            Assert.AreEqual(2, ord.Find(2).value);
            Assert.AreEqual(null, ord.Find(3));
            Assert.AreEqual(4, ord.Find(4).value);
            Assert.AreEqual(5, ord.Find(5).value);
        }
Esempio n. 25
0
        public void List_is_sorted_by_sort_function()
        {
            var ol = new OrderedList<int>();

            ol.SortFunc = (x) => x;

            ol.Add(4);
            ol.Add(2);
            ol.Add(3);
            ol.Add(1);

            var expected = new int[] { 1, 2, 3, 4 };

            CollectionAssert.AreEqual(expected, ol);
        }
Esempio n. 26
0
        public void Changing_the_SortFunc_property_changes_the_sort_order()
        {
            var ol = new OrderedList<string>(x => x);

            ol.Add("Cheese");
            ol.Add("Acorn");
            ol.Add("Blah");

            CollectionAssert.AreEqual(new string[] { "Acorn", "Blah", "Cheese" }, ol);

            ol.SortFunc = x => x.Last().ToString();

            CollectionAssert.AreEqual(new string[] { "Cheese", "Blah", "Acorn" }, ol);

        }
Esempio n. 27
0
        public void AddTest()
        {
            var list = new OrderedList <int>(new int[] { 10, 5, 7 });

            list.Add(2);
            list.Add(8);

            Assert.AreEqual(5, list.Count);

            Assert.AreEqual(2, list[0]);
            Assert.AreEqual(5, list[1]);
            Assert.AreEqual(7, list[2]);
            Assert.AreEqual(8, list[3]);
            Assert.AreEqual(10, list[4]);
        }
        public void TestAddIntegerAsc_2()
        {
            OrderedList <int> ord = new OrderedList <int>(true);

            ord.Add(1);
            ord.Add(22);
            ord.Add(3);
            ord.Add(14);

            Assert.AreEqual(22, ord.tail.value);
            Assert.AreEqual(14, ord.tail.prev.value);
            Assert.AreEqual(1, ord.head.value);
            Assert.AreEqual(3, ord.head.next.value);
            Assert.AreEqual(14, ord.head.next.next.value);
        }
        public void TestDeleteStringAsc_3()
        {
            OrderedList <string> ord = new OrderedList <string>(true);

            ord.Add("Fat32");
            ord.Add("Fat32");
            ord.Add("Fat");
            ord.Add("Fat");

            Assert.AreEqual(4, ord.Count());

            ord.Delete("Fat");

            Assert.AreEqual(3, ord.Count());
        }
Esempio n. 30
0
        public void Find_if_Elem_Is_Exists_in_Desc_List()
        {
            OrderedList <int> tList = new OrderedList <int>(false);

            tList.Add(12);
            tList.Add(48);
            tList.Add(35);

            tList.Add(-101);

            int expectedFoundValue = -101;
            int actualFoundValue   = tList.Find(-101).value;

            Assert.AreEqual(expectedFoundValue, actualFoundValue);
        }
Esempio n. 31
0
        public void Find_if_Elem_Is_Exists_in_Asc_List()
        {
            OrderedList <int> tList = new OrderedList <int>(true);

            tList.Add(2);
            tList.Add(3);
            tList.Add(9);

            tList.Add(0);

            int expectedFoundValue = 3;
            int actualFoundValue   = tList.Find(3).value;

            Assert.AreEqual(expectedFoundValue, actualFoundValue);
        }
Esempio n. 32
0
    public Path FindPath(Node start, Node end)
    {
        var openedNodesList = new OrderedList <NodePathfindingData>(_grid.Width * _grid.Height, new NodesComparer());
        var closedNodesSet  = new HashSet <NodePathfindingData>();

        var startNodeData = _nodes[start.X, start.Y];
        var endNodeData   = _nodes[end.X, end.Y];

        openedNodesList.Add(startNodeData);

        while (openedNodesList.Count > 0)
        {
            var currentNode = openedNodesList[0];
            openedNodesList.RemoveAt(0);
            closedNodesSet.Add(currentNode);

            if (currentNode.Node == end)
            {
                return(new Path(startNodeData, endNodeData));
            }

            var nearbyNodes = _grid.GetNearbyNodes(currentNode.Node);
            for (var i = 0; i < nearbyNodes.Count; i++)
            {
                var nearbyNode = _nodes[nearbyNodes[i].X, nearbyNodes[i].Y];
                if (!nearbyNode.Node.IsWalkable || closedNodesSet.Contains(nearbyNode))
                {
                    continue;
                }

                int cost = currentNode.DistanceFromStartNode + GetDistance(currentNode, nearbyNode);
                if (cost >= nearbyNode.DistanceFromStartNode && openedNodesList.Contains(nearbyNode))
                {
                    continue;
                }

                nearbyNode.DistanceFromStartNode = cost;
                nearbyNode.DistanceToEndNode     = GetDistance(nearbyNode, endNodeData);
                nearbyNode.Parent = currentNode;
                if (!openedNodesList.Contains(nearbyNode))
                {
                    openedNodesList.Add(nearbyNode);
                }
            }
        }

        return(null);
    }
Esempio n. 33
0
        public void Remove_removes_items()
        {
            var s = "a string";
            var list = new OrderedList<string>();

            list.Add(s);

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

            Assert.IsTrue(list.Remove(s));

            Assert.IsFalse(list.Contains(s));
        }
Esempio n. 34
0
        public void Add_ToCollection()
        {
            var task = new Task("(B) Add_ToCollection +test @task");

            var tl = new TaskList(Data.TestDataPath);

            var tasks = new OrderedList<Task>(tl.Tasks);
            tasks.Add(task);

            tl.Add(task);

            var newTasks = tl.Tasks.ToList();

            Assert.AreEqual(tasks.Count, newTasks.Count);

            for (int i = 0; i < tasks.Count; i++)
                Assert.AreEqual(tasks[i].ToString(), newTasks[i].ToString());
        }