|
| 1 | +require('../../../../src/common/commontypes/geometry/Collection'); |
| 2 | + |
| 3 | +describe('Collection', function () { |
| 4 | + it('clone, getComponentsString, removeComponents', function () { |
| 5 | + var point1 = new SuperMap.Geometry.Point(10, 20); |
| 6 | + var point2 = new SuperMap.Geometry.Point(30, 40); |
| 7 | + var collection = new SuperMap.Geometry.Collection([point1, point2]); |
| 8 | + var collection1 = collection.clone(); |
| 9 | + expect(collection.CLASS_NAME).toEqual(collection1.CLASS_NAME); |
| 10 | + expect(collection.components.length).toEqual(collection1.components.length); |
| 11 | + for (var i = 0; i < collection.components.length; i++) { |
| 12 | + expect(collection.components[i].CLASS_NAME).toEqual(collection1.components[i].CLASS_NAME); |
| 13 | + expect(collection.components[i].type).toEqual(collection1.components[i].type); |
| 14 | + expect(collection.components[i].x).toEqual(collection1.components[i].x); |
| 15 | + expect(collection.components[i].y).toEqual(collection1.components[i].y); |
| 16 | + } |
| 17 | + var componentsString = collection.getComponentsString(); |
| 18 | + expect(componentsString).toBe("10, 20,30, 40"); |
| 19 | + var isComponentsRemove = collection.removeComponents(point1, point2); |
| 20 | + expect(isComponentsRemove).toBe(true); |
| 21 | + //expect(collection.components.length).toEqual(0); //此处有BUG,只清除掉了components[0] |
| 22 | + collection.destroy(); |
| 23 | + collection1.destroy(); |
| 24 | + }); |
| 25 | + |
| 26 | + it('addComponent_index<components.length', function () { |
| 27 | + var point1 = new SuperMap.Geometry.Point(10, 20); |
| 28 | + var point2 = new SuperMap.Geometry.Point(30, 40); |
| 29 | + var collection = new SuperMap.Geometry.Collection([point1, point2]); |
| 30 | + expect(collection.components.length).toEqual(2); |
| 31 | + var point3 = new SuperMap.Geometry.Point(10, 10); |
| 32 | + collection.addComponent(point3, 0); |
| 33 | + expect(collection.components.length).toEqual(3); |
| 34 | + expect(collection.components[0].x).toEqual(10); |
| 35 | + expect(collection.components[0].y).toEqual(10); |
| 36 | + expect(collection.components[1].x).toEqual(10); |
| 37 | + expect(collection.components[1].y).toEqual(20); |
| 38 | + expect(collection.components[2].x).toEqual(30); |
| 39 | + expect(collection.components[2].y).toEqual(40); |
| 40 | + collection.destroy(); |
| 41 | + }); |
| 42 | + |
| 43 | + it('getArea', function () { |
| 44 | + var point1 = new SuperMap.Geometry.Point(1, 2); |
| 45 | + var point2 = new SuperMap.Geometry.Point(3, 2); |
| 46 | + var collection = new SuperMap.Geometry.Collection([point1, point2]); |
| 47 | + var area = collection.getArea(); |
| 48 | + expect(area).toEqual(0); |
| 49 | + collection.destroy(); |
| 50 | + }); |
| 51 | + |
| 52 | + it('equals', function () { |
| 53 | + //CLASS_NAME is not equal |
| 54 | + var point = new SuperMap.Geometry.Point(1, 2); |
| 55 | + var point1 = new SuperMap.Geometry.Point(2, 2); |
| 56 | + var collection = new SuperMap.Geometry.Collection([point]); |
| 57 | + var isEqual = collection.equals(point); |
| 58 | + expect(isEqual).toBeFalsy(); |
| 59 | + //length of components is not equal |
| 60 | + var collection1 = new SuperMap.Geometry.Collection([point, point1]); |
| 61 | + var isEqual1 = collection.equals(collection1); |
| 62 | + expect(isEqual1).toBeFalsy(); |
| 63 | + //components[i] is not equal |
| 64 | + var collection2 = new SuperMap.Geometry.Collection([point1]); |
| 65 | + var isEqual2 = collection.equals(collection2); |
| 66 | + expect(isEqual2).toBeFalsy(); |
| 67 | + //equal |
| 68 | + var collection3 = new SuperMap.Geometry.Collection([point]); |
| 69 | + var isEqual3 = collection.equals(collection3); |
| 70 | + expect(isEqual3).toBeTruthy(); |
| 71 | + collection.destroy(); |
| 72 | + collection1.destroy(); |
| 73 | + collection2.destroy(); |
| 74 | + collection3.destroy(); |
| 75 | + }); |
| 76 | + |
| 77 | + it('getVertices', function () { |
| 78 | + var point1 = new SuperMap.Geometry.Point(10, 0); |
| 79 | + var point2 = new SuperMap.Geometry.Point(30, 0); |
| 80 | + var collection = new SuperMap.Geometry.Collection([point1, point2]); |
| 81 | + var vertices = collection.getVertices(false); |
| 82 | + expect(vertices.length).toEqual(2); |
| 83 | + expect(collection.components[0].x).toEqual(10); |
| 84 | + expect(collection.components[0].y).toEqual(0); |
| 85 | + expect(collection.components[1].x).toEqual(30); |
| 86 | + expect(collection.components[1].y).toEqual(0); |
| 87 | + collection.destroy(); |
| 88 | + }) |
| 89 | +}); |
0 commit comments