refactor: move angular source to /packages rather than modules/@angular
This commit is contained in:
53
packages/router/test/utils/tree.spec.ts
Normal file
53
packages/router/test/utils/tree.spec.ts
Normal file
@ -0,0 +1,53 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {Tree, TreeNode} from '../../src/utils/tree';
|
||||
|
||||
describe('tree', () => {
|
||||
it('should return the root of the tree', () => {
|
||||
const t = new Tree<any>(new TreeNode<number>(1, []));
|
||||
expect(t.root).toEqual(1);
|
||||
});
|
||||
|
||||
it('should return the parent of a node', () => {
|
||||
const t = new Tree<any>(new TreeNode<number>(1, [new TreeNode<number>(2, [])]));
|
||||
expect(t.parent(1)).toEqual(null);
|
||||
expect(t.parent(2)).toEqual(1);
|
||||
});
|
||||
|
||||
it('should return the parent of a node (second child)', () => {
|
||||
const t = new Tree<any>(
|
||||
new TreeNode<number>(1, [new TreeNode<number>(2, []), new TreeNode<number>(3, [])]));
|
||||
expect(t.parent(1)).toEqual(null);
|
||||
expect(t.parent(3)).toEqual(1);
|
||||
});
|
||||
|
||||
it('should return the children of a node', () => {
|
||||
const t = new Tree<any>(new TreeNode<number>(1, [new TreeNode<number>(2, [])]));
|
||||
expect(t.children(1)).toEqual([2]);
|
||||
expect(t.children(2)).toEqual([]);
|
||||
});
|
||||
|
||||
it('should return the first child of a node', () => {
|
||||
const t = new Tree<any>(new TreeNode<number>(1, [new TreeNode<number>(2, [])]));
|
||||
expect(t.firstChild(1)).toEqual(2);
|
||||
expect(t.firstChild(2)).toEqual(null);
|
||||
});
|
||||
|
||||
it('should return the siblings of a node', () => {
|
||||
const t = new Tree<any>(
|
||||
new TreeNode<number>(1, [new TreeNode<number>(2, []), new TreeNode<number>(3, [])]));
|
||||
expect(t.siblings(2)).toEqual([3]);
|
||||
expect(t.siblings(1)).toEqual([]);
|
||||
});
|
||||
|
||||
it('should return the path to the root', () => {
|
||||
const t = new Tree<any>(new TreeNode<number>(1, [new TreeNode<number>(2, [])]));
|
||||
expect(t.pathFromRoot(2)).toEqual([1, 2]);
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user