コード例 #1
0
    public void EnableHierarchy_NodeNotInTree()
    {
        SkipTree <Item> tree  = new SkipTree <Item>();
        var             one   = new Item(null, "one");
        var             two   = new Item(null, "two");
        var             three = new Item(null, "three");
        var             four  = new Item(two, "four");
        var             five  = new Item(two, "five");
        var             six   = new Item(two, "six");

        tree.AddItem(one);
        // two not in tree!
        tree.AddItem(three);
        tree.AddItem(four);
        tree.AddItem(five);
        tree.AddItem(six);
        tree.DisableHierarchy(five);
        tree.DisableHierarchy(four);
        string[] output = new string[5];
        int      i      = 0;

        tree.EnableHierarchy(two);
        tree.TraversePreOrder((item) => {
            output[i++] = item.name;
        });
        Assert.AreEqual(new[] { "one", "three", "four", "five", "six" }, output);
        Assert.AreEqual(5, tree.Size);
    }
コード例 #2
0
    public void OhForFuckSakesNotAgain()
    {
        SkipTree <Item> tree  = new SkipTree <Item>();
        var             one   = new Item(null, "one");
        var             two   = new Item(null, "two");
        var             three = new Item(two, "three");
        var             four  = new Item(two, "four");
        var             five  = new Item(two, "five");
        var             six   = new Item(null, "six");

        tree.AddItem(one);
        tree.AddItem(two);
        tree.AddItem(three);
        tree.AddItem(four);
        tree.AddItem(five);
        tree.AddItem(six);
        string[] output = new string[3];
        int      i      = 0;

        tree.ConditionalTraversePreOrder((item) => {
            output[i++] = item.name;
            return(item.name != "two");
        });
        Assert.AreEqual(new [] {
            "one", "two", "six"
        }, output);
    }
コード例 #3
0
    public void RemoveAnElementHierarchy_NodeInTree()
    {
        SkipTree <Item> tree  = new SkipTree <Item>();
        var             one   = new Item(null, "one");
        var             two   = new Item(null, "two");
        var             three = new Item(null, "three");
        var             four  = new Item(two, "four");
        var             five  = new Item(two, "five");
        var             six   = new Item(two, "six");

        tree.AddItem(one);
        tree.AddItem(two);
        tree.AddItem(three);
        tree.AddItem(four);
        tree.AddItem(five);
        tree.AddItem(six);
        tree.RemoveHierarchy(two);
        string[] output = new string[2];
        int      i      = 0;

        tree.TraversePreOrder((item) => {
            output[i++] = item.name;
        });
        Assert.AreEqual(new[] { "one", "three" }, output);
        Assert.AreEqual(2, tree.Size);
    }
コード例 #4
0
    public void SetSiblingIndex()
    {
        SkipTree <Item> tree  = new SkipTree <Item>();
        var             one   = new Item(null, "one");
        var             two   = new Item(null, "two");
        var             three = new Item(null, "three");
        var             four  = new Item(null, "four");
        var             five  = new Item(null, "five");
        var             six   = new Item(null, "six");

        tree.AddItem(one);
        tree.AddItem(two);
        tree.AddItem(three);
        tree.AddItem(four);
        tree.AddItem(five);
        tree.AddItem(six);

        Assert.AreEqual(0, tree.GetSiblingIndex(one));
        Assert.AreEqual(1, tree.GetSiblingIndex(two));
        Assert.AreEqual(2, tree.GetSiblingIndex(three));
        Assert.AreEqual(3, tree.GetSiblingIndex(four));
        Assert.AreEqual(4, tree.GetSiblingIndex(five));
        Assert.AreEqual(5, tree.GetSiblingIndex(six));

        tree.SetSiblingIndex(two, 0);
        Assert.AreEqual(1, tree.GetSiblingIndex(one));
        Assert.AreEqual(0, tree.GetSiblingIndex(two));

        tree.SetSiblingIndex(five, 3);

        Assert.AreEqual(1, tree.GetSiblingIndex(one));
        Assert.AreEqual(0, tree.GetSiblingIndex(two));
        Assert.AreEqual(2, tree.GetSiblingIndex(three));
        Assert.AreEqual(3, tree.GetSiblingIndex(five));
        Assert.AreEqual(4, tree.GetSiblingIndex(four));
        Assert.AreEqual(5, tree.GetSiblingIndex(six));

        tree.SetSiblingIndex(six, -1);
        Assert.AreEqual(0, tree.GetSiblingIndex(six));
        Assert.AreEqual(1, tree.GetSiblingIndex(two));
        Assert.AreEqual(2, tree.GetSiblingIndex(one));
        Assert.AreEqual(3, tree.GetSiblingIndex(three));
        Assert.AreEqual(4, tree.GetSiblingIndex(five));
        Assert.AreEqual(5, tree.GetSiblingIndex(four));

        tree.SetSiblingIndex(six, 10);
        Assert.AreEqual(0, tree.GetSiblingIndex(two));
        Assert.AreEqual(1, tree.GetSiblingIndex(one));
        Assert.AreEqual(2, tree.GetSiblingIndex(three));
        Assert.AreEqual(3, tree.GetSiblingIndex(five));
        Assert.AreEqual(4, tree.GetSiblingIndex(four));
        Assert.AreEqual(5, tree.GetSiblingIndex(six));
    }
