r69388 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r69387‎ | r69388 | r69389 >
Date:15:43, 15 July 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
unit tests
Modified paths:
  • /trunk/extensions/Maps/test/MapsCoordinateParserTest.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Maps/test/MapsCoordinateParserTest.php
@@ -11,6 +11,48 @@
1212 */
1313 class MapsCoordinateParserTest extends PHPUnit_Framework_TestCase {
1414
 15+ public static $coordinates = array(
 16+ 'float' => array(
 17+ '55.7557860 N, 37.6176330 W',
 18+ '55.7557860, -37.6176330',
 19+ '55 S, 37.6176330 W',
 20+ '-55, -37.6176330',
 21+ '5.5S,37W ',
 22+ '-5.5,-37 '
 23+ ),
 24+ 'dd' => array(
 25+ '55.7557860� N, 37.6176330� W',
 26+ '55.7557860�, -37.6176330�',
 27+ '55� S, 37.6176330 � W',
 28+ '-55�, -37.6176330 �',
 29+ '5.5�S,37�W ',
 30+ '-5.5�,-37� '
 31+ ),
 32+ 'dm' => array(
 33+ "55� 45.34716' N, 37� 37.05798' W",
 34+ "55� 45.34716', -37� 37.05798'",
 35+ "55� S, 37� 37.05798'W",
 36+ "-55�, 37� -37.05798'",
 37+ "55�S, 37�37.05798'W ",
 38+ "-55�, 37�-37.05798' "
 39+ ),
 40+ 'dms' => array(
 41+ "55� 45' 21\" N, 37� 37' 3\" W",
 42+ "55� 45' 21\" N, -37� 37' 3\"",
 43+ "55� 45' S, 37� 37' 3\"W",
 44+ "-55�, -37� 37' 3\"",
 45+ "55�45'S,37�37'3\"W ",
 46+ "-55�,-37�37'3\" "
 47+ ),
 48+ );
 49+
 50+ public static $fakeCoordinates = array(
 51+ '55.7557860 E, 37.6176330 W',
 52+ '55.7557860 N, 37.6176330 N',
 53+ '55.7557860 S, 37.6176330 N',
 54+ '55.7557860 N, 37.6176330 S',
 55+ );
 56+
1557 /**
1658 * @var MapsCoordinateParser
1759 */
@@ -63,48 +105,36 @@
64106 * Tests MapsCoordinateParser::getCoordinatesType()
65107 */
66108 public function testGetCoordinatesType() {
67 - // Floats
68 - $this->assertEquals( MapsCoordinateParser::getCoordinatesType( '55.7557860 N, 37.6176330 W' ), Maps_COORDS_FLOAT );
69 - $this->assertEquals( MapsCoordinateParser::getCoordinatesType( '55.7557860, -37.6176330' ), Maps_COORDS_FLOAT );
70 - $this->assertEquals( MapsCoordinateParser::getCoordinatesType( '55 S, 37.6176330 W' ), Maps_COORDS_FLOAT );
71 - $this->assertEquals( MapsCoordinateParser::getCoordinatesType( '-55, -37.6176330' ), Maps_COORDS_FLOAT );
72 - $this->assertEquals( MapsCoordinateParser::getCoordinatesType( '5.5S,37W ' ), Maps_COORDS_FLOAT );
73 - $this->assertEquals( MapsCoordinateParser::getCoordinatesType( '-5.5,-37 ' ), Maps_COORDS_FLOAT );
 109+ foreach( self::$coordinates['float'] as $coord ) {
 110+ $this->assertEquals( MapsCoordinateParser::getCoordinatesType( $coord ), Maps_COORDS_FLOAT );
 111+ }
74112
75 - // Decimal Degrees
76 - $this->assertEquals( MapsCoordinateParser::getCoordinatesType( '55.7557860� N, 37.6176330� W' ), Maps_COORDS_DD );
77 - $this->assertEquals( MapsCoordinateParser::getCoordinatesType( '55.7557860�, -37.6176330�' ), Maps_COORDS_DD );
78 - $this->assertEquals( MapsCoordinateParser::getCoordinatesType( '55� S, 37.6176330 � W' ), Maps_COORDS_DD );
79 - $this->assertEquals( MapsCoordinateParser::getCoordinatesType( '-55�, -37.6176330 �' ), Maps_COORDS_DD );
80 - $this->assertEquals( MapsCoordinateParser::getCoordinatesType( '5.5�S,37�W ' ), Maps_COORDS_DD );
81 - $this->assertEquals( MapsCoordinateParser::getCoordinatesType( '-5.5�,-37� ' ), Maps_COORDS_DD );
 113+ foreach( self::$coordinates['dd'] as $coord ) {
 114+ $this->assertEquals( MapsCoordinateParser::getCoordinatesType( $coord ), Maps_COORDS_DD );
 115+ }
82116
83 - // Decimal Minutes
84 - $this->assertEquals( MapsCoordinateParser::getCoordinatesType( "55� 45.34716' N, 37� 37.05798' W" ), Maps_COORDS_DM );
85 - $this->assertEquals( MapsCoordinateParser::getCoordinatesType( "55� 45.34716', -37� 37.05798'" ), Maps_COORDS_DM );
86 - $this->assertEquals( MapsCoordinateParser::getCoordinatesType( "55� S, 37� 37.05798'W" ), Maps_COORDS_DM );
87 - $this->assertEquals( MapsCoordinateParser::getCoordinatesType( "-55�, 37� -37.05798'" ), Maps_COORDS_DM );
88 - $this->assertEquals( MapsCoordinateParser::getCoordinatesType( "55�S, 37�37.05798'W " ), Maps_COORDS_DM );
89 - $this->assertEquals( MapsCoordinateParser::getCoordinatesType( "-55�, 37�-37.05798' " ), Maps_COORDS_DM );
90 -
91 - // Degrees Minutes Seconds
92 - $this->assertEquals( MapsCoordinateParser::getCoordinatesType( "55� 45' 21\" N, 37� 37' 3\" W" ), Maps_COORDS_DMS );
93 - $this->assertEquals( MapsCoordinateParser::getCoordinatesType( "55� 45' 21\" N, -37� 37' 3\"" ), Maps_COORDS_DMS );
94 - $this->assertEquals( MapsCoordinateParser::getCoordinatesType( "55� 45' S, 37� 37' 3\"W" ), Maps_COORDS_DMS );
95 - $this->assertEquals( MapsCoordinateParser::getCoordinatesType( "-55�, -37� 37' 3\"" ), Maps_COORDS_DMS );
96 - $this->assertEquals( MapsCoordinateParser::getCoordinatesType( "55�45'S,37�37'3\"W " ), Maps_COORDS_DMS );
97 - $this->assertEquals( MapsCoordinateParser::getCoordinatesType( "-55�,-37�37'3\" " ), Maps_COORDS_DMS );
 117+ foreach( self::$coordinates['dm'] as $coord ) {
 118+ $this->assertEquals( MapsCoordinateParser::getCoordinatesType( $coord ), Maps_COORDS_DM );
 119+ }
 120+
 121+ foreach( self::$coordinates['dms'] as $coord ) {
 122+ $this->assertEquals( MapsCoordinateParser::getCoordinatesType( $coord ), Maps_COORDS_DMS );
 123+ }
98124 }
99125
100126 /**
101127 * Tests MapsCoordinateParser::areCoordinates()
102128 */
103129 public function testAreCoordinates() {
104 - // TODO Auto-generated MapsCoordinateParserTest::testAreCoordinates()
105 - $this->markTestIncomplete ( "areCoordinates test not implemented" );
 130+ foreach( self::$coordinates as $type ) {
 131+ foreach( self::$coordinates[$type] as $coord ) {
 132+ $this->assertTrue( MapsCoordinateParser::areCoordinates( $coord ) );
 133+ }
 134+ }
106135
107 - MapsCoordinateParser::areCoordinates(/* parameters */);
108 -
 136+ foreach ( self::$fakeCoordinates as $coord ) {
 137+ $this->assertFalse( MapsCoordinateParser::areCoordinates( $coord ) );
 138+ }
109139 }
110140
111141 /**

Status & tagging log