| 
									
										
										
										
											2017-06-20 21:03:05 +08:00
										 |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const SortableSet = require("../lib/util/SortableSet"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describe("util/SortableSet", () => { | 
					
						
							|  |  |  | 	it("Can be constructed like a normal Set", () => { | 
					
						
							| 
									
										
										
										
											2017-06-20 21:51:25 +08:00
										 |  |  | 		const sortableSet = new SortableSet([1, 1, 1, 1, 1, 4, 5, 2], () => {}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 		expect(Array.from(sortableSet)).toEqual([1, 4, 5, 2]); | 
					
						
							| 
									
										
										
										
											2017-06-20 21:03:05 +08:00
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	it("Can sort its content", () => { | 
					
						
							| 
									
										
										
										
											2017-06-20 21:51:25 +08:00
										 |  |  | 		const sortableSet = new SortableSet( | 
					
						
							|  |  |  | 			[1, 1, 1, 6, 6, 1, 1, 4, 5, 2, 3, 8, 5, 7, 9, 0, 3, 1], | 
					
						
							|  |  |  | 			(a, b) => a - b | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2017-06-20 21:03:05 +08:00
										 |  |  | 		sortableSet.sort(); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 		expect(Array.from(sortableSet)).toEqual([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); | 
					
						
							| 
									
										
										
										
											2017-06-20 21:03:05 +08:00
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	it("Can sort by a specified function", () => { | 
					
						
							| 
									
										
										
										
											2017-06-20 21:51:25 +08:00
										 |  |  | 		const sortableSet = new SortableSet( | 
					
						
							|  |  |  | 			[1, 1, 1, 6, 6, 1, 1, 4, 5, 2, 3, 8, 5, 7, 9, 0, 3, 1], | 
					
						
							|  |  |  | 			(a, b) => a - b | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 		sortableSet.sortWith((a, b) => b - a); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 		expect(Array.from(sortableSet)).toEqual([9, 8, 7, 6, 5, 4, 3, 2, 1, 0]); | 
					
						
							| 
									
										
										
										
											2017-06-20 21:03:05 +08:00
										 |  |  | 	}); | 
					
						
							|  |  |  | }); |