Skip to content

Commit

Permalink
add temperature conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
krishnahimself committed Sep 21, 2020
1 parent ba174cc commit 41c349f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/Temperature.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace KbhandariWeb\UnitConversions;

class Temperature
{
private float $celsius;

public static function forCelsius(float $celsius): self
{
return new static($celsius);
}

public function __construct(float $celsius)
{
$this->celsius = $celsius;
}

public function toFahrenheit(): float
{
return ($this->celsius * 1.8) + 32;
}
}
17 changes: 17 additions & 0 deletions tests/TemperatureTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace KbhandariWeb\UnitConversions\Tests;

use PHPUnit\Framework\TestCase;
use KbhandariWeb\UnitConversions\Temperature;

class TemperatureTest extends TestCase
{
/** @test */
public function it_can_convert_celsius_to_fahrenheit()
{
$fahrenheit = Temperature::forCelsius(100)->toFahrenheit();

$this->assertEquals(212, $fahrenheit );
}
}

0 comments on commit 41c349f

Please sign in to comment.