Skip to content

Commit

Permalink
Release 0.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
lsbardel committed Jul 9, 2020
1 parent a323fd0 commit 7796561
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.5.0",
"version": "0.5.1",
"name": "d3-quant",
"description": "D3 library for quantitative analytics",
"homepage": "https://github.com/quantmind/d3-quant",
Expand Down
4 changes: 2 additions & 2 deletions src/btree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ class Node implements BtreeNode {
let nd: Node;

if (score > this.score) {
if (this.right) return this.right.insert(node);
if (this.right) return this.right.insert(node, callback);
else this.right = nd = new Node(score);
} else {
if (this.left) return this.left.insert(node);
if (this.left) return this.left.insert(node, callback);
else this.left = nd = new Node(score);
}
nd.red = true;
Expand Down
17 changes: 16 additions & 1 deletion tests/btree.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { binaryTree } from "../src";
import { range } from "d3-array";
import { binaryTree, BtreeNode } from "../src";

describe("Btree", () => {
test("test btree constructor", () => {
Expand Down Expand Up @@ -28,4 +29,18 @@ describe("Btree", () => {
const nodes = tree.nodes();
expect(nodes.length).toBe(3);
});

test("test btree insert callback", () => {
const tree = binaryTree();
range(50).forEach(() => {
const value = Math.random();
let nd: BtreeNode | undefined;
tree.insert(value, (n: BtreeNode) => {
nd = n;
});
expect(nd?.score).toBe(value);
});
tree.insert(0.5);
tree.insert(0.6);
});
});

0 comments on commit 7796561

Please sign in to comment.