1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare( strict_types = 1 ); |
4
|
|
|
|
5
|
|
|
namespace Tests\DataValues\Geo\PackagePrivate; |
6
|
|
|
|
7
|
|
|
use DataValues\Geo\PackagePrivate\FloatPrecisionDetector; |
8
|
|
|
use DataValues\Geo\Parsers\DdCoordinateParser; |
9
|
|
|
use DataValues\Geo\Values\LatLongValue; |
10
|
|
|
use PHPUnit\Framework\TestCase; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @covers \DataValues\Geo\PackagePrivate\FloatPrecisionDetector |
14
|
|
|
* @license GPL-2.0-or-later |
15
|
|
|
*/ |
16
|
|
|
class FloatPrecisionDetectorTest extends TestCase { |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @dataProvider precisionDetectionProvider |
20
|
|
|
*/ |
21
|
|
|
public function testPrecisionDetection( LatLongValue $coordinate, float $expectedPrecision ) { |
22
|
|
|
$this->assertSame( |
23
|
|
|
$expectedPrecision, |
24
|
|
|
( new FloatPrecisionDetector() )->detectPrecision( $coordinate )->toFloat() |
25
|
|
|
); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function precisionDetectionProvider() { |
29
|
|
|
yield [ new LatLongValue( 10, 20 ), 1 ]; |
30
|
|
|
yield [ new LatLongValue( 1, 2 ), 1 ]; |
31
|
|
|
yield [ new LatLongValue( 1.3, 2.4 ), 0.1 ]; |
32
|
|
|
yield [ new LatLongValue( 1.3, 20 ), 0.1 ]; |
33
|
|
|
yield [ new LatLongValue( 10, 2.4 ), 0.1 ]; |
34
|
|
|
|
35
|
|
|
yield [ new LatLongValue( 1.35, 2.46 ), 0.01 ]; |
36
|
|
|
yield [ new LatLongValue( 1.357, 2.468 ), 0.001 ]; |
37
|
|
|
yield [ new LatLongValue( 1.3579, 2.468 ), 0.0001 ]; |
38
|
|
|
yield [ new LatLongValue( 1.00001, 2.00001 ), 0.00001 ]; |
39
|
|
|
yield [ new LatLongValue( 1.000001, 2.000001 ), 0.000001 ]; |
40
|
|
|
yield [ new LatLongValue( 1.0000001, 2.0000001 ), 0.0000001 ]; |
41
|
|
|
yield [ new LatLongValue( 1.00000001, 2.00000001 ), 0.00000001 ]; |
42
|
|
|
|
43
|
|
|
yield [ new LatLongValue( 1.000000001, 2.000000001 ), 1 ]; |
44
|
|
|
yield [ new LatLongValue( 1.555555555, 2.555555555 ), 0.00000001 ]; |
45
|
|
|
|
46
|
|
|
yield [ new LatLongValue( -10, -20 ), 1 ]; |
47
|
|
|
yield [ new LatLongValue( -10, -2.4 ), 0.1 ]; |
48
|
|
|
yield [ new LatLongValue( -1.00000001, -2.00000001 ), 0.00000001 ]; |
49
|
|
|
yield [ new LatLongValue( -1.000000001, -2.000000001 ), 1 ]; |
50
|
|
|
yield [ new LatLongValue( -1.555555555, -2.555555555 ), 0.00000001 ]; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @dataProvider decimalDegreeProvider |
55
|
|
|
*/ |
56
|
|
|
public function testDecimalDegreePrecisionDetection( string $coordinate, float $expectedPrecision ) { |
57
|
|
|
$latLong = ( new DdCoordinateParser() )->parse( $coordinate ); |
58
|
|
|
|
59
|
|
|
$this->assertSame( |
60
|
|
|
$expectedPrecision, |
61
|
|
|
( new FloatPrecisionDetector() )->detectPrecision( $latLong )->toFloat() |
62
|
|
|
); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function decimalDegreeProvider() { |
66
|
|
|
yield [ '10° 20°', 1 ]; |
67
|
|
|
yield [ '1° 2°', 1 ]; |
68
|
|
|
yield [ '1.3° 2.4°', 0.1 ]; |
69
|
|
|
yield [ '1.3° 20°', 0.1 ]; |
70
|
|
|
yield [ '10° 2.4°', 0.1 ]; |
71
|
|
|
yield [ '1.35° 2.46°', 0.01 ]; |
72
|
|
|
yield [ '1.357° 2.468°', 0.001 ]; |
73
|
|
|
yield [ '1.3579° 2.468°', 0.0001 ]; |
74
|
|
|
yield [ '1.00001° 2.00001°', 0.00001 ]; |
75
|
|
|
yield [ '1.000001° 2.000001°', 0.000001 ]; |
76
|
|
|
yield [ '1.0000001° 2.0000001°', 0.0000001 ]; |
77
|
|
|
yield [ '1.00000001° 2.00000001°', 0.00000001 ]; |
78
|
|
|
yield [ '1.000000001° 2.000000001°', 1 ]; |
79
|
|
|
yield [ '1.555555555° 2.555555555°', 0.00000001 ]; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
} |
83
|
|
|
|