Completed
Pull Request — master (#168)
by Jeroen De
02:05
created

precisionDetectionProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace Tests\DataValues\Geo\PackagePrivate;
6
7
use DataValues\Geo\PackagePrivate\DmsPrecisionDetector;
8
use DataValues\Geo\Parsers\DmsCoordinateParser;
9
use PHPUnit\Framework\TestCase;
10
11
/**
12
 * @covers \DataValues\Geo\PackagePrivate\DmsPrecisionDetector
13
 * @license GPL-2.0-or-later
14
 */
15
class DmsPrecisionDetectorTest extends TestCase {
16
17
	/**
18
	 * @dataProvider precisionDetectionProvider
19
	 */
20
	public function testPrecisionDetection( string $coordinate, float $expectedPrecision ) {
21
		$latLong = ( new DmsCoordinateParser() )->parse( $coordinate );
22
23
		$this->assertSame(
24
			$expectedPrecision,
25
			( new DmsPrecisionDetector() )->detectPrecision( $latLong )->toFloat()
26
		);
27
	}
28
29
	public function precisionDetectionProvider() {
30
		yield [ '1°3\'5" 2°4\'6"', 1 / 3600 ];
31
		yield [ '1°3\'5" 2°0\'0"', 1 / 3600 ];
32
		yield [ '1°0\'0" 2°4\'6"', 1 / 3600 ];
33
		yield [ '1°3\'0" 2°4\'0"', 1 / 3600 ];
34
		yield [ '1°3\'5.7" 2°4\'6.8"', 1 / 36000 ];
35
		yield [ '1°3\'5.79" 2°4\'6.8"', 1 / 360000 ];
36
		yield [ '1°3\'5.001" 2°4\'6.001"', 1 / 3600000 ];
37
		yield [ '1°3\'5.0001" 2°4\'6.0001"', 1 / 36000000 ];
38
		yield [ '1°3\'5.00001" 2°4\'6.00001"', 1 / 3600 ];
39
		yield [ '1°3\'5.55555" 2°4\'6.55555"', 1 / 36000000 ];
40
41
		yield [ '-1°3\'5" -2°4\'6"', 1 / 3600 ];
42
		yield [ '-1°3\'5.00001" -2°4\'6.00001"', 1 / 3600 ];
43
		yield [ '1°3\'5.55555" -2°4\'6.55555"', 1 / 36000000 ];
44
	}
45
46
}
47