public function testTotalSurfaceArea() { $wrapCalculator = new WrapCalculator(); $box = new Box(); $box->setHeight(2); $box->setWidth(3); $box->setLength(4); $this->assertEquals(58, $wrapCalculator->getTotalSurfaceArea($box)); }
$options = getopt("f:vh"); $file = isset($options['f']) ? $options['f'] : "box-sizes.txt"; $verbose = (bool) isset($options['v']) ? true : false; $help = (bool) isset($options['h']) ? true : false; if ($help) { echo <<<HELP Usage: php calculate-wrapping-paper.php [-f] <file> -v -f <file> Parse file as having a box dimension on each line -v Verbose HELP; } require_once __DIR__ . '/vendor/autoload.php'; $totalSurfaceArea = 0; $wrapCalculator = new WrapCalculator(); $boxFactory = new BoxFactory(); $handle = fopen($file, "r"); while (false !== ($line = fgets($handle, 4096))) { $line = trim($line); $box = $boxFactory->createBox($line); $surfaceArea = $wrapCalculator->getTotalSurfaceArea($box); $totalSurfaceArea += $surfaceArea; if ($verbose) { $verboseOutput = "Dimensions: %' 9s, Total Surface Area: %d"; echo sprintf($verboseOutput, $line, $surfaceArea) . PHP_EOL; } } fclose($handle); $output = "Total Surface Area is: %s sq ft"; echo sprintf($output, number_format($totalSurfaceArea)) . PHP_EOL;