@@ -17,28 +17,12 @@ import { floatAnswer } from '../../src/answer/ExpectedFloatAnswer.ts';
17
17
import { Scenario } from '../../src/jr/Scenario.ts' ;
18
18
import { EARTH_EQUATORIAL_CIRCUMFERENCE_METERS } from '../../src/jr/core/util/GeoUtils.ts' ;
19
19
20
- interface TrailingSemicolonOptions {
21
- readonly stripTrailingSemicolon : boolean ;
22
- }
23
-
24
- const geopointListValue = ( portedValue : string , options : TrailingSemicolonOptions ) => {
25
- if ( options . stripTrailingSemicolon ) {
26
- return portedValue . replace ( / ; $ / , '' ) ;
27
- }
28
-
29
- return portedValue ;
30
- } ;
31
-
32
20
const NINETY_DEGREES_ON_EQUATOR_KM = EARTH_EQUATORIAL_CIRCUMFERENCE_METERS / 4 ;
33
21
34
22
interface RelaxedPrecisionOptions {
35
23
readonly relaxAssertionPrecision : boolean ;
36
24
}
37
25
38
- interface CombinedParameterizationOptions
39
- extends RelaxedPrecisionOptions ,
40
- TrailingSemicolonOptions { }
41
-
42
26
/**
43
27
* **PORTING NOTES**
44
28
*
@@ -362,68 +346,55 @@ describe('Geoshape', () => {
362
346
/**
363
347
* **PORTING NOTES**
364
348
*
365
- * Fails on both of:
366
- *
367
- * - Directly ported precision. Same notes as previous test in first
368
- * geopoint distance test.
369
- *
370
- * - Trailing semicolon in `/data/polygon` value.
371
- *
372
- * Parameterized to demonstrate passage when accommodating both.
349
+ * Fails on directly ported precision. Same notes as previous test in
350
+ * first geopoint distance test. Parameterized to demonstrate passage when
351
+ * accommodated.
373
352
*/
374
- describe . each < CombinedParameterizationOptions > ( [
375
- { relaxAssertionPrecision : false , stripTrailingSemicolon : false } ,
376
- { relaxAssertionPrecision : true , stripTrailingSemicolon : true } ,
377
- ] ) (
378
- 'relax assertion precision: $relaxAssertionPrecision; strip triling semicolon: $stripTrailingSemicolon' ,
379
- ( { relaxAssertionPrecision, stripTrailingSemicolon } ) => {
380
- let testFn : typeof it | typeof it . fails ;
353
+ describe . each < RelaxedPrecisionOptions > ( [
354
+ { relaxAssertionPrecision : false } ,
355
+ { relaxAssertionPrecision : true } ,
356
+ ] ) ( 'relax assertion precision: $relaxAssertionPrecision' , ( { relaxAssertionPrecision } ) => {
357
+ let testFn : typeof it | typeof it . fails ;
381
358
382
- if ( relaxAssertionPrecision && stripTrailingSemicolon ) {
383
- testFn = it ;
384
- } else {
385
- testFn = it . fails ;
386
- }
359
+ if ( relaxAssertionPrecision ) {
360
+ testFn = it ;
361
+ } else {
362
+ testFn = it . fails ;
363
+ }
387
364
388
- testFn ( 'is computed for geoshape' , async ( ) => {
389
- const scenario = await Scenario . init (
390
- 'geoshape distance' ,
391
- html (
392
- head (
393
- title ( 'Geoshape distance' ) ,
394
- model (
395
- mainInstance (
396
- t (
397
- 'data id="geoshape-distance"' ,
398
- t (
399
- 'polygon' ,
400
- geopointListValue ( '0 1 0 0; 0 91 0 0; 0 1 0 0;' , {
401
- stripTrailingSemicolon,
402
- } )
403
- ) ,
404
- t ( 'distance' )
405
- )
406
- ) ,
407
- bind ( '/data/polygon' ) . type ( 'geoshape' ) ,
408
- bind ( '/data/distance' ) . type ( 'decimal' ) . calculate ( 'distance(/data/polygon)' )
409
- )
410
- ) ,
411
- body ( input ( '/data/polygon' ) )
412
- )
413
- ) ;
365
+ testFn ( 'is computed for geoshape' , async ( ) => {
366
+ const scenario = await Scenario . init (
367
+ 'geoshape distance' ,
368
+ html (
369
+ head (
370
+ title ( 'Geoshape distance' ) ,
371
+ model (
372
+ mainInstance (
373
+ t (
374
+ 'data id="geoshape-distance"' ,
375
+ t ( 'polygon' , '0 1 0 0; 0 91 0 0; 0 1 0 0;' ) ,
376
+ t ( 'distance' )
377
+ )
378
+ ) ,
379
+ bind ( '/data/polygon' ) . type ( 'geoshape' ) ,
380
+ bind ( '/data/distance' ) . type ( 'decimal' ) . calculate ( 'distance(/data/polygon)' )
381
+ )
382
+ ) ,
383
+ body ( input ( '/data/polygon' ) )
384
+ )
385
+ ) ;
414
386
415
- // assertThat(Double.parseDouble(scenario.answerOf("/data/distance").getDisplayText()),
416
- // closeTo(NINETY_DEGREES_ON_EQUATOR_KM * 2, 1e-7));
417
- // })
418
- expect ( scenario . answerOf ( '/data/distance' ) ) . toHaveAnswerCloseTo (
419
- expectedDistance (
420
- NINETY_DEGREES_ON_EQUATOR_KM * 2 ,
421
- relaxAssertionPrecision ? 0.0999999 : 1e-7
422
- )
423
- ) ;
424
- } ) ;
425
- }
426
- ) ;
387
+ // assertThat(Double.parseDouble(scenario.answerOf("/data/distance").getDisplayText()),
388
+ // closeTo(NINETY_DEGREES_ON_EQUATOR_KM * 2, 1e-7));
389
+ // })
390
+ expect ( scenario . answerOf ( '/data/distance' ) ) . toHaveAnswerCloseTo (
391
+ expectedDistance (
392
+ NINETY_DEGREES_ON_EQUATOR_KM * 2 ,
393
+ relaxAssertionPrecision ? 0.0999999 : 1e-7
394
+ )
395
+ ) ;
396
+ } ) ;
397
+ } ) ;
427
398
} ) ;
428
399
} ) ;
429
400
} ) ;
@@ -434,109 +405,78 @@ describe('Geotrace', () => {
434
405
/**
435
406
* **PORTING NOTES**
436
407
*
437
- * Fails on both of:
438
- *
439
- * - Directly ported precision. Same notes as previous test in first
440
- * geopoint distance test.
441
- *
442
- * - Trailing semicolon in `/data/line` value.
443
- *
444
- * Parameterized to demonstrate passage when accommodating both.
408
+ * Fails on directly ported precision. Same notes as previous test in
409
+ * first geopoint distance test. Parameterized to demonstrate passage with
410
+ * relaxed precision.
445
411
*/
446
- describe . each < CombinedParameterizationOptions > ( [
447
- { relaxAssertionPrecision : false , stripTrailingSemicolon : false } ,
448
- { relaxAssertionPrecision : true , stripTrailingSemicolon : true } ,
449
- ] ) (
450
- 'relax assertion precision: $relaxAssertionPrecision; strip triling semicolon: $stripTrailingSemicolon' ,
451
- ( { relaxAssertionPrecision, stripTrailingSemicolon } ) => {
452
- let testFn : typeof it | typeof it . fails ;
412
+ describe . each < RelaxedPrecisionOptions > ( [
413
+ { relaxAssertionPrecision : false } ,
414
+ { relaxAssertionPrecision : true } ,
415
+ ] ) ( 'relax assertion precision: $relaxAssertionPrecision' , ( { relaxAssertionPrecision } ) => {
416
+ let testFn : typeof it | typeof it . fails ;
453
417
454
- if ( relaxAssertionPrecision && stripTrailingSemicolon ) {
455
- testFn = it ;
456
- } else {
457
- testFn = it . fails ;
458
- }
418
+ if ( relaxAssertionPrecision ) {
419
+ testFn = it ;
420
+ } else {
421
+ testFn = it . fails ;
422
+ }
459
423
460
- testFn ( 'is computed for geotrace' , async ( ) => {
461
- const scenario = await Scenario . init (
462
- 'geotrace distance' ,
463
- html (
464
- head (
465
- title ( 'Geotrace distance' ) ,
466
- model (
467
- mainInstance (
468
- t (
469
- 'data id="geotrace-distance"' ,
470
- t (
471
- 'line' ,
472
- geopointListValue ( '0 1 0 0; 0 91 0 0;' , { stripTrailingSemicolon } )
473
- ) ,
474
- t ( 'distance' )
475
- )
476
- ) ,
477
- bind ( '/data/line' ) . type ( 'geotrace' ) ,
478
- bind ( '/data/distance' ) . type ( 'decimal' ) . calculate ( 'distance(/data/line)' )
479
- )
480
- ) ,
481
- body ( input ( '/data/line' ) )
482
- )
483
- ) ;
424
+ testFn ( 'is computed for geotrace' , async ( ) => {
425
+ const scenario = await Scenario . init (
426
+ 'geotrace distance' ,
427
+ html (
428
+ head (
429
+ title ( 'Geotrace distance' ) ,
430
+ model (
431
+ mainInstance (
432
+ t ( 'data id="geotrace-distance"' , t ( 'line' , '0 1 0 0; 0 91 0 0;' ) , t ( 'distance' ) )
433
+ ) ,
434
+ bind ( '/data/line' ) . type ( 'geotrace' ) ,
435
+ bind ( '/data/distance' ) . type ( 'decimal' ) . calculate ( 'distance(/data/line)' )
436
+ )
437
+ ) ,
438
+ body ( input ( '/data/line' ) )
439
+ )
440
+ ) ;
484
441
485
- // assertThat(Double.parseDouble(scenario.answerOf("/data/distance").getDisplayText()),
486
- // closeTo(NINETY_DEGREES_ON_EQUATOR_KM, 1e-7));
487
- expect ( scenario . answerOf ( '/data/distance' ) ) . toHaveAnswerCloseTo (
488
- expectedDistance (
489
- NINETY_DEGREES_ON_EQUATOR_KM ,
490
- relaxAssertionPrecision ? 0.0999999 : 1e-7
491
- )
492
- ) ;
493
- } ) ;
494
- }
495
- ) ;
442
+ // assertThat(Double.parseDouble(scenario.answerOf("/data/distance").getDisplayText()),
443
+ // closeTo(NINETY_DEGREES_ON_EQUATOR_KM, 1e-7));
444
+ expect ( scenario . answerOf ( '/data/distance' ) ) . toHaveAnswerCloseTo (
445
+ expectedDistance (
446
+ NINETY_DEGREES_ON_EQUATOR_KM ,
447
+ relaxAssertionPrecision ? 0.0999999 : 1e-7
448
+ )
449
+ ) ;
450
+ } ) ;
451
+ } ) ;
496
452
497
453
describe ( 'when [`geotrace`] trace has fewer than two points' , ( ) => {
498
- describe . each < TrailingSemicolonOptions > ( [
499
- { stripTrailingSemicolon : false } ,
500
- { stripTrailingSemicolon : true } ,
501
- ] ) ( 'strip trailing semicolons: $stripTrailingSemicolons' , ( { stripTrailingSemicolon } ) => {
502
- /**
503
- * **PORTING NOTES**
504
- *
505
- * - Direct port is currently expected to fail due to trailing
506
- * semicolon in `/data/line` value.
507
- *
508
- * - Parameterized alternate test stripping that trailing semicolon
509
- * also fails, producing {@link NaN} where the value is expected to
510
- * be zero. This is presumably a bug in the XPath `distance`
511
- * function's handling of this specific case (and would likely
512
- * affect Enketo as well, since the extant tests were ported from
513
- * ORXE).
514
- */
515
- it . fails ( 'is zero' , async ( ) => {
516
- const scenario = await Scenario . init (
517
- 'geotrace distance' ,
518
- html (
519
- head (
520
- title ( 'Geotrace distance' ) ,
521
- model (
522
- mainInstance (
523
- t (
524
- 'data id="geotrace-distance"' ,
525
- t ( 'line' , geopointListValue ( '0 1 0 0;' , { stripTrailingSemicolon } ) ) ,
526
- t ( 'distance' )
527
- )
528
- ) ,
529
- bind ( '/data/line' ) . type ( 'geotrace' ) ,
530
- bind ( '/data/distance' ) . type ( 'decimal' ) . calculate ( 'distance(/data/line)' )
531
- )
532
- ) ,
533
- body ( input ( '/data/line' ) )
534
- )
535
- ) ;
454
+ /**
455
+ * **PORTING NOTES**
456
+ *
457
+ * Fails due to another nuance of `distance` fallibility. Evidently
458
+ *
459
+ */
460
+ it . fails ( 'is zero' , async ( ) => {
461
+ const scenario = await Scenario . init (
462
+ 'geotrace distance' ,
463
+ html (
464
+ head (
465
+ title ( 'Geotrace distance' ) ,
466
+ model (
467
+ mainInstance (
468
+ t ( 'data id="geotrace-distance"' , t ( 'line' , '0 1 0 0;' ) , t ( 'distance' ) )
469
+ ) ,
470
+ bind ( '/data/line' ) . type ( 'geotrace' ) ,
471
+ bind ( '/data/distance' ) . type ( 'decimal' ) . calculate ( 'distance(/data/line)' )
472
+ )
473
+ ) ,
474
+ body ( input ( '/data/line' ) )
475
+ )
476
+ ) ;
536
477
537
- // assertThat(Double.parseDouble(scenario.answerOf("/data/distance").getDisplayText()), is(0.0));
538
- expect ( scenario . answerOf ( '/data/distance' ) ) . toEqualAnswer ( floatAnswer ( 0.0 ) ) ;
539
- } ) ;
478
+ // assertThat(Double.parseDouble(scenario.answerOf("/data/distance").getDisplayText()), is(0.0));
479
+ expect ( scenario . answerOf ( '/data/distance' ) ) . toEqualAnswer ( floatAnswer ( 0.0 ) ) ;
540
480
} ) ;
541
481
} ) ;
542
482
} ) ;
0 commit comments