Skip to content

Commit

Permalink
bst
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenGrider committed Jun 10, 2020
1 parent 39521ea commit f5e75f1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
13 changes: 13 additions & 0 deletions exercises/bst/index.js
@@ -0,0 +1,13 @@
// --- Directions
// 1) Implement the Node class to create
// a binary search tree. The constructor
// should initialize values 'data', 'left',
// and 'right'.
// 2) Implement the 'insert' method for the
// Node class. Insert should accept an argument
// 'data', then create an insert a new node
// at the appropriate location in the tree.

class Node {}

module.exports = Node;
16 changes: 16 additions & 0 deletions exercises/bst/test.js
@@ -0,0 +1,16 @@
const Node = require('./index');

test('Node is a constructor', () => {
expect(typeof Node.prototype.constructor).toEqual('function');
});

test('Node can insert correctly', () => {
const node = new Node(10);
node.insert(5);
node.insert(15);
node.insert(17);

expect(node.left.data).toEqual(5);
expect(node.right.data).toEqual(15);
expect(node.right.right.data).toEqual(17);
});

0 comments on commit f5e75f1

Please sign in to comment.