refactor(router): remove dead code
This commit is contained in:
parent
29caa37943
commit
5fceb21549
|
@ -38,8 +38,6 @@ export class Tree<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pathFromRoot(t: T): T[] { return findPath(t, this._root, []).map(s => s.value); }
|
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> {
|
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 [];
|
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> {
|
export class TreeNode<T> {
|
||||||
constructor(public value: T, public children: TreeNode<T>[]) {}
|
constructor(public value: T, public children: TreeNode<T>[]) {}
|
||||||
|
|
||||||
|
|
|
@ -43,23 +43,4 @@ describe('tree', () => {
|
||||||
const t = new Tree<any>(new TreeNode<number>(1, [new TreeNode<number>(2, [])]));
|
const t = new Tree<any>(new TreeNode<number>(1, [new TreeNode<number>(2, [])]));
|
||||||
expect(t.pathFromRoot(2)).toEqual([1, 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);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue