diff --git a/lib/WPStrava/SOM.php b/lib/WPStrava/SOM.php index 65d9715..485bfb8 100644 --- a/lib/WPStrava/SOM.php +++ b/lib/WPStrava/SOM.php @@ -64,9 +64,13 @@ abstract class WPStrava_SOM { */ public function swimpace( $mps ) { - $kmh = $mps * 3.6; - $min100m = 60 / $kmh / 10; + $kmh = $mps * 3.6; + $s = 3600 / $kmh / 10; + $ss = $s / 60; + $ms = floor( $ss ) * 60; + $sec = sprintf( '%02d', round( $s - $ms ) ); + $min = floor( $ss ); - return number_format( $min100m, 2 ); + return "{$min}:{$sec}"; } } diff --git a/tests/WPStrava/SOMEnglishTest.php b/tests/WPStrava/SOMEnglishTest.php index 7cc60e9..ad5a8c5 100644 --- a/tests/WPStrava/SOMEnglishTest.php +++ b/tests/WPStrava/SOMEnglishTest.php @@ -18,7 +18,7 @@ class WPStrava_SOMEnglishTest extends TestCase { * Test that 10,000 meters is 6.21 miles using both string and float inputs. * * @author Justin Foell - * @since NEXT + * @since 1.7.1 */ public function test_distance() { $this->assertEquals( '6.21' , $this->som->distance( '10000' ) ); @@ -29,7 +29,7 @@ class WPStrava_SOMEnglishTest extends TestCase { * Test that 6.213712 miles is 10,000.00 meters using both string and float inputs. * * @author Justin Foell - * @since NEXT + * @since 1.7.1 */ public function test_distance_inverse() { $this->assertEquals( '10,000.00' , $this->som->distance_inverse( '6.213712' ) ); @@ -40,7 +40,7 @@ class WPStrava_SOMEnglishTest extends TestCase { * Test that 6.705 meters per second is 15.00 mph using both string and float inputs. * * @author Justin Foell - * @since NEXT + * @since 1.7.1 */ public function test_speed() { $this->assertEquals( '15.00', $this->som->speed( '6.705' ) ); @@ -51,7 +51,7 @@ class WPStrava_SOMEnglishTest extends TestCase { * Test that 2.68224 meters per second is a 10:00 minute/mile pace using both string and float inputs. * * @author Justin Foell - * @since NEXT + * @since 1.7.1 */ public function test_pace() { $this->assertEquals( '10:00', $this->som->pace( '2.68224' ) ); @@ -62,10 +62,22 @@ class WPStrava_SOMEnglishTest extends TestCase { * Test that 60.96 meters is 200.00 feet using both string and float inputs. * * @author Justin Foell - * @since NEXT + * @since 1.7.1 */ public function test_elevation() { $this->assertEquals( '200.00', $this->som->elevation( '60.96' ) ); $this->assertEquals( '200.00', $this->som->elevation( 60.96 ) ); } + + /** + * Test that 4805 seconds is 01:20:05 time (H:i:s) using both string and float inputs. + * + * @author Justin Foell + * @since 1.7.1 + */ + public function test_time() { + $this->assertEquals( '01:20:05', $this->som->time( '4805' ) ); + $this->assertEquals( '01:20:05', $this->som->time( 4805 ) ); + + } } diff --git a/tests/WPStrava/SOMMetricTest.php b/tests/WPStrava/SOMMetricTest.php new file mode 100644 index 0000000..d5ad8be --- /dev/null +++ b/tests/WPStrava/SOMMetricTest.php @@ -0,0 +1,82 @@ +som = new WPStrava_SOMMetric(); + } + + public function test_object() { + $this->assertInstanceOf( 'WPStrava_SOMMetric', $this->som ); + } + + /** + * Test that 10,000 meters is 10.00 kilometers using both string and float inputs. + * + * @author Justin Foell + * @since 1.7.1 + */ + public function test_distance() { + $this->assertEquals( '10.00' , $this->som->distance( '10000' ) ); + $this->assertEquals( '10.00' , $this->som->distance( 10000 ) ); + } + + /** + * Test that 42.195 km is 42,195.00 meters using both string and float inputs. + * + * @author Justin Foell + * @since 1.7.1 + */ + public function test_distance_inverse() { + $this->assertEquals( '42,195.00' , $this->som->distance_inverse( '42.195' ) ); + $this->assertEquals( '42,195.00' , $this->som->distance_inverse( 42.195 ) ); + } + + /** + * Test that 4.47 meters per second is 16.09 kmh using both string and float inputs. + * + * @author Justin Foell + * @since 1.7.1 + */ + public function test_speed() { + $this->assertEquals( '16.09', $this->som->speed( '4.47' ) ); + $this->assertEquals( '16.09', $this->som->speed( 4.47 ) ); + } + + /** + * Test that 2.2352 meters per second is a 7:27 minute/kilometer pace using both string and float inputs. + * + * @author Justin Foell + * @since 1.7.1 + */ + public function test_pace() { + $this->assertEquals( '7:27', $this->som->pace( '2.2352' ) ); + $this->assertEquals( '7:27', $this->som->pace( 2.2352 ) ); + } + + /** + * Test that 70 meters is 70.00 meters using both string and float inputs. + * + * @author Justin Foell + * @since 1.7.1 + */ + public function test_elevation() { + $this->assertEquals( '70.00', $this->som->elevation( '70' ) ); + $this->assertEquals( '70.00', $this->som->elevation( 70 ) ); + } + + /** + * Test that 1.66 meters per second is a 1:00 minute/100m pace using both string and float inputs. + * + * @author Justin Foell + * @since 1.7.1 + */ + public function test_swimpace() { + $this->assertEquals( '1:00', $this->som->swimpace( '1.66' ) ); + $this->assertEquals( '1:00', $this->som->swimpace( 1.66 ) ); + } +}