コード例 #5
0
    public void GetTraversableTree_Root()
    {
        SkipTree <Item> tree  = new SkipTree <Item>();
        var             one   = new Item(null, "one");
        var             two   = new Item(null, "two");
        var             three = new Item(null, "three");
        var             four  = new Item(two, "four");
        var             five  = new Item(two, "five");
        var             six   = new Item(two, "six");

        tree.AddItem(one);
        tree.AddItem(two);
        tree.AddItem(three);
        tree.AddItem(four);
        tree.AddItem(five);
        tree.AddItem(six);

        SkipTree <Item> .TreeNode traverseTree = tree.GetTraversableTree();

        Stack <SkipTree <Item> .TreeNode> stack = new Stack <SkipTree <Item> .TreeNode>();

        stack.Push(traverseTree);
        string[] output = new string[6];
        int      count  = 0;

        while (stack.Count > 0)
        {
            var current = stack.Pop();
            if (current.item != null)
            {
                output[count++] = current.item.name;
            }
            for (int i = 0; i < current.children.Length; i++)
            {
                stack.Push(current.children[i]);
            }
        }

        Assert.AreEqual(new string[] {
            "three",
            "two",
            "six",
            "five",
            "four",
            "one"
        }, output);
    }
コード例 #6
0
    public void AddNodeToRoot()
    {
        SkipTree <Item> tree  = new SkipTree <Item>();
        var             one   = new Item(null, "one");
        var             two   = new Item(one, "two");
        var             three = new Item(one, "three");

        tree.AddItem(two);
        tree.AddItem(three);
        string[] output = new string[2];
        int      i      = 0;

        tree.TraversePreOrder((item) => {
            output[i++] = item.name;
        });
        Assert.AreEqual(new[] { "two", "three" }, output);
    }
コード例 #7
0
    public void Event_AddItem()
    {
        int             callCount = 0;
        SkipTree <Item> tree      = new SkipTree <Item>();
        var             one       = new Item(null, "one");
        var             two       = new Item(null, "two");

        tree.onTreeChanged += (changeType) => {
            if (changeType == SkipTree <Item> .TreeChangeType.ItemAdded)
            {
                callCount++;
            }
        };
        tree.AddItem(one);
        tree.AddItem(two);
        Assert.AreEqual(2, callCount);
    }
コード例 #8
0
    public void MissingParentInTree()
    {
        SkipTree <Item> tree  = new SkipTree <Item>();
        var             one   = new Item(null, "one");
        var             two   = new Item(one, "two");
        var             three = new Item(two, "three");
        var             four  = new Item(two, "four");

        tree.AddItem(three);
        tree.AddItem(four);
        tree.AddItem(one);
        string[] output = new string[3];
        int      i      = 0;

        tree.TraversePreOrder((item) => {
            output[i++] = item.name;
        });
        Assert.AreEqual(new[] { "one", "three", "four" }, output);
    }
コード例 #9
0
    public void Event_RemoveHierarchy()
    {
        int             callCount = 0;
        SkipTree <Item> tree      = new SkipTree <Item>();
        var             one       = new Item(null, "one");
        var             two       = new Item(null, "two");

        tree.onTreeChanged += (changeType) => {
            if (changeType == SkipTree <Item> .TreeChangeType.HierarchyRemoved)
            {
                callCount++;
            }
        };
        tree.AddItem(one);
        tree.AddItem(two);
        tree.DisableHierarchy(two);
        tree.RemoveHierarchy(two);
        Assert.AreEqual(1, callCount);
    }
コード例 #10
0
        protected InputSystem(ILayoutSystem layoutSystem, KeyboardInputManager keyboardInputManager = null)
        {
            this.m_LayoutSystem = layoutSystem;

            this.m_MouseDownElements = new LightList <UIElement>();
            this.m_ElementsThisFrame = new List <UIElement>();
            this.m_ElementsLastFrame = new List <UIElement>();
            this.m_EnteredElements   = new List <UIElement>();
            this.m_ExitedElements    = new List <UIElement>();
            this.m_ActiveElements    = new List <UIElement>();

            this.m_KeyboardEventTree     = new SkipTree <UIElement>();
            this.keyboardInputManager    = keyboardInputManager ?? new KeyboardInputManager();
            this.m_EventPropagator       = new EventPropagator();
            this.m_MouseEventCaptureList = new List <ValueTuple <object, UIElement> >();
            // this.m_DragEventCaptureList = new List<ValueTuple<DragEventHandler, UIElement>>();
            this.m_FocusedElement = null;
            this.focusables       = new List <IFocusable>();
            this.hoveredElements  = new LightList <UIElement>(16);
        }