diff --git a/Conversions/TemperatureConversions.php b/Conversions/TemperatureConversions.php new file mode 100644 index 00000000..1be1fb52 --- /dev/null +++ b/Conversions/TemperatureConversions.php @@ -0,0 +1,115 @@ +expectException(\Exception::class); convertSpeed(1, 'km/h', 'miles'); } + + public function testCelsiusToFahrenheit() + { + $this->assertEquals(32.0, CelsiusToFahrenheit(0)); + $this->assertEquals(212.0, CelsiusToFahrenheit(100)); + $this->assertEquals(98.6, CelsiusToFahrenheit(37)); + $this->expectException(\Exception::class); + $this->expectExceptionMessage('Temperature (Celsius) must be a number'); + CelsiusToFahrenheit("non-numeric"); + } + + public function testFahrenheitToCelsius() + { + $this->assertEquals(0.0, FahrenheitToCelsius(32)); + $this->assertEquals(100.0, FahrenheitToCelsius(212)); + $this->assertEquals(37.0, FahrenheitToCelsius(98.6)); + $this->expectException(\Exception::class); + $this->expectExceptionMessage('Temperature (Fahrenheit) must be a number'); + FahrenheitToCelsius("non-numeric"); + } + + public function testCelsiusToKelvin() + { + $this->assertEquals(273.15, CelsiusToKelvin(0)); + $this->assertEquals(373.15, CelsiusToKelvin(100)); + $this->expectException(\Exception::class); + $this->expectExceptionMessage('Temperature (Celsius) must be a number'); + CelsiusToKelvin("non-numeric"); + } + + public function testKelvinToCelsius() + { + $this->assertEquals(0.0, KelvinToCelsius(273.15)); + $this->assertEquals(100.0, KelvinToCelsius(373.15)); + $this->expectException(\Exception::class); + $this->expectExceptionMessage('Temperature (Kelvin) must be a number'); + KelvinToCelsius("non-numeric"); + } + + public function testKelvinToFahrenheit() + { + $this->assertEquals(32.0, KelvinToFahrenheit(273.15)); + $this->assertEquals(212.0, KelvinToFahrenheit(373.15)); + $this->expectException(\Exception::class); + $this->expectExceptionMessage('Temperature (Kelvin) must be a number'); + KelvinToFahrenheit("non-numeric"); + } + + public function testFahrenheitToKelvin() + { + $this->assertEquals(273.15, FahrenheitToKelvin(32)); + $this->assertEquals(373.15, FahrenheitToKelvin(212)); + $this->expectException(\Exception::class); + $this->expectExceptionMessage('Temperature (Fahrenheit) must be a number'); + FahrenheitToKelvin("non-numeric"); + } } diff --git a/tests/Maths/MathsTest.php b/tests/Maths/MathsTest.php index 66a86347..a9428b7f 100644 --- a/tests/Maths/MathsTest.php +++ b/tests/Maths/MathsTest.php @@ -22,6 +22,7 @@ require_once __DIR__ . '/../../Maths/Mode.php'; require_once __DIR__ . '/../../Maths/FastInverseSquareRoot.php'; require_once __DIR__ . '/../../Maths/BaseX.php'; +require_once __DIR__ . '/../../Maths/PerfectNumber.php'; class MathsTest extends TestCase { @@ -185,6 +186,22 @@ public function testGreatestCommonDivisor() $this->assertEquals(3, gcd(9, 12)); } + public function testPerfectNumber() + { + $this->assertTrue(perfect_number(6)); + $this->assertTrue(perfect_number(28)); + $this->assertTrue(perfect_number(496)); + + $this->assertFalse(perfect_number(10)); + $this->assertFalse(perfect_number(15)); + + $this->assertFalse(perfect_number(-6)); + $this->assertFalse(perfect_number(0)); + $this->assertFalse(perfect_number(1)); + $this->assertFalse(perfect_number(2.5)); + $this->assertFalse(perfect_number("string")); + } + public function testFastInverseSquareRoot() { $this->assertEqualsWithDelta(0.31568579235273, fastInvSqrt(10), 0.00001);