refactor(router): remove dead code

This commit is contained in:
vsavkin 2016-08-02 13:41:02 -07:00 committed by Alex Rickabaugh
parent 29caa37943
commit 5fceb21549
2 changed files with 0 additions and 33 deletions

View File

@ -38,8 +38,6 @@ export class Tree<T> {
}
pathFromRoot(t: T): T[] { return findPath(t, this._root, []).map(s => s.value); }
contains(tree: Tree<T>): boolean { return contains(this._root, tree._root); }
}
function findNode<T>(expected: T, c: TreeNode<T>): TreeNode<T> {
@ -64,18 +62,6 @@ function findPath<T>(expected: T, c: TreeNode<T>, collected: TreeNode<T>[]): Tre
return [];
}
function contains<T>(tree: TreeNode<T>, subtree: TreeNode<T>): boolean {
if (tree.value !== subtree.value) return false;
for (let subtreeNode of subtree.children) {
const s = tree.children.filter(child => child.value === subtreeNode.value);
if (s.length === 0) return false;
if (!contains(s[0], subtreeNode)) return false;
}
return true;
}
export class TreeNode<T> {
constructor(public value: T, public children: TreeNode<T>[]) {}

View File

@ -43,23 +43,4 @@ describe('tree', () => {
const t = new Tree<any>(new TreeNode<number>(1, [new TreeNode<number>(2, [])]));
expect(t.pathFromRoot(2)).toEqual([1, 2]);
});
describe('contains', () => {
it('should work', () => {
const tree = new Tree<any>(
new TreeNode<number>(1, [new TreeNode<number>(2, []), new TreeNode<number>(3, [])]));
const subtree1 = new Tree<any>(new TreeNode<number>(1, []));
const subtree2 = new Tree<any>(new TreeNode<number>(1, [new TreeNode<number>(2, [])]));
const subtree3 = new Tree<any>(new TreeNode<number>(1, [new TreeNode<number>(3, [])]));
const notSubtree1 = new Tree<any>(new TreeNode<number>(1, [new TreeNode<number>(4, [])]));
const notSubtree2 = new Tree<any>(
new TreeNode<number>(1, [new TreeNode<number>(2, [new TreeNode<number>(4, [])])]));
expect(tree.contains(subtree1)).toEqual(true);
expect(tree.contains(subtree2)).toEqual(true);
expect(tree.contains(subtree3)).toEqual(true);
expect(tree.contains(notSubtree1)).toEqual(false);
expect(tree.contains(notSubtree2)).toEqual(false);
});
});
});