Skip to content

Commit 37c5f57

Browse files
committed
补充UT,review by caoxinke.
1 parent 3a4dd50 commit 37c5f57

File tree

7 files changed

+795
-3
lines changed

7 files changed

+795
-3
lines changed
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
require('../../../../src/common/commontypes/geometry/LineString');
2+
3+
describe('common_LineString Test', function () {
4+
var roadLine;
5+
beforeEach(function () {
6+
var points = [new SuperMap.Geometry.Point(4933.319287022352, -3337.3849141502124),
7+
new SuperMap.Geometry.Point(4960.9674060199022, -3349.3316322355736),
8+
new SuperMap.Geometry.Point(5075.3145648369318, -3378.0037556404409),
9+
new SuperMap.Geometry.Point(5006.0235999418364, -3358.8890067038628),
10+
new SuperMap.Geometry.Point(5305.19551436013, -3376.9669111768926)];
11+
roadLine = new SuperMap.Geometry.LineString(points);
12+
});
13+
14+
it('constructor test', function () {
15+
expect(roadLine).not.toBeNull();
16+
expect(roadLine.components.length).toEqual(5);
17+
});
18+
19+
it('removeComponent test', function () {
20+
var removePoint = new SuperMap.Geometry.Point(4960.9674060199022, -3349.3316322355736);
21+
var removed = roadLine.removeComponent(removePoint);
22+
expect(removed).toBeTruthy();
23+
});
24+
25+
it('getSortedSegments test', function () {
26+
var segments = roadLine.getSortedSegments();
27+
expect(segments).not.toBeNull();
28+
expect(segments.length).toEqual(4);
29+
expect(segments[0].x1).toBeLessThan(segments[0].x2);
30+
expect(segments[1].x1).toBeLessThan(segments[1].x2);
31+
expect(segments[2].x1).toBeLessThan(segments[2].x2);
32+
expect(segments[3].x1).toBeLessThan(segments[3].x2);
33+
34+
});
35+
36+
it('getVertices test', function () {
37+
var vertices1, vertices2, vertices3;
38+
//nodes = true
39+
vertices1 = roadLine.getVertices(true);
40+
expect(vertices1).not.toBeNull();
41+
expect(vertices1.length).toEqual(2);
42+
//nodes = false
43+
vertices2 = roadLine.getVertices(false);
44+
expect(vertices2).not.toBeNull();
45+
expect(vertices2.length).toEqual(3);
46+
//nodes = ""
47+
vertices3 = roadLine.getVertices();
48+
expect(vertices3).not.toBeNull();
49+
expect(vertices3.length).toEqual(5);
50+
});
51+
52+
it('calculateCircle', function () {
53+
var points1 = [], points2 = [], points3 = [];
54+
//两点:
55+
points1.push(new SuperMap.Geometry.Point(-50, 30));
56+
points1.push(new SuperMap.Geometry.Point(-30, 50));
57+
var circle1 = SuperMap.Geometry.LineString.calculateCircle(points1);
58+
expect(circle1.length).toEqual(2);
59+
60+
//三点p1.x != p3.x:
61+
points2.push(new SuperMap.Geometry.Point(-50, 30));
62+
points2.push(new SuperMap.Geometry.Point(-30, 50));
63+
points2.push(new SuperMap.Geometry.Point(-20, 60));
64+
var circle2 = SuperMap.Geometry.LineString.calculateCircle(points2);
65+
expect(circle2.length).toEqual(3);
66+
67+
//三点p1.x == p3.x:
68+
points3.push(new SuperMap.Geometry.Point(-50, 30));
69+
points3.push(new SuperMap.Geometry.Point(-30, 50));
70+
points3.push(new SuperMap.Geometry.Point(-50, 60));
71+
var circle3 = SuperMap.Geometry.LineString.calculateCircle(points3);
72+
expect(circle3.length).toBeGreaterThan(3);
73+
74+
});
75+
76+
it('createLineEPS test', function () {
77+
var points = [];
78+
points.push(new SuperMap.Geometry.Point(-50, 30));
79+
points.push(new SuperMap.Geometry.Point(-30, 50, "LTypeArc"));
80+
points.push(new SuperMap.Geometry.Point(2, 60));
81+
points.push(new SuperMap.Geometry.Point(8, 20));
82+
83+
var lineEPS = SuperMap.Geometry.LineString.createLineEPS(points);
84+
expect(lineEPS.length).toEqual(74);
85+
86+
var points1 = [];
87+
points1.push(new SuperMap.Geometry.Point(-50, 30));
88+
points1.push(new SuperMap.Geometry.Point(-30, 50, "LTypeCurve"));
89+
points1.push(new SuperMap.Geometry.Point(2, 60));
90+
points1.push(new SuperMap.Geometry.Point(8, 20));
91+
92+
var lineEPS1 = SuperMap.Geometry.LineString.createLineEPS(points1);
93+
expect(lineEPS1.length).toEqual(4);
94+
});
95+
96+
it('createLineArc test', function () {
97+
var lineArc1, lineArc2, lineArc3;
98+
var list = [], i, len, points = [];
99+
points.push(new SuperMap.Geometry.Point(-50, 30));
100+
points.push(new SuperMap.Geometry.Point(-30, 50, "LTypeArc"));
101+
points.push(new SuperMap.Geometry.Point(2, 60));
102+
points.push(new SuperMap.Geometry.Point(8, 20));
103+
104+
//i = 0;
105+
i = 0; len = 2;
106+
lineArc1 = SuperMap.Geometry.LineString.createLineArc(list, i, len, points);
107+
expect(lineArc1[0].length).toEqual(2);
108+
//i = len -1;
109+
i = 1; len = 2;
110+
lineArc2 = SuperMap.Geometry.LineString.createLineArc(list, i, len, points);
111+
expect(lineArc2[0].length).toEqual(4);
112+
//i = "";
113+
i = 1; len = 4;
114+
lineArc3 = SuperMap.Geometry.LineString.createLineArc(list, i, len, points);
115+
expect(lineArc3[0].length).toEqual(76);
116+
});
117+
118+
it('addPointEPS test', function () {
119+
var pointEPS1, pointEPS2, pointEPS3;
120+
var type = "LTypeArc", i, len, points = [];
121+
points.push(new SuperMap.Geometry.Point(-50, 30));
122+
points.push(new SuperMap.Geometry.Point(-30, 50, "LTypeArc"));
123+
points.push(new SuperMap.Geometry.Point(2, 60));
124+
points.push(new SuperMap.Geometry.Point(8, 20));
125+
126+
//i = 0;
127+
i = 0; len = 2;
128+
pointEPS1 = SuperMap.Geometry.LineString.addPointEPS(points, i, len, type);
129+
expect(pointEPS1[0].length).toEqual(2);
130+
//i = len -1;
131+
i = 1; len = 2;
132+
pointEPS2 = SuperMap.Geometry.LineString.addPointEPS(points, i, len, type);
133+
expect(pointEPS2[0].length).toEqual(2);
134+
//i = "";
135+
i = 1; len = 4;
136+
pointEPS3 = SuperMap.Geometry.LineString.addPointEPS(points, i, len, type);
137+
expect(pointEPS3[0].length).toEqual(73);
138+
});
139+
});

