Esempio n. 1
0
    def test_guess_not_null(self):
        """
        pre: none
        post: confirms that a record may not be saved without a value for guess
        """
        n = Node(guess=None)

        with self.assertRaises(IntegrityError):
            n.save()
Esempio n. 2
0
def populate_data():
    """
    pre: none
    post: resets the database back to the initial state as follows:
        according the data in initial_data.json
    """
    print 'populating data '
    with open('trees/initial_data.json', 'r') as data_file:
        data = json.load(data_file)

    for record in data:

        print "record is", record

        node = Node(id=record['id'],
                    guess=record['guess'],
                    edge=record['edge'],
                    parent_id=record['parent_id'],
                    question=record['question']
                    )
        node.save()

    print ' -> Done!'
Esempio n. 3
0
    def insert(self, node, root: Node = None):
        if not self._root:
            self._root = node
            return

        if not root:
            root = self._root

        print(
            f'Inserting {node}, root is {root}. Root: {root.left} <> {root.right}'
        )
        if node.data >= root.data:
            if root.right is None:
                node.set_root(root)
                root.set_right(node)
            else:
                self.insert(node, root.right)
        else:
            if root.left is None:
                node.set_root(root)
                root.set_left(node)
            else:
                self.insert(node, root.left)