@@ -82,19 +82,26 @@ test('Test combining 3 ways 1->2->3', () => {
8282 expect ( result [ 0 ] . getElementsByTagName ( 'nd' ) . length ) . toBe ( 4 ) ;
8383} ) ;
8484
85- test ( 'Test combining 4 ways' , ( ) => {
85+ tests = [
86+ [ [
87+ '<way id="1"><nd ref="1"/><nd ref="2"/></way>' ,
88+ '<way id="2"><nd ref="3"/><nd ref="4"/></way>' ,
89+ '<way id="3"><nd ref="4"/><nd ref="1"/></way>' ,
90+ '<way id="4"><nd ref="2"/><nd ref="3"/></way>' ,
91+ ] , 1 , 4 ] ,
92+ ] ;
93+ test . each ( ) ( 'Test combining 4 ways' , ( ways , length , nodes ) => {
8694 var way1 = '<way id="1"><nd ref="1"/><nd ref="2"/></way>' ;
8795 var way2 = '<way id="2"><nd ref="3"/><nd ref="4"/></way>' ;
8896 var way3 = '<way id="3"><nd ref="4"/><nd ref="1"/></way>' ;
8997 var way4 = '<way id="4"><nd ref="2"/><nd ref="3"/></way>' ;
9098 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 ) ;
99+ xml = [ ] ;
100+ for ( const way on ways ) {
101+ xml . push ( parser . parseFromString ( way, 'text/xml' ) . getElementsByTagName ( 'way' ) [ 0 ] ) ;
102+ let result = BuildingShapeUtils . combineWays ( xml ) ;
103+ expect ( result . length ) . toBe ( length ) ;
97104 expect ( BuildingShapeUtils . isClosed ( result [ 0 ] ) ) ;
98105 expect ( BuildingShapeUtils . isSelfIntersecting ( result [ 0 ] ) ) . toBe ( false ) ;
99- expect ( result [ 0 ] . getElementsByTagName ( 'nd' ) . length ) . toBe ( 5 ) ;
106+ expect ( result [ 0 ] . getElementsByTagName ( 'nd' ) . length ) . toBe ( nodes ) ;
100107} ) ;
0 commit comments