Skip to content

Commit

Permalink
add: text case added for ConvertTime classs
Browse files Browse the repository at this point in the history
  • Loading branch information
arafat-web committed Oct 30, 2024
1 parent 2a1a280 commit fcd7dc7
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions tests/Conversions/ConversionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
require_once __DIR__ . '/../../Conversions/HexadecimalToDecimal.php';
require_once __DIR__ . '/../../Conversions/SpeedConversion.php';
require_once __DIR__ . '/../../Conversions/TemperatureConversions.php';
require_once __DIR__ . '/../../Conversions/ConvertTime.php';

class ConversionsTest extends TestCase
{
Expand Down Expand Up @@ -142,4 +143,41 @@ public function testFahrenheitToKelvin()
$this->expectExceptionMessage('Temperature (Fahrenheit) must be a number');
FahrenheitToKelvin("non-numeric");
}

public function testConvertTime()
{
// Test basic conversions
$this->assertEquals(2.0, convertTime(120, 'seconds', 'minutes'), "Failed converting 120 seconds to minutes");
$this->assertEquals(2.0, convertTime(120, 'minutes', 'hours'), "Failed converting 120 minutes to hours");
$this->assertEquals(2.0, convertTime(48, 'hours', 'days'), "Failed converting 48 hours to days");
$this->assertEquals(2.0, convertTime(14, 'days', 'weeks'), "Failed converting 14 days to weeks");

// Test with different units and values
$this->assertEqualsWithDelta(2.0, convertTime(8.6, 'weeks', 'months'), 0.01, "Failed converting 8.6 weeks to months");
$this->assertEquals(2.0, convertTime(24, 'months', 'years'), "Failed converting 24 months to years");

// Test edge cases
$this->assertEquals(0.0, convertTime(0, 'seconds', 'hours'), "Failed converting 0 seconds to hours");

// Test invalid 'from' and 'to' units
try {
convertTime(120, 'invalidUnit', 'minutes');
} catch (InvalidArgumentException $e) {
$this->assertEquals("Invalid time unit(s) specified: invalidUnit to minutes", $e->getMessage());
}

try {
convertTime(120, 'seconds', 'invalidUnit');
} catch (InvalidArgumentException $e) {
$this->assertEquals("Invalid time unit(s) specified: seconds to invalidUnit", $e->getMessage());
}

try {
convertTime(120, 'invalidFrom', 'invalidTo');
} catch (InvalidArgumentException $e) {
$this->assertEquals("Invalid time unit(s) specified: invalidFrom to invalidTo", $e->getMessage());
}
}


}

0 comments on commit fcd7dc7

Please sign in to comment.