Ejemplo n.º 1
0
    public void RemoveAnElementWithSiblings()
    {
        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.RemoveItem(two);
        string[] output = new string[5];
        int      i      = 0;

        tree.TraversePreOrder((item) => {
            output[i++] = item.name;
        });
        Assert.AreEqual(new[] { "one", "four", "five", "six", "three" }, output);
        Assert.AreEqual(tree.Size, 5);
    }
Ejemplo n.º 2
0
    public void Event_RemoveItem()
    {
        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.ItemRemoved)
            {
                callCount++;
            }
        };
        tree.AddItem(one);
        tree.AddItem(two);
        tree.RemoveItem(two);
        Assert.AreEqual(1, callCount);
    }
Ejemplo n.º 3
0
    public void RemoveAnElement()
    {
        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);
        tree.AddItem(one);
        tree.RemoveItem(one);
        string[] output = new string[2];
        int      i      = 0;

        tree.TraversePreOrder((item) => {
            output[i++] = item.name;
        });
        Assert.AreEqual(new[] { "two", "three" }, output);
    }