Skip to content

Commit 2eb5d50

Browse files
authored
Combine multiple tests into one runner (#93)
1 parent a329e54 commit 2eb5d50

File tree

1 file changed

+53
-79
lines changed

1 file changed

+53
-79
lines changed

test/combine_ways.test.js

Lines changed: 53 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -14,87 +14,61 @@ import { BuildingShapeUtils } from '../src/extras/BuildingShapeUtils.js';
1414
// import { JSDOM } from 'jsdom';
1515

1616
test('Test no combining necessary. one open way', () => {
17-
var way1 = '<way id="1"><nd ref="1"/><nd ref="2"/><nd ref="3"/><nd ref="4"/></way>';
17+
var way = '<way id="1"><nd ref="1"/><nd ref="2"/><nd ref="3"/><nd ref="4"/></way>';
1818
let parser = new window.DOMParser();
19-
let xml1 = parser.parseFromString(way1, 'text/xml').getElementsByTagName('way')[0];
20-
let result = BuildingShapeUtils.combineWays([xml1]);
19+
let xml = parser.parseFromString(way, 'text/xml').getElementsByTagName('way')[0];
20+
let result = BuildingShapeUtils.combineWays([xml]);
2121
expect(result.length).toBe(0);
2222
});
2323

24-
test('Test combining 2 ways 1->2', () => {
25-
var way1 = '<way id="1"><nd ref="1"/><nd ref="2"/></way>';
26-
var way2 = '<way id="2"><nd ref="2"/><nd ref="3"/></way>';
27-
var way3 = '<way id="3"><nd ref="3"/><nd ref="1"/></way>';
28-
let parser = new window.DOMParser();
29-
let xml1 = parser.parseFromString(way1, 'text/xml').getElementsByTagName('way')[0];
30-
let xml2 = parser.parseFromString(way2, 'text/xml').getElementsByTagName('way')[0];
31-
let xml3 = parser.parseFromString(way3, 'text/xml').getElementsByTagName('way')[0];
32-
let result = BuildingShapeUtils.combineWays([xml1, xml2, xml3]);
33-
// Expect one closed way with 3 unique nodes.
34-
expect(result.length).toBe(1);
35-
expect(BuildingShapeUtils.isClosed(result[0])).toBe(true);
36-
expect(result[0].getElementsByTagName('nd').length).toBe(4);
37-
expect(BuildingShapeUtils.isSelfIntersecting(result[0])).toBe(false);
38-
});
39-
40-
test('Test combining 3 ways 2->1->3', () => {
41-
var way1 = '<way id="1"><nd ref="1"/><nd ref="2"/></way>';
42-
var way2 = '<way id="2"><nd ref="3"/><nd ref="1"/></way>';
43-
var way3 = '<way id="3"><nd ref="2"/><nd ref="3"/></way>';
44-
let parser = new window.DOMParser();
45-
let xml1 = parser.parseFromString(way1, 'text/xml').getElementsByTagName('way')[0];
46-
let xml2 = parser.parseFromString(way2, 'text/xml').getElementsByTagName('way')[0];
47-
let xml3 = parser.parseFromString(way3, 'text/xml').getElementsByTagName('way')[0];
48-
let result = BuildingShapeUtils.combineWays([xml1, xml2, xml3]);
49-
expect(result.length).toBe(1);
50-
expect(BuildingShapeUtils.isClosed(result[0])).toBe(true);
51-
expect(BuildingShapeUtils.isSelfIntersecting(result[0])).toBe(false);
52-
expect(result[0].getElementsByTagName('nd').length).toBe(4);
53-
});
54-
55-
test('Test combining 2 unaligned ways', () => {
56-
var way1 = '<way id="1"><nd ref="1"/><nd ref="2"/></way>';
57-
var way2 = '<way id="2"><nd ref="3"/><nd ref="2"/></way>';
58-
var way3 = '<way id="3"><nd ref="3"/><nd ref="1"/></way>';
59-
let parser = new window.DOMParser();
60-
let xml1 = parser.parseFromString(way1, 'text/xml').getElementsByTagName('way')[0];
61-
let xml2 = parser.parseFromString(way2, 'text/xml').getElementsByTagName('way')[0];
62-
let xml3 = parser.parseFromString(way3, 'text/xml').getElementsByTagName('way')[0];
63-
let result = BuildingShapeUtils.combineWays([xml1, xml2, xml3]);
64-
expect(result.length).toBe(1);
65-
expect(BuildingShapeUtils.isClosed(result[0])).toBe(true);
66-
expect(BuildingShapeUtils.isSelfIntersecting(result[0])).toBe(false);
67-
expect(result[0].getElementsByTagName('nd').length).toBe(4);
68-
});
69-
70-
test('Test combining 3 ways 1->2->3', () => {
71-
var way1 = '<way id="1"><nd ref="1"/><nd ref="2"/></way>';
72-
var way2 = '<way id="2"><nd ref="1"/><nd ref="3"/></way>';
73-
var way3 = '<way id="3"><nd ref="2"/><nd ref="3"/></way>';
74-
let parser = new window.DOMParser();
75-
let xml1 = parser.parseFromString(way1, 'text/xml').getElementsByTagName('way')[0];
76-
let xml2 = parser.parseFromString(way2, 'text/xml').getElementsByTagName('way')[0];
77-
let xml3 = parser.parseFromString(way3, 'text/xml').getElementsByTagName('way')[0];
78-
let result = BuildingShapeUtils.combineWays([xml1, xml2, xml3]);
79-
expect(result.length).toBe(1);
80-
expect(BuildingShapeUtils.isClosed(result[0])).toBe(true);
81-
expect(BuildingShapeUtils.isSelfIntersecting(result[0])).toBe(false);
82-
expect(result[0].getElementsByTagName('nd').length).toBe(4);
83-
});
84-
85-
test('Test combining 4 ways', () => {
86-
var way1 = '<way id="1"><nd ref="1"/><nd ref="2"/></way>';
87-
var way2 = '<way id="2"><nd ref="3"/><nd ref="4"/></way>';
88-
var way3 = '<way id="3"><nd ref="4"/><nd ref="1"/></way>';
89-
var way4 = '<way id="4"><nd ref="2"/><nd ref="3"/></way>';
90-
let parser = new window.DOMParser();
91-
let xml1 = parser.parseFromString(way1, 'text/xml').getElementsByTagName('way')[0];
92-
let xml2 = parser.parseFromString(way2, 'text/xml').getElementsByTagName('way')[0];
93-
let xml3 = parser.parseFromString(way3, 'text/xml').getElementsByTagName('way')[0];
94-
let xml4 = parser.parseFromString(way4, 'text/xml').getElementsByTagName('way')[0];
95-
let result = BuildingShapeUtils.combineWays([xml1, xml2, xml3, xml4]);
96-
expect(result.length).toBe(1);
97-
expect(BuildingShapeUtils.isClosed(result[0]));
98-
expect(BuildingShapeUtils.isSelfIntersecting(result[0])).toBe(false);
99-
expect(result[0].getElementsByTagName('nd').length).toBe(5);
24+
describe('Combine Ways', () => {
25+
test.each([
26+
[
27+
[
28+
'<way id="1"><nd ref="1"/><nd ref="2"/></way>',
29+
'<way id="2"><nd ref="2"/><nd ref="3"/></way>',
30+
'<way id="3"><nd ref="3"/><nd ref="1"/></way>',
31+
], 1, 4, 'Test combining 3 ways 1->2->3',
32+
],
33+
[
34+
[
35+
'<way id="1"><nd ref="1"/><nd ref="2"/></way>',
36+
'<way id="2"><nd ref="3"/><nd ref="1"/></way>',
37+
'<way id="3"><nd ref="2"/><nd ref="3"/></way>',
38+
], 1, 4, 'Test combining 3 ways 2->1->3',
39+
],
40+
[
41+
[
42+
'<way id="1"><nd ref="1"/><nd ref="2"/></way>',
43+
'<way id="2"><nd ref="3"/><nd ref="2"/></way>',
44+
'<way id="3"><nd ref="3"/><nd ref="1"/></way>',
45+
], 1, 4, 'Test combining tip to tip',
46+
],
47+
[
48+
[
49+
'<way id="1"><nd ref="1"/><nd ref="2"/></way>',
50+
'<way id="2"><nd ref="1"/><nd ref="3"/></way>',
51+
'<way id="3"><nd ref="2"/><nd ref="3"/></way>',
52+
], 1, 4, 'Test combining tail to tail',
53+
],
54+
[
55+
[
56+
'<way id="1"><nd ref="1"/><nd ref="2"/></way>',
57+
'<way id="2"><nd ref="3"/><nd ref="4"/></way>',
58+
'<way id="3"><nd ref="4"/><nd ref="1"/></way>',
59+
'<way id="4"><nd ref="2"/><nd ref="3"/></way>',
60+
], 1, 5, 'Test combining 4 ways',
61+
],
62+
])('${description}', (ways, length, nodes, description) => {
63+
let parser = new window.DOMParser();
64+
const xml = [];
65+
for (const way of ways){
66+
xml.push(parser.parseFromString(way, 'text/xml').getElementsByTagName('way')[0]);
67+
}
68+
let result = BuildingShapeUtils.combineWays(xml);
69+
expect(result.length).toBe(length);
70+
expect(BuildingShapeUtils.isClosed(result[0]));
71+
expect(BuildingShapeUtils.isSelfIntersecting(result[0])).toBe(false);
72+
expect(result[0].getElementsByTagName('nd').length).toBe(nodes);
73+
});
10074
});

0 commit comments

Comments
 (0)