Skip to content

Commit e91dabc

Browse files
committed
补充UT。review by chenmy
1 parent c1a6634 commit e91dabc

File tree

6 files changed

+1002
-0
lines changed

6 files changed

+1002
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
require('../../../../src/common/commontypes/geometry/LinearRing');
2+
describe('common_LinearRing Test', function () {
3+
var points = [new SuperMap.Geometry.Point(4933.319287022352, -3337.3849141502124),
4+
new SuperMap.Geometry.Point(4960.9674060199022, -3349.3316322355736),
5+
new SuperMap.Geometry.Point(5006.0235999418364, -3358.8890067038628),
6+
new SuperMap.Geometry.Point(5075.3145648369318, -3378.0037556404409),
7+
new SuperMap.Geometry.Point(5305.19551436013, -3376.9669111768926)];
8+
var linearRing = new SuperMap.Geometry.LinearRing(points);
9+
10+
it('constructor_test', function () {
11+
expect(linearRing).not.toBeNull();
12+
expect(linearRing.id).not.toBeNull();
13+
expect(linearRing.components.length).toEqual(6);
14+
expect(linearRing.components[0].id).toEqual(linearRing.components[5].id);
15+
for (var i = 0; i < linearRing.components.length; i++) {
16+
expect(linearRing.components[i].CLASS_NAME).toEqual("SuperMap.Geometry.Point");
17+
expect(linearRing.components[i].type).toEqual("NONE");
18+
}
19+
//获得当前几何对象区域大小,如果是沿顺时针方向的环则是正值,否则为负值
20+
var area = linearRing.getArea();
21+
expect(area).toEqual(-4929.534861156455);
22+
});
23+
24+
25+
// 添加一个点到几何图形数组中
26+
it('addComponent_test', function () {
27+
var addPoint = new SuperMap.Geometry.Point(5365.09521434033, -3324.5789112568386);
28+
var addSuccess = linearRing.addComponent(addPoint, 6);
29+
expect(addSuccess).toBeTruthy();
30+
expect(linearRing.components.length).toEqual(7);
31+
expect(linearRing.components[0].id).toEqual(linearRing.components[6].id);
32+
});
33+
34+
35+
//从几何组件中删除一个点。
36+
xit('removeComponent_test',function () {
37+
var removePoint = new SuperMap.Geometry.Point(5365.09521434033, -3324.5789112568386);
38+
var removedSuccess = linearRing.removeComponent(removePoint);
39+
expect(removedSuccess).toBeTruthy();
40+
expect(linearRing.components.length).toEqual(6);
41+
});
42+
43+
//返回几何图形的所有点的列表
44+
it('getVertices_test', function () {
45+
var pointList1 = linearRing.getVertices(true);
46+
var pointList2 = linearRing.getVertices(false);
47+
expect(pointList1.length).toEqual(0);
48+
expect(pointList2).not.toBeNull();
49+
expect(pointList2.length).toEqual(6);
50+
});
51+
52+
});

