| 
									
										
										
										
											2016-06-23 09:47:54 -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-06-08 16:38:52 -07:00
										 |  |  | import {ListWrapper, MapWrapper, StringMapWrapper} from '../src/collection'; | 
					
						
							| 
									
										
										
										
											2015-05-26 17:00:31 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | export function main() { | 
					
						
							|  |  |  |   describe('ListWrapper', () => { | 
					
						
							| 
									
										
										
										
											2015-08-13 11:19:37 -07:00
										 |  |  |     describe('maximum', () => { | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |       it('should return the maximal element', () => { | 
					
						
							|  |  |  |         expect(ListWrapper.maximum([1, 2, 3, 4], x => x)).toEqual(4); | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2015-08-13 11:19:37 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |       it('should ignore null values', () => { | 
					
						
							|  |  |  |         expect(ListWrapper.maximum([null, 2, 3, null], x => x)).toEqual(3); | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2015-08-13 11:19:37 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |       it('should use the provided function to determine maximum', () => { | 
					
						
							|  |  |  |         expect(ListWrapper.maximum([1, 2, 3, 4], x => -x)).toEqual(1); | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2015-08-13 11:19:37 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |       it('should return null for an empty list', | 
					
						
							|  |  |  |          () => { expect(ListWrapper.maximum([], x => x)).toEqual(null); }); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2015-08-19 11:26:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-26 17:00:31 -07:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe('StringMapWrapper', () => { | 
					
						
							|  |  |  |     describe('equals', () => { | 
					
						
							|  |  |  |       it('should return true when comparing empty maps', | 
					
						
							|  |  |  |          () => { expect(StringMapWrapper.equals({}, {})).toBe(true); }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should return true when comparing the same map', () => { | 
					
						
							| 
									
										
										
										
											2015-10-02 17:33:21 -07:00
										 |  |  |         var m1: {[key: string]: number} = {'a': 1, 'b': 2, 'c': 3}; | 
					
						
							| 
									
										
										
										
											2015-05-26 17:00:31 -07:00
										 |  |  |         expect(StringMapWrapper.equals(m1, m1)).toBe(true); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should return true when comparing different maps with the same keys and values', () => { | 
					
						
							| 
									
										
										
										
											2015-10-02 17:33:21 -07:00
										 |  |  |         var m1: {[key: string]: number} = {'a': 1, 'b': 2, 'c': 3}; | 
					
						
							|  |  |  |         var m2: {[key: string]: number} = {'a': 1, 'b': 2, 'c': 3}; | 
					
						
							| 
									
										
										
										
											2015-05-26 17:00:31 -07:00
										 |  |  |         expect(StringMapWrapper.equals(m1, m2)).toBe(true); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should return false when comparing maps with different numbers of keys', () => { | 
					
						
							| 
									
										
										
										
											2015-10-02 17:33:21 -07:00
										 |  |  |         var m1: {[key: string]: number} = {'a': 1, 'b': 2, 'c': 3}; | 
					
						
							|  |  |  |         var m2: {[key: string]: number} = {'a': 1, 'b': 2, 'c': 3, 'd': 4}; | 
					
						
							| 
									
										
										
										
											2015-05-26 17:00:31 -07:00
										 |  |  |         expect(StringMapWrapper.equals(m1, m2)).toBe(false); | 
					
						
							|  |  |  |         expect(StringMapWrapper.equals(m2, m1)).toBe(false); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should return false when comparing maps with different keys', () => { | 
					
						
							| 
									
										
										
										
											2015-10-02 17:33:21 -07:00
										 |  |  |         var m1: {[key: string]: number} = {'a': 1, 'b': 2, 'c': 3}; | 
					
						
							|  |  |  |         var m2: {[key: string]: number} = {'a': 1, 'b': 2, 'CC': 3}; | 
					
						
							| 
									
										
										
										
											2015-05-26 17:00:31 -07:00
										 |  |  |         expect(StringMapWrapper.equals(m1, m2)).toBe(false); | 
					
						
							|  |  |  |         expect(StringMapWrapper.equals(m2, m1)).toBe(false); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should return false when comparing maps with different values', () => { | 
					
						
							| 
									
										
										
										
											2015-10-02 17:33:21 -07:00
										 |  |  |         var m1: {[key: string]: number} = {'a': 1, 'b': 2, 'c': 3}; | 
					
						
							|  |  |  |         var m2: {[key: string]: number} = {'a': 1, 'b': 20, 'c': 3}; | 
					
						
							| 
									
										
										
										
											2015-05-26 17:00:31 -07:00
										 |  |  |         expect(StringMapWrapper.equals(m1, m2)).toBe(false); | 
					
						
							|  |  |  |         expect(StringMapWrapper.equals(m2, m1)).toBe(false); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2015-06-18 15:44:44 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     describe('MapWrapper', () => { | 
					
						
							|  |  |  |       it('should return a list of keys values', () => { | 
					
						
							|  |  |  |         var m = new Map(); | 
					
						
							|  |  |  |         m.set('a', 'b'); | 
					
						
							|  |  |  |         expect(MapWrapper.keys(m)).toEqual(['a']); | 
					
						
							|  |  |  |         expect(MapWrapper.values(m)).toEqual(['b']); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2015-05-26 17:00:31 -07:00
										 |  |  |   }); | 
					
						
							|  |  |  | } |