test/karma.conf.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module.exports = function (config) {
2222
plugins: ['transform-class-properties','istanbul']
2323
}],
2424
require('browserify-css'),
25-
require('browserify-imgify')
25+
require('browserify-imgify'),
2626
]
2727
},
2828

@@ -58,7 +58,15 @@ module.exports = function (config) {
5858
'../src/openlayers/**/*.js',
5959
'../src/openlayers/overlay/**/*.js',
6060
/***测试文件***/
61-
'./test-main-openlayers.js'
61+
'./test-main-openlayers.js',
62+
63+
/***mapboxgl***/
64+
{pattern: '../node_modules/mapbox-gl/dist/mapbox-gl.css', include: false},
65+
'../src/mapboxgl/**/*.js',
66+
'../src/mapboxgl/overlay/**/*.js',
67+
/***测试文件***/
68+
'./test-main-mapboxgl.js',
69+
6270
],
6371

6472
// list of files to exclude 测试时排除的文件
@@ -92,6 +100,12 @@ module.exports = function (config) {
92100
'../src/openlayers/overlay/**/*.js': ['browserify'],
93101
'./openlayers/**/*Spec.js': ['browserify'],
94102
'./test-main-openlayers.js': ['browserify'],
103+
104+
'../node_modules/mapbox-gl/dist/mapbox-gl-dev.js': ['browserify'],
105+
'../src/mapboxgl/**/*.js': ['browserify'],
106+
'../src/mapboxgl/overlay/**/*.js': ['browserify'],
107+
'./mapboxgl/**/*Spec.js': ['browserify'],
108+
'./test-main-mapboxgl.js': ['browserify'],
95109
},
96110

