Passed
Push — master ( 5b74be...84d61d )
by Eric
18:51 queued 06:03
created

ConversionTest::testFahrenheitToKelvin()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * Utility - Collection of various PHP utility functions.
7
 *
8
 * @author    Eric Sizemore <[email protected]>
9
 * @version   2.0.0
10
 * @copyright (C) 2017 - 2024 Eric Sizemore
11
 * @license   The MIT License (MIT)
12
 *
13
 * Copyright (C) 2017 - 2024 Eric Sizemore <https://www.secondversion.com>.
14
 *
15
 * Permission is hereby granted, free of charge, to any person obtaining a copy
16
 * of this software and associated documentation files (the "Software"), to
17
 * deal in the Software without restriction, including without limitation the
18
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
19
 * sell copies of the Software, and to permit persons to whom the Software is
20
 * furnished to do so, subject to the following conditions:
21
 *
22
 * The above copyright notice and this permission notice shall be included in
23
 * all copies or substantial portions of the Software.
24
 *
25
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
31
 * THE SOFTWARE.
32
 */
33
34
namespace Esi\Utility\Tests;
35
36
use Esi\Utility\Conversion;
37
use PHPUnit\Framework\TestCase;
38
use PHPUnit\Framework\Attributes\CoversClass;
39
40
/**
41
 * Conversion utility tests.
42
 */
43
#[CoversClass(Conversion::class)]
44
class ConversionTest extends TestCase
45
{
46
    /**
47
     * Test Conversion::fahrenheitToCelsius().
48
     */
49
    public function testFahrenheitToCelsius(): void
50
    {
51
        self::assertEquals(23.33, Conversion::fahrenheitToCelsius(74));
52
        self::assertEquals(23.333_333_333_333_332, Conversion::fahrenheitToCelsius(74, false));
1 ignored issue
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_STRING, expecting ',' or ')' on line 52 at column 33
Loading history...
53
    }
54
55
    /**
56
     * Test Conversion::celsiusToFahrenheit().
57
     */
58
    public function testCelsiusToFahrenheit(): void
59
    {
60
        self::assertEquals(73.99, Conversion::celsiusToFahrenheit(23.33));
61
        self::assertEquals(74, Conversion::celsiusToFahrenheit(23.333_333_333_333_332, false));
62
    }
63
64
    /**
65
     * Test Conversion::celsiusToKelvin().
66
     */
67
    public function testCelsiusToKelvin(): void
68
    {
69
        self::assertEquals(296.48, Conversion::celsiusToKelvin(23.33));
70
        self::assertEquals(296.483_333_333_333_3, Conversion::celsiusToKelvin(23.333_333_333_333_332, false));
71
    }
72
73
    /**
74
     * Test Conversion::kelvinToCelsius().
75
     */
76
    public function testKelvinToCelsius(): void
77
    {
78
        self::assertEquals(23.33, Conversion::kelvinToCelsius(296.48));
79
        self::assertEquals(23.333_333_333_333_314, Conversion::kelvinToCelsius(296.483_333_333_333_3, false));
80
    }
81
82
    /**
83
     * Test Conversion::fahrenheitToKelvin().
84
     */
85
    public function testFahrenheitToKelvin(): void
86
    {
87
        self::assertEquals(296.48, Conversion::fahrenheitToKelvin(74));
88
        self::assertEquals(296.483_333_333_333_3, Conversion::fahrenheitToKelvin(74, false));
89
    }
90
91
    /**
92
     * Test Conversion::kelvinToFahrenheit().
93
     */
94
    public function testKelvinToFahrenheit(): void
95
    {
96
        self::assertEquals(73.99, Conversion::kelvinToFahrenheit(296.48));
97
        self::assertEquals(73.999_999_999_999_97, Conversion::kelvinToFahrenheit(296.483_333_333_333_3, false));
98
    }
99
100
    /**
101
     * Test Conversion::fahrenheitToRankine().
102
     */
103
    public function testFahrenheitToRankine(): void
104
    {
105
        self::assertEquals(533.67, Conversion::fahrenheitToRankine(74));
106
        self::assertEquals(533.670_000_000_000_1, Conversion::fahrenheitToRankine(74, false));
107
    }
108
109
    /**
110
     * Test Conversion::rankineToFahrenheit().
111
     */
112
    public function testRankineToFahrenheit(): void
113
    {
114
        self::assertEquals(74, Conversion::rankineToFahrenheit(533.67));
115
        self::assertEquals(74.000_000_000_000_06, Conversion::rankineToFahrenheit(533.670_000_000_000_1, false));
116
    }
117
118
    /**
119
     * Test Conversion::celsiusToRankine().
120
     */
121
    public function testCelsiusToRankine(): void
122
    {
123
        self::assertEquals(545.67, Conversion::celsiusToRankine(30));
124
        self::assertEquals(545.670_000_000_000_1, Conversion::celsiusToRankine(30, false));
125
    }
126
127
    /**
128
     * Test Conversion::rankineToCelsius().
129
     */
130
    public function testRankineToCelsius(): void
131
    {
132
        self::assertEquals(30, Conversion::rankineToCelsius(545.67));
133
        self::assertEquals(29.999_999_999_999_968, Conversion::rankineToCelsius(545.67, false));
134
    }
135
136
    /**
137
     * Test Conversion::kelvinToRankine().
138
     */
139
    public function testKelvinToRankine(): void
140
    {
141
        self::assertEquals(234.0, Conversion::kelvinToRankine(130));
142
        self::assertEquals(234.000_000_000_000_06, Conversion::kelvinToRankine(130, false));
143
    }
144
145
    /**
146
     * Test Conversion::rankineToKelvin().
147
     */
148
    public function testRankineToKelvin(): void
149
    {
150
        self::assertEquals(130, Conversion::rankineToKelvin(234.0));
151
        self::assertEquals(129.999_999_999_999_97, Conversion::rankineToKelvin(234.0, false));
152
    }
153
154
    /**
155
     * Test Conversion::haversineDistance().
156
     */
157
    public function testHaversineDistance(): void
158
    {
159
        $lat1 = 37.774_9;
160
        $lon1 = -122.419_4;
161
        $lat2 = 34.052_2;
162
        $lon2 = -118.243_7;
163
164
        $resultNoPrecision   = Conversion::haversineDistance($lat1, $lon1, $lat2, $lon2);
165
        $expectedNoPrecision = ['meters' => '559,119', 'kilometers' => '559', 'miles' => '347'];
166
        self::assertSame($expectedNoPrecision, $resultNoPrecision);
167
168
        $resultPrecision   = Conversion::haversineDistance($lat1, $lon1, $lat2, $lon2, 2);
169
        $expectedPrecision = ['meters' => '559,119.35', 'kilometers' => '559.12', 'miles' => '347.42'];
170
        self::assertSame($expectedPrecision, $resultPrecision);
171
    }
172
}
173