MathPHP\Functions\ArithmeticTest::testMultipleProducts PHP Method

testMultipleProducts() public method

    public function testMultipleProducts()
    {
        // f(x) = x - 9
        $f = function ($x) {
            return $x - 9;
        };
        // g(x) = x + 2
        $g = function ($x) {
            return $x + 2;
        };
        // h(x) = x
        $h = function ($x) {
            return $x;
        };
        // Π(x) = f(x) * g(x) * h(x) = x³ - 7x² -18x
        $product = Arithmetic::multiply($f, $g, $h);
        // Π(0) = 0
        $expected = 0;
        $x = $product(0);
        $this->assertEquals($expected, $x);
        // Π(5) = -140
        $expected = -140;
        $x = $product(5);
        $this->assertEquals($expected, $x);
        // Π(-5) = -210
        $expected = -210;
        $x = $product(-5);
        $this->assertEquals($expected, $x);
    }