Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
39521ea
commit f5e75f1
Showing
2 changed files
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); |