@@ -274,25 +274,52 @@ describe('Geopoint', () => {
274
274
describe ( 'Geoshape' , ( ) => {
275
275
describe ( 'GeoAreaTest.java' , ( ) => {
276
276
describe ( 'area' , ( ) => {
277
- describe . each < TrailingSemicolonOptions > ( [
278
- { stripTrailingSemicolon : false } ,
279
- { stripTrailingSemicolon : true } ,
280
- ] ) ( 'string trailing semicolon: $stripTrailingSemicolon' , ( { stripTrailingSemicolon } ) => {
281
- let testFn : typeof it | typeof it . fails ;
277
+ /**
278
+ * **PORTING NOTES**
279
+ *
280
+ * Previously failed due to trailing semicolon. Addressed while extracting
281
+ * XPath logic for decoding serialized geopoint lists.
282
+ */
283
+ it ( 'is computed for geoshape' , async ( ) => {
284
+ const scenario = await Scenario . init (
285
+ 'geoshape area' ,
286
+ html (
287
+ head (
288
+ title ( 'Geoshape area' ) ,
289
+ model (
290
+ mainInstance (
291
+ t (
292
+ 'data id="geoshape-area"' ,
293
+ t (
294
+ 'polygon' ,
295
+ '38.253094215699576 21.756382658677467 0 0; 38.25021274773806 21.756382658677467 0 0; 38.25007793942195 21.763892843919166 0 0; 38.25290886154963 21.763935759263404 0 0; 38.25146813817506 21.758421137528785 0 0;'
296
+ ) ,
297
+ t ( 'area' )
298
+ )
299
+ ) ,
300
+ bind ( '/data/polygon' ) . type ( 'geoshape' ) ,
301
+ bind ( '/data/area' ) . type ( 'decimal' ) . calculate ( 'area(/data/polygon)' )
302
+ )
303
+ ) ,
304
+ body ( input ( '/data/polygon' ) )
305
+ )
306
+ ) ;
282
307
283
- if ( stripTrailingSemicolon ) {
284
- testFn = it ;
285
- } else {
286
- testFn = it . fails ;
287
- }
308
+ // JR:
309
+ //
310
+ // http://www.mapdevelopers.com/area_finder.php?&points=%5B%5B38.253094215699576%2C21.756382658677467%5D%2C%5B38.25021274773806%2C21.756382658677467%5D%2C%5B38.25007793942195%2C21.763892843919166%5D%2C%5B38.25290886154963%2C21.763935759263404%5D%2C%5B38.25146813817506%2C21.758421137528785%5D%5D
311
+ // assertThat(Double.parseDouble(scenario.answerOf("/data/area").getDisplayText()),
312
+ // closeTo(151452, 0.5));
313
+ expect ( scenario . answerOf ( '/data/area' ) ) . toHaveAnswerCloseTo ( expectedArea ( 151452 , 0.5 ) ) ;
314
+ } ) ;
288
315
316
+ describe ( 'when shape has fewer than three points' , ( ) => {
289
317
/**
290
318
* **PORTING NOTES**
291
319
*
292
- * - Direct port fails due to trailing semicolon in `/data/polygon` value,
293
- * as demonstrated by parameterized alternate test.
320
+ * Previously failed with trailing semicolon, and lack of logic to enforce a minimum number of points. Both addressed while extracting XPath logic for decoding serializeed geopoint lists.
294
321
*/
295
- testFn ( 'is computed for geoshape ' , async ( ) => {
322
+ it ( 'is zero ' , async ( ) => {
296
323
const scenario = await Scenario . init (
297
324
'geoshape area' ,
298
325
html (
@@ -302,87 +329,29 @@ describe('Geoshape', () => {
302
329
mainInstance (
303
330
t (
304
331
'data id="geoshape-area"' ,
332
+ t ( 'polygon1' , '38.253094215699576 21.756382658677467 0 0;' ) ,
305
333
t (
306
- 'polygon' ,
307
- geopointListValue (
308
- '38.253094215699576 21.756382658677467 0 0; 38.25021274773806 21.756382658677467 0 0; 38.25007793942195 21.763892843919166 0 0; 38.25290886154963 21.763935759263404 0 0; 38.25146813817506 21.758421137528785 0 0;' ,
309
- { stripTrailingSemicolon }
310
- )
334
+ 'polygon2' ,
335
+ '38.253094215699576 21.756382658677467 0 0; 38.25021274773806 21.756382658677467 0 0;'
311
336
) ,
312
- t ( 'area' )
337
+ t ( 'area1' ) ,
338
+ t ( 'area2' )
313
339
)
314
340
) ,
315
- bind ( '/data/polygon' ) . type ( 'geoshape' ) ,
316
- bind ( '/data/area' ) . type ( 'decimal' ) . calculate ( 'area(/data/polygon)' )
341
+ bind ( '/data/polygon1' ) . type ( 'geoshape' ) ,
342
+ bind ( '/data/polygon2' ) . type ( 'geoshape' ) ,
343
+ bind ( '/data/area1' ) . type ( 'decimal' ) . calculate ( 'area(/data/polygon1)' ) ,
344
+ bind ( '/data/area2' ) . type ( 'decimal' ) . calculate ( 'area(/data/polygon2)' )
317
345
)
318
346
) ,
319
- body ( input ( '/data/polygon ' ) )
347
+ body ( input ( '/data/polygon1' ) , input ( '/data/polygon2 ') )
320
348
)
321
349
) ;
322
350
323
- // JR:
324
- //
325
- // http://www.mapdevelopers.com/area_finder.php?&points=%5B%5B38.253094215699576%2C21.756382658677467%5D%2C%5B38.25021274773806%2C21.756382658677467%5D%2C%5B38.25007793942195%2C21.763892843919166%5D%2C%5B38.25290886154963%2C21.763935759263404%5D%2C%5B38.25146813817506%2C21.758421137528785%5D%5D
326
- // assertThat(Double.parseDouble(scenario.answerOf("/data/area").getDisplayText()),
327
- // closeTo(151452, 0.5));
328
- expect ( scenario . answerOf ( '/data/area' ) ) . toHaveAnswerCloseTo ( expectedArea ( 151452 , 0.5 ) ) ;
329
- } ) ;
330
-
331
- describe ( 'when shape has fewer than three points' , ( ) => {
332
- /**
333
- * **PORTING NOTES**
334
- *
335
- * - Direct port is currently expected to fail due to trailing
336
- * semicolons in `/data/polygon1` and `/data/polygon2` values.
337
- *
338
- * - Parameterized alternate test stripping those trailing semicolons
339
- * also fails, producing {@link NaN} where the value is expected to be
340
- * zero. This is presumably a bug in the XPath `area` function's
341
- * handling of this specific case (and would likely affect Enketo as
342
- * well, since the extant tests were ported from ORXE).
343
- */
344
- it . fails ( 'is zero' , async ( ) => {
345
- const scenario = await Scenario . init (
346
- 'geoshape area' ,
347
- html (
348
- head (
349
- title ( 'Geoshape area' ) ,
350
- model (
351
- mainInstance (
352
- t (
353
- 'data id="geoshape-area"' ,
354
- t (
355
- 'polygon1' ,
356
- geopointListValue ( '38.253094215699576 21.756382658677467 0 0;' , {
357
- stripTrailingSemicolon,
358
- } )
359
- ) ,
360
- t (
361
- 'polygon2' ,
362
- geopointListValue (
363
- '38.253094215699576 21.756382658677467 0 0; 38.25021274773806 21.756382658677467 0 0;' ,
364
- { stripTrailingSemicolon }
365
- )
366
- ) ,
367
- t ( 'area1' ) ,
368
- t ( 'area2' )
369
- )
370
- ) ,
371
- bind ( '/data/polygon1' ) . type ( 'geoshape' ) ,
372
- bind ( '/data/polygon2' ) . type ( 'geoshape' ) ,
373
- bind ( '/data/area1' ) . type ( 'decimal' ) . calculate ( 'area(/data/polygon1)' ) ,
374
- bind ( '/data/area2' ) . type ( 'decimal' ) . calculate ( 'area(/data/polygon2)' )
375
- )
376
- ) ,
377
- body ( input ( '/data/polygon1' ) , input ( '/data/polygon2' ) )
378
- )
379
- ) ;
380
-
381
- // assertThat(Double.parseDouble(scenario.answerOf("/data/area1").getDisplayText()), is(0.0));
382
- expect ( scenario . answerOf ( '/data/area1' ) ) . toEqualAnswer ( floatAnswer ( 0.0 ) ) ;
383
- // assertThat(Double.parseDouble(scenario.answerOf("/data/area2").getDisplayText()), is(0.0));
384
- expect ( scenario . answerOf ( '/data/area2' ) ) . toEqualAnswer ( floatAnswer ( 0.0 ) ) ;
385
- } ) ;
351
+ // assertThat(Double.parseDouble(scenario.answerOf("/data/area1").getDisplayText()), is(0.0));
352
+ expect ( scenario . answerOf ( '/data/area1' ) ) . toEqualAnswer ( floatAnswer ( 0.0 ) ) ;
353
+ // assertThat(Double.parseDouble(scenario.answerOf("/data/area2").getDisplayText()), is(0.0));
354
+ expect ( scenario . answerOf ( '/data/area2' ) ) . toEqualAnswer ( floatAnswer ( 0.0 ) ) ;
386
355
} ) ;
387
356
} ) ;
388
357
} ) ;
0 commit comments