|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Vlaswinkel\UnitConverter\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
|
6
|
|
|
use Vlaswinkel\UnitConverter\UnitConverter; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Class UnitConverterTest |
|
10
|
|
|
* |
|
11
|
|
|
* @author Koen Vlaswinkel <[email protected]> |
|
12
|
|
|
* @package Vlaswinkel\UnitConverter\Tests |
|
13
|
|
|
*/ |
|
14
|
|
|
class UnitConverterTest extends TestCase { |
|
15
|
|
|
/** |
|
16
|
|
|
* @var UnitConverter |
|
17
|
|
|
*/ |
|
18
|
|
|
private $converter; |
|
19
|
|
|
|
|
20
|
|
|
public static function setUpBeforeClass() { |
|
21
|
|
|
bcscale(20); // we want to have a reasonable scale for testing |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function setUp() { |
|
25
|
|
|
$this->converter = new UnitConverter(); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function testSimpleUnitConverter() { |
|
29
|
|
|
$this->assertEquals('3.28083989501312335958', $this->converter->convert('1', 'm', 'ft')); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function testDerivedMile() { |
|
33
|
|
|
$this->assertEquals('1609.344', $this->converter->convert('1', 'mile', 'm')); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function testDerivedShortTon() { |
|
37
|
|
|
$this->assertEquals('907.18474', $this->converter->convert('1', 'shortton', 'kg')); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function testArea() { |
|
41
|
|
|
$this->assertEquals('10.76391041670972230833', $this->converter->convert('1', 'm^2', 'ft^2')); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function testComplexArea() { |
|
45
|
|
|
$this->assertEquals('10000', $this->converter->convert('1', 'ha', 'm^2')); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function testComplexVolume() { |
|
49
|
|
|
$this->assertEquals('4.54609', $this->converter->convert('1', 'impgal', 'L')); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function testSpeed() { |
|
53
|
|
|
$this->assertEquals('2.23693629205440229062', $this->converter->convert('1', 'm/s', 'mi/h')); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function testComplexUnit() { |
|
57
|
|
|
$this->assertEquals('1069.06636670416528910000', $this->converter->convert('10000', 'L/ha', 'usgal/ac')); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function testDerivedWatt() { |
|
61
|
|
|
$this->assertEquals('1', $this->converter->convert('1', 'W', 'J/s')); |
|
62
|
|
|
} |
|
63
|
|
|
} |