/** * コンストラクタ * * @param double $degree 摂氏度, 華氏度 * @param string $unit "C" または "F" * @throws \Exception 単位が異常なとき投げる */ public function __construct($degree, $unit) { switch (strtoupper($unit)) { case 'C': $this->degreeCelsius = (double) $degree; break; case 'F': $this->degreeCelsius = TemperatureConverter::convertFToC((double) $degree); break; default: throw new Exception('Unknown temperature unit was given'); } }
/** * @dataProvider degreeProvider */ public function testFtoC($c, $f) { $actual = TemperatureConverter::convertFToC($f); $this->assertEquals($c, $actual, '', 0.01); }