Esempio n. 1
0
    public void Data_is_retained()
    {
        var zipper = Zipper <int> .FromTree(t1);

        var tree = zipper.ToTree();

        Assert.Equal(t1, tree);
    }
    public void Dead_end()
    {
        var tree   = new BinTree(1, new BinTree(2, null, new BinTree(3, null, null)), new BinTree(4, null, null));
        var sut    = Zipper.FromTree(tree);
        var actual = sut.Left().Left();

        Assert.Null(actual);
    }
    public void Traversing_up_from_top()
    {
        var tree   = new BinTree(1, new BinTree(2, null, new BinTree(3, null, null)), new BinTree(4, null, null));
        var sut    = Zipper.FromTree(tree);
        var actual = sut.Up();

        Assert.Null(actual);
    }
Esempio n. 4
0
    public void Data_is_retained()
    {
        var zipper = Zipper <int> .FromTree(t1);

        var tree = zipper.ToTree();

        Assert.That(tree, Is.EqualTo(t1));
    }
Esempio n. 5
0
    public void Set_value()
    {
        var zipper = Zipper <int> .FromTree(t1);

        var updatedZipper = zipper.Left().SetValue(5);
        var tree          = updatedZipper.ToTree();

        Assert.That(tree, Is.EqualTo(t2));
    }
Esempio n. 6
0
    public void Set_left_with_leaf()
    {
        var tree     = new BinTree(1, new BinTree(2, null, new BinTree(3, null, null)), new BinTree(4, null, null));
        var sut      = Zipper.FromTree(tree);
        var actual   = sut.Left().SetLeft(new BinTree(5, null, null)).ToTree();
        var expected = new BinTree(1, new BinTree(2, new BinTree(5, null, null), new BinTree(3, null, null)), new BinTree(4, null, null));

        Assert.Equal(expected, actual);
    }
Esempio n. 7
0
    public void Set_value_after_traversing_up()
    {
        var tree     = new BinTree(1, new BinTree(2, null, new BinTree(3, null, null)), new BinTree(4, null, null));
        var sut      = Zipper.FromTree(tree);
        var actual   = sut.Left().Right().Up().SetValue(5).ToTree();
        var expected = new BinTree(1, new BinTree(5, null, new BinTree(3, null, null)), new BinTree(4, null, null));

        Assert.Equal(expected, actual);
    }
Esempio n. 8
0
    public void Set_right_to_null()
    {
        var zipper = Zipper <int> .FromTree(t1);

        var updatedZipper = zipper.Left().SetRight(null);
        var tree          = updatedZipper.ToTree();

        Assert.Equal(t4, tree);
    }
Esempio n. 9
0
    public void Left_right_and_up()
    {
        var tree     = new BinTree(1, new BinTree(2, null, new BinTree(3, null, null)), new BinTree(4, null, null));
        var sut      = Zipper.FromTree(tree);
        var actual   = sut.Left().Up().Right().Up().Left().Right().Value();
        var expected = 3;

        Assert.Equal(expected, actual);
    }
Esempio n. 10
0
    public void Data_is_retained()
    {
        var tree     = new BinTree(1, new BinTree(2, null, new BinTree(3, null, null)), new BinTree(4, null, null));
        var sut      = Zipper.FromTree(tree);
        var actual   = sut.ToTree();
        var expected = new BinTree(1, new BinTree(2, null, new BinTree(3, null, null)), new BinTree(4, null, null));

        Assert.Equal(expected, actual);
    }
Esempio n. 11
0
    public void Different_paths_to_same_zipper()
    {
        var tree     = new BinTree(1, new BinTree(2, null, new BinTree(3, null, null)), new BinTree(4, null, null));
        var sut      = Zipper.FromTree(tree);
        var actual   = sut.Left().Up().Right();
        var expected = Zipper.FromTree(new BinTree(1, new BinTree(2, null, new BinTree(3, null, null)), new BinTree(4, null, null))).Right();

        Assert.Equal(expected, actual);
    }
Esempio n. 12
0
    public void Tree_from_deep_focus()
    {
        var tree     = new BinTree(1, new BinTree(2, null, new BinTree(3, null, null)), new BinTree(4, null, null));
        var sut      = Zipper.FromTree(tree);
        var actual   = sut.Left().Right().ToTree();
        var expected = new BinTree(1, new BinTree(2, null, new BinTree(3, null, null)), new BinTree(4, null, null));

        Assert.Equal(expected, actual);
    }
Esempio n. 13
0
    public void Set_left_with_value()
    {
        var zipper = Zipper <int> .FromTree(t1);

        var updatedZipper = zipper.Left().SetLeft(new BinTree <int>(5, null, null));
        var tree          = updatedZipper.ToTree();

        Assert.Equal(t3, tree);
    }
Esempio n. 14
0
    public void Set_right_with_subtree()
    {
        var tree     = new BinTree(1, new BinTree(2, null, new BinTree(3, null, null)), new BinTree(4, null, null));
        var sut      = Zipper.FromTree(tree);
        var actual   = sut.SetRight(new BinTree(6, new BinTree(7, null, null), new BinTree(8, null, null))).ToTree();
        var expected = new BinTree(1, new BinTree(2, null, new BinTree(3, null, null)), new BinTree(6, new BinTree(7, null, null), new BinTree(8, null, null)));

        Assert.Equal(expected, actual);
    }
Esempio n. 15
0
    public void Set_value()
    {
        var zipper = Zipper <int> .FromTree(t1);

        var updatedZipper = zipper.Left().SetValue(5);
        var tree          = updatedZipper.ToTree();

        Assert.Equal(t2, tree);
    }
Esempio n. 16
0
    public void Tree_from_deep_focus()
    {
        var zipper = Zipper <int> .FromTree(t1);

        Assert.That(zipper.Left().Right().ToTree(), Is.EqualTo(t1));
    }
Esempio n. 17
0
    public void Left_right_and_value()
    {
        var zipper = Zipper <int> .FromTree(t1);

        Assert.Equal(3, zipper.Left().Right().Value);
    }
Esempio n. 18
0
    public void Different_paths_to_same_zipper()
    {
        var zipper = Zipper <int> .FromTree(t1);

        Assert.Equal(zipper.Right().ToTree(), zipper.Left().Up().Right().ToTree());
    }
Esempio n. 19
0
    public void Left_right_and_value()
    {
        var zipper = Zipper <int> .FromTree(t1);

        Assert.That(zipper.Left().Right().Value, Is.EqualTo(3));
    }
Esempio n. 20
0
    public void Tree_from_deep_focus()
    {
        var zipper = Zipper <int> .FromTree(t1);

        Assert.Equal(t1, zipper.Left().Right().ToTree());
    }
Esempio n. 21
0
    public void Dead_end()
    {
        var zipper = Zipper <int> .FromTree(t1);

        Assert.Null(zipper.Left().Left());
    }