public static function validateSpline(array $points, $degree = 2) : bool { if (count($points) < $degree) { throw new Exception\BadDataException('You need to have at least $degree sets of coordinates (arrays) for this technique'); } $x_coordinates = []; foreach ($points as $point) { if (count($point) !== 3) { throw new Exception\BadDataException('Each array needs to have have precisely three numbers, representing x, y, and y-prime'); } $x_component = $point[self::X]; if (in_array($x_component, $x_coordinates)) { throw new Exception\BadDataException('Not a function. Your input array contains more than one coordinate with the same x-component.'); } array_push($x_coordinates, $x_component); } return true; }
public function testNotAFunctionException() { // Two arrays share the same first number (x-component) $this->setExpectedException('MathPHP\\Exception\\BadDataException'); ClampedCubicSpline::validateSpline([[0, 0, 1], [0, 5, 0], [1, 1, 3]]); }