"""
Test for Node class
"""

import unittest

from binarytree.node import Node


class NodeTestCase(unittest.TestCase):
    """
    This Case of tests checks the functionality of the Node implementation
    """

    def test_node_add_left_descendant(self):
        """
            (positive testing of add_left function)
        Create a Node.
        Add left descendant from a list of nodes with correct values.
        Test that the input node is equal to the left descendant of the Node
        """
        smaller_than_five = [Node(0), Node(1), Node(2), Node(3), Node(4)]
        for val in smaller_than_five:
            node = Node(5)
            node.add_left(val)
            self.assertEqual(val, node.left)

    def test_call_add_wrong_left_descendants_raised_error(self):
        """
            (negative testing of add_left function)
        Create a Node.
        Add left descendant from lists of incorrect values.
        Test that call of add_left function with incorrect inputs raises errors
        """
        greater_than_five = [Node(5), Node(6), Node(7), Node(1000), Node(100000000000)]
        for val in greater_than_five:
            node = Node(5)
            self.assertRaises(ValueError, node.add_left, val)
        not_nodes = [6, 7, 2.4, 'three', None, {}, []]
        for val in not_nodes:
            node = Node(5)
            self.assertRaises(TypeError, node.add_left, val)

    def test_node_add_multiple_left_descendants(self):
        """
            (end-to-end testing of add_left function)
        Create a Node with three left descendants.
        Test that the values are added correctly to the Node.
        """
        node = Node(10000000)
        node.add_left(Node(3))
        node.left.add_left(Node(2))
        node.left.left.add_left(Node(1))
        self.assertEqual(10000000, node.value)
        self.assertEqual(3, node.left.value)
        self.assertEqual(2, node.left.left.value)
        self.assertEqual(1, node.left.left.left.value)

    def test_node_add_right_descendant(self):
        """
            (positive testing of add_right function)
        Create a Node.
        Add right descendant from a list of correct nodes.
        Test that the input node is equal to the right descendant of the Node
        """
        greater_than_five = [Node(6), Node(7), Node(8), Node(9), Node(10000000)]
        for val in greater_than_five:
            node = Node(5)
            node.add_right(val)
            self.assertEqual(val, node.right)

    def test_call_add_wrong_right_descendants_raised_error(self):
        """
            (negative testing of add_right function)
        Create a Node.
        Add right descendant from lists of incorrect values.
        Test that call of add_right function with incorrect inputs raises errors
        """
        smaller_than_five = [Node(5), Node(4), Node(3), Node(2), Node(1), Node(0)]
        for val in smaller_than_five:
            node = Node(5)
            self.assertRaises(ValueError, node.add_right, val)
        not_nodes = [5, 100, 10.44465, 'twelve', None, {}, []]
        for val in not_nodes:
            node = Node(5)
            self.assertRaises(TypeError, node.add_right, val)

    def test_node_add_multiple_right_descendants(self):
        """
            (end-to-end testing of add_right function)
        Create a Node with three right descendants.
        Test that the values are added correctly to the Node.
        """
        node = Node(0)
        node.add_right(Node(1))
        node.right.add_right(Node(2))
        node.right.right.add_right(Node(3))
        self.assertEqual(0, node.value)
        self.assertEqual(1, node.right.value)
        self.assertEqual(2, node.right.right.value)
        self.assertEqual(3, node.right.right.right.value)

"""
Test for Node class
"""

import unittest

from binarytree.node import Node


class NodeTestCase(unittest.TestCase):
    """
    This Case of tests checks the functionality of the Node implementation
    """

    def test_node_add_left_descendant(self):
        """
            (positive testing of add_left function)
        Create a Node.
        Add left descendant from a list of nodes with correct values.
        Test that the input node is equal to the left descendant of the Node
        """
        smaller_than_five = [Node(0), Node(1), Node(2), Node(3), Node(4)]
        for val in smaller_than_five:
            node = Node(5)
            node.add_left(val)
            self.assertEqual(val, node.left)

    def test_call_add_wrong_left_descendants_raised_error(self):
        """
            (negative testing of add_left function)
        Create a Node.
        Add left descendant from lists of incorrect values.
        Test that call of add_left function with incorrect inputs raises errors
        """
        greater_than_five = [Node(5), Node(6), Node(7), Node(1000), Node(100000000000)]
        for val in greater_than_five:
            node = Node(5)
            self.assertRaises(ValueError, node.add_left, val)
        not_nodes = [6, 7, 2.4, 'three', None, {}, []]
        for val in not_nodes:
            node = Node(5)
            self.assertRaises(TypeError, node.add_left, val)

    def test_node_add_multiple_left_descendants(self):
        """
            (end-to-end testing of add_left function)
        Create a Node with three left descendants.
        Test that the values are added correctly to the Node.
        """
        node = Node(10000000)
        node.add_left(Node(3))
        node.left.add_left(Node(2))
        node.left.left.add_left(Node(1))
        self.assertEqual(10000000, node.value)
        self.assertEqual(3, node.left.value)
        self.assertEqual(2, node.left.left.value)
        self.assertEqual(1, node.left.left.left.value)

    def test_node_add_right_descendant(self):
        """
            (positive testing of add_right function)
        Create a Node.
        Add right descendant from a list of correct nodes.
        Test that the input node is equal to the right descendant of the Node
        """
        greater_than_five = [Node(6), Node(7), Node(8), Node(9), Node(10000000)]
        for val in greater_than_five:
            node = Node(5)
            node.add_right(val)
            self.assertEqual(val, node.right)

    def test_call_add_wrong_right_descendants_raised_error(self):
        """
            (negative testing of add_right function)
        Create a Node.
        Add right descendant from lists of incorrect values.
        Test that call of add_right function with incorrect inputs raises errors
        """
        smaller_than_five = [Node(5), Node(4), Node(3), Node(2), Node(1), Node(0)]
        for val in smaller_than_five:
            node = Node(5)
            self.assertRaises(ValueError, node.add_right, val)
        not_nodes = [5, 100, 10.44465, 'twelve', None, {}, []]
        for val in not_nodes:
            node = Node(5)
            self.assertRaises(TypeError, node.add_right, val)

    def test_node_add_multiple_right_descendants(self):
        """
            (end-to-end testing of add_right function)
        Create a Node with three right descendants.
        Test that the values are added correctly to the Node.
        """
        node = Node(0)
        node.add_right(Node(1))
        node.right.add_right(Node(2))
        node.right.right.add_right(Node(3))
        self.assertEqual(0, node.value)
        self.assertEqual(1, node.right.value)
        self.assertEqual(2, node.right.right.value)
        self.assertEqual(3, node.right.right.right.value)

Test for Node class This Case of tests checks the functionality of the Node implementation (positive testing of add_left function)         Create a Node.         Add left descendant from a list of nodes with correct values.         Test that the input node is equal to the left descendant of the Node (negative testing of add_left function)         Create a Node.         Add left descendant from lists of incorrect values.         Test that call of add_left function with incorrect inputs raises errors (end-to-end testing of add_left function)         Create a Node with three left descendants.         Test that the values are added correctly to the Node. (positive testing of add_right function)         Create a Node.         Add right descendant from a list of correct nodes.         Test that the input node is equal to the right descendant of the Node (negative testing of add_right function)         Create a Node.         Add right descendant from lists of incorrect values.         Test that call of add_right function with incorrect inputs raises errors (end-to-end testing of add_right function)         Create a Node with three right descendants.         Test that the values are added correctly to the Node.