| 
									
										
										
										
											2016-07-21 17:12:00 -07:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @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
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-24 13:57:51 -07:00
										 |  |  | import {Tree, TreeNode} from '../../src/utils/tree'; | 
					
						
							| 
									
										
										
										
											2016-05-20 13:56:52 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | describe('tree', () => { | 
					
						
							| 
									
										
										
										
											2016-06-21 11:49:42 -07:00
										 |  |  |   it('should return the root of the tree', () => { | 
					
						
							| 
									
										
										
										
											2016-05-20 13:56:52 -07:00
										 |  |  |     const t = new Tree<any>(new TreeNode<number>(1, [])); | 
					
						
							|  |  |  |     expect(t.root).toEqual(1); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-21 11:49:42 -07:00
										 |  |  |   it('should return the parent of a node', () => { | 
					
						
							| 
									
										
										
										
											2016-05-20 13:56:52 -07:00
										 |  |  |     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); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-07 20:05:05 -07:00
										 |  |  |   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); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-21 11:49:42 -07:00
										 |  |  |   it('should return the children of a node', () => { | 
					
						
							| 
									
										
										
										
											2016-05-20 13:56:52 -07:00
										 |  |  |     const t = new Tree<any>(new TreeNode<number>(1, [new TreeNode<number>(2, [])])); | 
					
						
							|  |  |  |     expect(t.children(1)).toEqual([2]); | 
					
						
							|  |  |  |     expect(t.children(2)).toEqual([]); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-21 11:49:42 -07:00
										 |  |  |   it('should return the first child of a node', () => { | 
					
						
							| 
									
										
										
										
											2016-05-20 13:56:52 -07:00
										 |  |  |     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); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-21 11:49:42 -07:00
										 |  |  |   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, [])])); | 
					
						
							| 
									
										
										
										
											2016-05-24 13:46:50 -07:00
										 |  |  |     expect(t.siblings(2)).toEqual([3]); | 
					
						
							|  |  |  |     expect(t.siblings(1)).toEqual([]); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-21 11:49:42 -07:00
										 |  |  |   it('should return the path to the root', () => { | 
					
						
							| 
									
										
										
										
											2016-05-20 13:56:52 -07:00
										 |  |  |     const t = new Tree<any>(new TreeNode<number>(1, [new TreeNode<number>(2, [])])); | 
					
						
							|  |  |  |     expect(t.pathFromRoot(2)).toEqual([1, 2]); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | }); |