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

precisionDetectionProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.6666
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\DmPrecisionDetector;
8
use DataValues\Geo\Parsers\DmCoordinateParser;
9
use PHPUnit\Framework\TestCase;
10
11
/**
12
 * @covers \DataValues\Geo\PackagePrivate\DmPrecisionDetector
13
 * @license GPL-2.0-or-later
14
 */
15
class DmPrecisionDetectorTest extends TestCase {
16
17
	/**
18
	 * @dataProvider precisionDetectionProvider
19
	 */
20
	public function testPrecisionDetection( string $coordinate, float $expectedPrecision ) {
21
		$latLong = ( new DmCoordinateParser() )->parse( $coordinate );
22
23
		$this->assertSame(
24
			$expectedPrecision,
25
			( new DmPrecisionDetector() )->detectPrecision( $latLong )->toFloat()
26
		);
27
	}
28
29
	public function precisionDetectionProvider() {
30
		yield [ '1°3\' 2°4\'', 1 / 60 ];
31
		yield [ '1°3\' 2°0\'', 1 / 60 ];
32
		yield [ '1°0\' 2°4\'', 1 / 60 ];
33
		yield [ '1°3.5\' 2°4.6\'', 1 / 3600 ];
34
		yield [ '1°3.57\' 2°4.68\'', 1 / 36000 ];
35
		yield [ '1°3.579\' 2°4.68\'', 1 / 360000 ];
36
		yield [ '1°3.0001\' 2°4.0001\'', 1 / 3600000 ];
37
		yield [ '1°3.00001\' 2°4.00001\'', 1 / 36000000 ];
38
		yield [ '1°3.000001\' 2°4.000001\'', 1 / 36000000 ];
39
		yield [ '1°3.0000001\' 2°4.0000001\'', 1 / 60 ];
40
		yield [ '1°3.5555555\' 2°4.5555555\'', 1 / 36000000 ];
41
42
		yield [ '-1°0\' 2°4\'', 1 / 60 ];
43
		yield [ '1°3.5\' -2°4.6\'', 1 / 3600 ];
44
		yield [ '-1°3.0000001\' -2°4.0000001\'', 1 / 60 ];
45
		yield [ '-1°3.5555555\' -2°4.5555555\'', 1 / 36000000 ];
46
	}
47
48
}
49