Skip to content

Commit fff0565

Browse files
authored
feat: add Velocity Units (pimlie#8)
* feat: added velocity unit type fix: Added correct unit systems to velocity units * added .idea to gitignore * fix: adjusted spelling, added aliases Added aliases for Mile based Velocity Units as per code review. * fix: Adjust test to account for added unit types
1 parent e158067 commit fff0565

20 files changed

+276
-1
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.idea/
12
.git
23
clover.xml
34
coveralls-upload.json

src/Unit/Velocity.php

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
namespace PhpUnitConversion\Unit;
3+
4+
use PhpUnitConversion\Unit;
5+
use PhpUnitConversion\UnitType;
6+
7+
class Velocity extends Unit
8+
{
9+
const TYPE = UnitType::VELOCITY;
10+
11+
const BASE_UNIT = Velocity\MeterPerSecond::class;
12+
}

src/Unit/Velocity/FootPerHour.php

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
namespace PhpUnitConversion\Unit\Velocity;
3+
4+
use PhpUnitConversion\System\Imperial;
5+
use PhpUnitConversion\System\USC;
6+
use PhpUnitConversion\Unit\Velocity;
7+
8+
class FootPerHour extends Velocity implements Imperial, USC
9+
{
10+
const FACTOR = 1/11811;
11+
12+
const SYMBOL = 'fph';
13+
const LABEL = 'foot per hour';
14+
}

src/Unit/Velocity/FootPerMinute.php

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
namespace PhpUnitConversion\Unit\Velocity;
3+
4+
use PhpUnitConversion\System\Imperial;
5+
use PhpUnitConversion\System\USC;
6+
use PhpUnitConversion\Unit\Velocity;
7+
8+
class FootPerMinute extends Velocity implements Imperial, USC
9+
{
10+
const FACTOR = 1/196.85;
11+
12+
const SYMBOL = 'fpm';
13+
const LABEL = 'foot per minute';
14+
}

src/Unit/Velocity/FootPerSecond.php

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
namespace PhpUnitConversion\Unit\Velocity;
3+
4+
use PhpUnitConversion\System\Imperial;
5+
use PhpUnitConversion\System\USC;
6+
use PhpUnitConversion\Unit\Velocity;
7+
8+
class FootPerSecond extends Velocity implements Imperial, USC
9+
{
10+
const FACTOR = 1/3.280840;
11+
12+
const SYMBOL = 'fps';
13+
const LABEL = 'foot per second';
14+
}

src/Unit/Velocity/InchPerHour.php

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
namespace PhpUnitConversion\Unit\Velocity;
3+
4+
use PhpUnitConversion\System\Imperial;
5+
use PhpUnitConversion\System\USC;
6+
use PhpUnitConversion\Unit\Velocity;
7+
8+
class InchPerHour extends Velocity implements Imperial, USC
9+
{
10+
const FACTOR = 1/141732.3;
11+
12+
const SYMBOL = 'iph';
13+
const LABEL = 'inch per hour';
14+
}

src/Unit/Velocity/InchPerMinute.php

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
namespace PhpUnitConversion\Unit\Velocity;
3+
4+
use PhpUnitConversion\System\Imperial;
5+
use PhpUnitConversion\System\USC;
6+
use PhpUnitConversion\Unit\Velocity;
7+
8+
class InchPerMinute extends Velocity implements Imperial, USC
9+
{
10+
const FACTOR = 1/2362.205;
11+
12+
const SYMBOL = 'ipm';
13+
const LABEL = 'inch per minute';
14+
}

src/Unit/Velocity/InchPerSecond.php

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
namespace PhpUnitConversion\Unit\Velocity;
3+
4+
use PhpUnitConversion\System\Imperial;
5+
use PhpUnitConversion\System\USC;
6+
use PhpUnitConversion\Unit\Velocity;
7+
8+
class InchPerSecond extends Velocity implements Imperial, USC
9+
{
10+
const FACTOR = 1/39.37008;
11+
12+
const SYMBOL = 'ips';
13+
const LABEL = 'inch per second';
14+
}
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
namespace PhpUnitConversion\Unit\Velocity;
3+
4+
use PhpUnitConversion\System\Metric;
5+
use PhpUnitConversion\Unit\Velocity;
6+
7+
class KiloMeterPerHour extends Velocity implements Metric
8+
{
9+
const FACTOR = 1/3.6;
10+
11+
const SYMBOL = 'km/h';
12+
const LABEL = 'kilometer per hour';
13+
}

src/Unit/Velocity/Knot.php

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
namespace PhpUnitConversion\Unit\Velocity;
3+
4+
use PhpUnitConversion\System\Metric;
5+
use PhpUnitConversion\Unit\Velocity;
6+
7+
class Knot extends Velocity implements Metric
8+
{
9+
const FACTOR = 1/1.943844;
10+
11+
const SYMBOL = 'kn';
12+
const LABEL = 'knot';
13+
}

src/Unit/Velocity/MeterPerSecond.php

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
namespace PhpUnitConversion\Unit\Velocity;
3+
4+
use PhpUnitConversion\System\Metric;
5+
use PhpUnitConversion\Unit\Velocity;
6+
use PhpUnitConversion\Traits\BaseUnit;
7+
8+
class MeterPerSecond extends Velocity implements Metric
9+
{
10+
use BaseUnit;
11+
12+
const FACTOR = 1;
13+
14+
const SYMBOL = 'm/s';
15+
const LABEL = 'meter per second';
16+
}

src/Unit/Velocity/MilePerHour.php

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
namespace PhpUnitConversion\Unit\Velocity;
3+
4+
use PhpUnitConversion\System\Imperial;
5+
use PhpUnitConversion\System\USC;
6+
use PhpUnitConversion\Unit\Velocity;
7+
8+
class MilePerHour extends Velocity implements Imperial, USC
9+
{
10+
const FACTOR = 1/2.236936;
11+
12+
const SYMBOL = 'mph';
13+
const LABEL = 'mile per hour';
14+
}

src/Unit/Velocity/MilePerMinute.php

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
namespace PhpUnitConversion\Unit\Velocity;
3+
4+
use PhpUnitConversion\System\Imperial;
5+
use PhpUnitConversion\System\USC;
6+
use PhpUnitConversion\Unit\Velocity;
7+
8+
class MilePerMinute extends Velocity implements Imperial, USC
9+
{
10+
const FACTOR = 26.82240;
11+
12+
const SYMBOL = 'mpm';
13+
const LABEL = 'mile per minute';
14+
}

src/Unit/Velocity/MilePerSecond.php

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
namespace PhpUnitConversion\Unit\Velocity;
3+
4+
use PhpUnitConversion\System\Imperial;
5+
use PhpUnitConversion\System\USC;
6+
use PhpUnitConversion\Unit\Velocity;
7+
8+
class MilePerSecond extends Velocity implements Imperial, USC
9+
{
10+
const FACTOR = 1609.344;
11+
12+
const SYMBOL = 'mps';
13+
const LABEL = 'mile per second';
14+
}

src/Unit/Velocity/MilesPerHour.php

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
namespace PhpUnitConversion\Unit\Velocity;
3+
4+
class MilesPerHour extends MilePerHour
5+
{
6+
}

src/Unit/Velocity/MilesPerMinute.php

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
namespace PhpUnitConversion\Unit\Velocity;
3+
4+
class MilesPerMinute extends MilePerMinute
5+
{
6+
}

src/Unit/Velocity/MilesPerSecond.php

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
namespace PhpUnitConversion\Unit\Velocity;
3+
4+
class MilesPerSecond extends MilePerSecond
5+
{
6+
}

src/UnitType.php

+1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ class UnitType extends Enum
1414
const TIME = 5;
1515
const TEMPERATURE = 6;
1616
const AMOUNT = 7;
17+
const VELOCITY = 8;
1718
}

