<jupyter_start><jupyter_text>This notebook was prepared by [<NAME>](https://github.com/donnemartin). Source and license info is on [GitHub](https://github.com/donnemartin/interactive-coding-challenges).  Challenge Notebook  Problem: Find the in-order successor of a given node in a binary search tree.* [Constraints](Constraints)* [Test Cases](Test-Cases)* [Algorithm](Algorithm)* [Code](Code)* [Unit Test](Unit-Test)* [Solution Notebook](Solution-Notebook)  Constraints* If there is no successor, do we return None?    * Yes* If the input is None, should we throw an exception?    * Yes* Can we assume we already have a Node class that keeps track of parents?    * Yes* Can we assume this fits memory?    * Yes  Test Cases          _5_        /     \       3       8      / \    /   \     2   4  6    12    /        \   / \   1          7 10  15               /              9In: None  Out: ExceptionIn: 4     Out: 5In: 5     Out: 6In: 8     Out: 9In: 15    Out: None  AlgorithmRefer to the [Solution Notebook](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/graphs_trees/bst_successor/bst_successor_solution.ipynb).  If you are stuck and need a hint, the solution notebook's algorithm discussion might be a good place to start.  Code<jupyter_code>%run ../bst/bst.py
%load ../bst/bst.py
class BstSuccessor(object):

    def get_next(self, node):
        # TODO: Implement me
        pass<jupyter_output><empty_output><jupyter_text>Unit Test **The following unit test is expected to fail until you solve the challenge.**<jupyter_code># %load test_bst_successor.py
from nose.tools import assert_equal
from nose.tools import raises


class TestBstSuccessor(object):

    @raises(Exception)
    def test_bst_successor_empty(self):
        bst_successor = BstSuccessor()
        bst_successor.get_next(None)

    def test_bst_successor(self):
        nodes = {}
        node = Node(5)
        nodes[5] = node
        bst = Bst(nodes[5])
        nodes[3] = bst.insert(3)
        nodes[8] = bst.insert(8)
        nodes[2] = bst.insert(2)
        nodes[4] = bst.insert(4)
        nodes[6] = bst.insert(6)
        nodes[12] = bst.insert(12)
        nodes[1] = bst.insert(1)
        nodes[7] = bst.insert(7)
        nodes[10] = bst.insert(10)
        nodes[15] = bst.insert(15)
        nodes[9] = bst.insert(9)

        bst_successor = BstSuccessor()
        assert_equal(bst_successor.get_next(nodes[4]), 5)
        assert_equal(bst_successor.get_next(nodes[5]), 6)
        assert_equal(bst_successor.get_next(nodes[8]), 9)
        assert_equal(bst_successor.get_next(nodes[15]), None)

        print('Success: test_bst_successor')


def main():
    test = TestBstSuccessor()
    test.test_bst_successor()
    test.test_bst_successor_empty()


if __name__ == '__main__':
    main()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11462728551336146, 'fraction_numerical': 0.02180028129395218, 'mean_word_length': 2.9026063100137174, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '180797', 'license': 'Apache-2.0', 'n_tokens_mistral': 978, 'n_tokens_neox': 923, 'n_words': 234, 'path': 'graphs_trees/bst_successor/bst_successor_challenge.ipynb', 'repo_name': 'sophomore99/PythonInterective', 'size': '2850'}