test/common/overlay/GraphSpec.js

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
require('../../../src/common/overlay/Graph');
2+
3+
describe('common_Graph', function () {
4+
var originalTimeout;
5+
beforeEach(function () {
6+
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
7+
jasmine.DEFAULT_TIMEOUT_INTERVAL = 50000;
8+
});
9+
afterEach(function () {
10+
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
11+
});
12+
13+
14+
it('constructor_test', function () {
15+
var geometry = new SuperMap.Geometry.Point(-115, 10);
16+
var attributes = {
17+
'SMID': 1,
18+
'CAPITAL_CH': "巴西利亚"
19+
};
20+
var style = {
21+
strokeColor: "#339933",
22+
strokeOpacity: 1,
23+
strokeWidth: 3,
24+
pointRadius: 6
25+
};
26+
var data = new SuperMap.Feature.Vector(geometry, attributes, style);
27+
var layer = "continent_T@World";
28+
var fields = ["SMID", "CAPITAL_CH"];// data 中的参与此图表生成的字段名称
29+
var setting = {
30+
width: 500,
31+
height: 300,
32+
codomain: [0, 300],
33+
XOffset: 10,
34+
YOffset: 10,
35+
dataViewBoxParameter: [5, 5, 5, 5],
36+
decimalNumber: 0
37+
};
38+
//专题要素地理位置。默认为 data 指代的地理要素 Bounds 中心。
39+
var lonlat = new SuperMap.LonLat(0, -20);
40+
var point = new SuperMap.Feature.ShapeParameters.Point;
41+
var options = {
42+
shapeFactory: point,
43+
shapeParameters: {
44+
clickable: true,
45+
hoverable: true
46+
},
47+
RelativeCoordinate: true,
48+
origonPoint: [0, 0],
49+
chartBox: [0, -300, 500, 0],
50+
width: 500,
51+
height: 300,
52+
XOffset: 10,
53+
YOffset: 10,
54+
DVBParameter: [5, 5, 5, 5],
55+
dataViewBox: [400, 250],
56+
DVBCodomain: [0, 300],
57+
DVBOrigonPoint: [50, -25],
58+
DVBWidth: 400,
59+
DVBHeight: 250,
60+
origonPointOffset: [0, 0],
61+
fields: ["SMID", "CAPITAL_CH"],
62+
};
63+
64+
var graph = new SuperMap.Feature.Theme.Graph(data, layer, fields, setting, options, lonlat);
65+
expect(graph).not.toBeNull();
66+
expect(graph.RelativeCoordinate).toBe(false);
67+
expect(graph.fields).not.toBeNull();
68+
expect(graph.fields.length).toEqual(2);
69+
expect(graph.fields[0]).toEqual("SMID");
70+
expect(graph.fields[1]).toEqual("CAPITAL_CH");
71+
expect(graph.lonlat.shapeFactory.CLASS_NAME).toEqual("SuperMap.Feature.ShapeParameters.Point");
72+
expect(graph.lonlat.shapeParameters.clickable).toBe(true);
73+
expect(graph.lonlat.shapeParameters.hoverable).toBe(true);
74+
expect(graph.lonlat.XOffset).toEqual(10);
75+
expect(graph.lonlat.RelativeCoordinate).toBe(true);
76+
expect(graph.setting).not.toBeNull();
77+
expect(graph.lonlat.DVBHeight).toEqual(options.DVBHeight);
78+
expect(graph.lonlat.DVBWidth).toEqual(options.DVBWidth);
79+
expect(graph.lonlat.DVBCodomain[0]).toEqual(0);
80+
expect(graph.lonlat.DVBCodomain[1]).toEqual(300);
81+
expect(graph.lonlat.DVBOrigonPoint[0]).toEqual(50);
82+
expect(graph.lonlat.DVBOrigonPoint[1]).toEqual(-25);
83+
for (var i = 0; i < graph.lonlat.DVBParameter.length; i++) {
84+
expect(graph.lonlat.DVBParameter[i]).toEqual(5);
85+
}
86+
for (var j = 0; i < graph.setting.dataViewBoxParameter.length; j++) {
87+
expect(graph.setting.dataViewBoxParameter[j]).toEqual(5);
88+
}
89+
expect(graph.setting.decimalNumber).toEqual(setting.decimalNumber);
90+
91+
graph.destroy();
92+
expect(graph.width).toBeNull();
93+
expect(graph.height).toBeNull();
94+
expect(graph.setting).toBeNull();
95+
expect(graph.shapeFactory).toBeNull();
96+
expect(graph.shapeParameters).toBeNull();
97+
expect(graph.chartBox).toBeNull();
98+
expect(graph.fields).toBeNull();
99+
expect(graph.dataValues).toBeNull();
100+
});
101+
});
102+

0 commit comments

Comments
 (0)