tests/Unit/VelocityTest.php

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
namespace PhpUnitConversionTest\Unit;
3+
4+
use PHPUnit\Framework\TestCase;
5+
use PhpUnitConversion\Unit\Velocity;
6+
use PhpUnitConversion\Unit\Volume;
7+
8+
class VelocityTest extends TestCase
9+
{
10+
public function testFromFootPerHour()
11+
{
12+
$volumeUnit = new Velocity\FootPerHour(100000);
13+
$this->assertEquals('8.467 m/s', Velocity\MeterPerSecond::from($volumeUnit)->format(3));
14+
}
15+
16+
public function testFromFootPerMinute()
17+
{
18+
$volumeUnit = new Velocity\FootPerMinute(100000);
19+
$this->assertEquals('508.001 m/s', Velocity\MeterPerSecond::from($volumeUnit)->format(3));
20+
}
21+
22+
public function testFromFootPerSecond()
23+
{
24+
$volumeUnit = new Velocity\FootPerSecond(100000);
25+
$this->assertEquals('30480 m/s', Velocity\MeterPerSecond::from($volumeUnit)->format(0));
26+
}
27+
28+
public function testFromMilesPerHour()
29+
{
30+
$volumeUnit = new Velocity\MilePerHour(100000);
31+
$this->assertEquals('44704 m/s', Velocity\MeterPerSecond::from($volumeUnit)->format(0));
32+
}
33+
34+
public function testFromKiloMetersPerHour()
35+
{
36+
$volumeUnit = new Velocity\KiloMeterPerHour(100000);
37+
$this->assertEquals('27777.78 m/s', Velocity\MeterPerSecond::from($volumeUnit)->format(2));
38+
}
39+
40+
public function testFromMilesPerSecond()
41+
{
42+
$volumeUnit = new Velocity\MilePerSecond(100000);
43+
$this->assertEquals('160934400.00 m/s', Velocity\MeterPerSecond::from($volumeUnit)->format(2));
44+
}
45+
46+
public function testFromInchPerHour()
47+
{
48+
$volumeUnit = new Velocity\InchPerHour(100000);
49+
$this->assertEquals('0.706 m/s', Velocity\MeterPerSecond::from($volumeUnit)->format(3));
50+
}
51+
52+
public function testFromInchPerMinute()
53+
{
54+
$volumeUnit = new Velocity\InchPerMinute(100000);
55+
$this->assertEquals('42.333 m/s', Velocity\MeterPerSecond::from($volumeUnit)->format(3));
56+
}
57+
58+
public function testFromInchPerSecond()
59+
{
60+
$volumeUnit = new Velocity\InchPerSecond(100000);
61+
$this->assertEquals('2540.00 m/s', Velocity\MeterPerSecond::from($volumeUnit)->format(2));
62+
}
63+
64+
public function testFromKnot()
65+
{
66+
$volumeUnit = new Velocity\Knot(100000);
67+
$this->assertEquals('51444 m/s', Velocity\MeterPerSecond::from($volumeUnit)->format(0));
68+
}
69+
70+
public function testFromMilesPerMinute()
71+
{
72+
$volumeUnit = new Velocity\MilePerMinute(100000);
73+
$this->assertEquals('2682240.00 m/s', Velocity\MeterPerSecond::from($volumeUnit)->format(2));
74+
}
75+
}

tests/UnitTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function testTypeUnits()
6262
count($allUnits),
6363
$this->logicalOr(
6464
$this->equalTo(9),
65-
$this->equalTo(232)
65+
$this->equalTo(247)
6666
)
6767
);
6868

0 commit comments

Comments
 (0)