97111
// test results reporter to use
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
var mapboxgl = require('mapbox-gl');
2+
var mapv = require('mapv');
3+
window.mapv = mapv;
4+
require('../../../src/mapboxgl/overlay/MapvLayer');
5+
6+
var url = GlobeParameter.ChinaURL + '/zxyTileImage.png?z={z}&x={x}&y={y}';
7+
describe('mapboxgl_MapVLayer', function () {
8+
var originalTimeout;
9+
var testDiv, map, mapvLayer;
10+
beforeAll(function () {
11+
testDiv = window.document.createElement("div");
12+
testDiv.setAttribute("id", "map");
13+
testDiv.style.styleFloat = "left";
14+
testDiv.style.marginLeft = "8px";
15+
testDiv.style.marginTop = "50px";
16+
testDiv.style.width = "500px";
17+
testDiv.style.height = "500px";
18+
window.document.body.appendChild(testDiv);
19+
20+
map = new mapboxgl.Map({
21+
container: 'map',
22+
style: {
23+
"version": 8,
24+
"sources": {
25+
"raster-tiles": {
26+
"type": "raster",
27+
"tiles": [url],
28+
"tileSize": 256,
29+
},
30+
},
31+
"layers": [{
32+
"id": "simple-tiles",
33+
"type": "raster",
34+
"source": "raster-tiles",
35+
"minzoom": 0,
36+
"maxzoom": 22
37+
}]
38+
},
39+
center: [112, 37.94],
40+
zoom: 3
41+
});
42+
43+
map.on('load', function () {
44+
var randomCount = 1000;
45+
var data = [];
46+
var citys = ["北京", "天津", "上海", "重庆", "石家庄", "太原", "呼和浩特", "哈尔滨", "长春", "沈阳", "济南", "南京", "合肥", "杭州", "南昌", "福州", "郑州", "武汉", "长沙", "广州", "南宁", "西安", "银川", "兰州", "西宁", "乌鲁木齐", "成都", "贵阳", "昆明", "拉萨", "海口"];
47+
// 构造数据
48+
while (randomCount--) {
49+
var cityCenter1 = mapv.utilCityCenter.getCenterByCityName(citys[parseInt(Math.random() * citys.length)]);
50+
var cityCenter2 = mapv.utilCityCenter.getCenterByCityName(citys[parseInt(Math.random() * citys.length)]);
51+
data.push({
52+
geometry: {
53+
type: 'LineString',
54+
coordinates: [[cityCenter1.lng - 1 + Math.random() * 1, cityCenter1.lat - 1 + Math.random() * 1],
55+
[cityCenter2.lng - 1 + Math.random() * 1, cityCenter2.lat - 1 + Math.random() * 1]
56+
]
57+
},
58+
count: 30 * Math.random()
59+
});
60+
}
61+
var dataSet = new mapv.DataSet(data);
62+
var options = {
63+
gradient: {
64+
0: 'blue',
65+
0.5: 'yellow',
66+
1: 'red'
67+
},
68+
lineWidth: 0.5,
69+
max: 30,
70+
draw: 'intensity'
71+
};
72+
mapvLayer = new mapboxgl.supermap.MapvLayer(map, dataSet, options);
73+
});
74+
75+
});
76+
beforeEach(function () {
77+
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
78+
jasmine.DEFAULT_TIMEOUT_INTERVAL = 50000;
79+
});
80+
81+
afterEach(function () {
82+
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
83+
});
84+
85+
afterAll(function () {
86+
document.body.removeChild(testDiv);
87+
mapv = null;
88+
});
89+
90+
it('constructor test', function (done) {
91+
setTimeout(function(){
92+
expect(mapvLayer).not.toBeNull();
93+
expect(mapvLayer.canvas).not.toBeNull();
94+
expect(mapvLayer.map).not.toBeNull();
95+
expect(mapvLayer.mapContainer).not.toBeNull();
96+
97+
//判断是否返回期望的maplayer
98+
expect(mapvLayer.renderer).not.toBeNull();
99+
expect(mapvLayer.renderer.context).toBe("2d");
100+
done();
101+
},6000);
102+
});
103+
104+
it('getTopLeft test', function () {
105+
var topLeft = mapvLayer.getTopLeft();
106+
expect(topLeft).not.toBeNull();
107+
});
108+
109+
it('show test', function () {
110+
var thisMapvlayer = mapvLayer.show();
111+
expect(thisMapvlayer).not.toBeNull();
112+
expect(thisMapvlayer.renderer.canvasLayer.canvas.style.display).toBe('block');
113+
});
114+
115+
it('hide test', function () {
116+
var thisMapvlayer = mapvLayer.hide();
117+
expect(thisMapvlayer).not.toBeNull();
118+
expect(thisMapvlayer.renderer.canvasLayer.canvas.style.display).toBe('none');
119+
});
120+
121+
});

0 commit comments

Comments
 (0)