Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/treap.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var treap = (typeof exports === 'undefined') ? {} : exports;

// Create the node and randomly assign it a priority
var node = {key: key, priority: Math.random(), size: 1};
if (data) node.data = data;
if (data !== undefined) node.data = data;

// Perform the insertion of the node as for a normal BST
var parentNode = this._search(key);
Expand Down
28 changes: 27 additions & 1 deletion test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ describe('performing insertions', function() {
});
});


describe('performing lookups', function() {
var t = treap.create();

Expand Down Expand Up @@ -120,3 +119,30 @@ describe('splitting and merging', function() {
mergedTreap.find(50).key.should.equal(50)
});
});

describe('data', function() {
var t = treap.create();

it('inserts falsy data values', function() {
// https://developer.mozilla.org/en-US/docs/Glossary/Falsy
var falsyValues = [
false,
null,
undefined, // ok to include
0,
NaN,
'',
"",
``,
];
var found;
falsyValues.map(function(value, key) {
t.insert(key, value)
});

found = t.findRange(0, falsyValues.length);
found.map(function(node) {
return node.data;
}).should.eql(falsyValues);
});
})