"""test itree structure"""
import pytest
from itree import ITree, ITreeError

def test_len():
    tree = ITree('dog')
    tree.root.append_child('cat')
    tree.root.append_child('mouse')
    assert(len(tree) == 3)

def test_root():
    tree = ITree('dog')
    assert(tree.root.data == 'dog')

def test_children():
    tree = ITree('dog')
    tree.root.append_child('cat')
    tree.root.append_child('mouse')
    assert([each.data for each in tree.root.children] == ['cat', 'mouse'])

def test_append_child():
    tree = ITree('dog')
    cat = tree.root.append_child('cat')
    mouse = tree.root.append_child('mouse')
    cat.append_child('kitten')
    mouse.append_child('mouseling')
    kitten2 = cat.append_child('kitten2')
    assert(kitten2.sibling_index == 1)

def test_indexing_children():
    tree = ITree('dog')
    tree.root.append_child('cat')
    tree.root.append_child('mouse')
    should_be_cat_node = tree[1][0]
    assert should_be_cat_node.data == 'cat'
    should_be_cat_node.append_child('kitten')
    should_be_kitten_node = tree[2][0]
    assert should_be_kitten_node.data == 'kitten'

def test_deleting_non_leaf():
    tree = ITree('dog')
    with pytest.raises(ITreeError) as e:
        tree.set_root('dog')
        tree.root.append_child('cat')
        tree.root.delete()
        assert(len(tree) == 1)

def test_deleting_leaf():
    tree = ITree('dog')
    tree.root.append_child('cat')
    should_be_cat_node = tree[1][0]
    should_be_cat_node.delete()
    assert(len(tree) == 1)
    with pytest.raises(IndexError) as e:
        cat = tree[1][0]

def test_deleting_root():
    tree = ITree('dog')
    tree[0][0].delete()
    assert(len(tree) == 0)
    assert(tree.height == 0)
    tree.set_root('b')
    assert(len(tree) == 1)

@@ -96,32 +96,56 @@
    tree = ITree(
+)%0A    tree.append_child(
 'dog')%0A    tree.
@@ -259,32 +259,56 @@
    tree = ITree(
+)%0A    tree.append_child(
 'dog')%0A    asser
@@ -365,32 +365,56 @@
    tree = ITree(
+)%0A    tree.append_child(
 'dog')%0A    tree.
@@ -584,32 +584,56 @@
    tree = ITree(
+)%0A    tree.append_child(
 'dog')%0A    cat =
@@ -895,32 +895,56 @@
    tree = ITree(
+)%0A    tree.append_child(
 'dog')%0A    tree.
@@ -1031,26 +1031,26 @@
 ode = tree%5B1
-%5D%5B
+, 
 0%5D%0A    asser
@@ -1164,18 +1164,18 @@
 = tree%5B2
-%5D%5B
+, 
 0%5D%0A    a
@@ -1259,32 +1259,56 @@
    tree = ITree(
+)%0A    tree.append_child(
 'dog')%0A    with 
@@ -1500,32 +1500,56 @@
    tree = ITree(
+)%0A    tree.append_child(
 'dog')%0A    tree.
@@ -1604,18 +1604,18 @@
 = tree%5B1
-%5D%5B
+, 
 0%5D%0A    s
@@ -1729,18 +1729,18 @@
 = tree%5B1
-%5D%5B
+, 
 0%5D%0A%0Adef 
@@ -1778,16 +1778,40 @@
 = ITree(
+)%0A    tree.append_child(
 'dog')%0A 
@@ -1823,10 +1823,10 @@
 ee%5B0
-%5D%5B
+, 
 0%5D.d

update tests to use empty constructor and [a, b] getter instead of [a][b]