Skip to content

Commit 62e78c5

Browse files
committed
Add RBTree function
1 parent c0eb351 commit 62e78c5

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/data-structures/red-black-tree.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,11 @@
2222

2323
global.Node = Node;
2424

25+
26+
function RBTree() {
27+
this._root = null;
28+
}
29+
30+
global.RBTree = RBTree;
31+
2532
}(typeof window === 'undefined' ? module.exports : window));

test/data-structures/red-black-tree.spec.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
'use strict';
22

33
var mod = require('../../src/data-structures/red-black-tree.js'),
4-
Node = mod.Node;
4+
Node = mod.Node,
5+
RBTree = mod.RBTree;
56

67
describe('Node', function () {
78
it('should be a constructor function', function () {
@@ -12,5 +13,17 @@ describe('Node', function () {
1213
expect(node.getKey()).toBe('key');
1314
expect(node.getValue()).toBe('value');
1415
expect(node.isRed()).toBeTruthy();
16+
node = new Node('key', 'value', undefined);
17+
//if we set isRed to falcy it should be turned to red
18+
expect(node.isRed()).toBe(false);
19+
});
20+
});
21+
22+
describe('RBTree', function () {
23+
it('should be a constructor function', function () {
24+
expect(typeof RBTree).toBe('function');
25+
});
26+
it('should initialize root to null by default', function () {
27+
expect(new RBTree()._root).toBeNull();
1528
});
1629
});

0 commit comments

Comments
 (0)