diff --git a/tests/muqsit/arithmexp/OptimizerTest.php b/tests/muqsit/arithmexp/OptimizerTest.php index ac25fe1..9b693b8 100644 --- a/tests/muqsit/arithmexp/OptimizerTest.php +++ b/tests/muqsit/arithmexp/OptimizerTest.php @@ -61,7 +61,25 @@ public function testConstantPropagationOptimization() : void{ self::assertExpressionsEqual($expected, $actual); } - public function testDivisionConstantFoldingForEqualOperandsReturningNan() : void{ + public function testDivisionConstantFoldingForRightOperandNan() : void{ + $expression = $this->parser->parse("min(1, 2) / nan"); + self::assertInstanceOf(ConstantExpression::class, $expression); + self::assertNan($expression->evaluate()); + } + + public function testSubtractionConstantFoldingBetweenInf() : void{ + $expression = $this->parser->parse("inf - inf"); + self::assertInstanceOf(ConstantExpression::class, $expression); + self::assertNan($expression->evaluate()); + } + + public function testSubtractionConstantFoldingBetweenNan() : void{ + $expression = $this->parser->parse("nan - nan"); + self::assertInstanceOf(ConstantExpression::class, $expression); + self::assertNan($expression->evaluate()); + } + + public function testDivisionConstantFoldingForFunctionCallOperandsReturningNan() : void{ $expression = $this->parser->parse("sqrt(-1) / sqrt(-1)"); self::assertInstanceOf(ConstantExpression::class, $expression); self::assertNan($expression->evaluate()); @@ -204,6 +222,16 @@ public function testDivisionOperatorStrengthReductionForEqualOperandsWithGroupin self::assertEquals(1, $expression->evaluate()); } + public function testMultiplicationOperatorStrengthReductionForNanOperands() : void{ + $expression = $this->parser->parse("nan * x"); + self::assertInstanceOf(ConstantExpression::class, $expression); + self::assertNan($expression->evaluate()); + + $expression = $this->parser->parse("x * nan"); + self::assertInstanceOf(ConstantExpression::class, $expression); + self::assertNan($expression->evaluate()); + } + public function testDivisionOperatorStrengthReductionForCommutativelyEqualOperands() : void{ $expression = $this->parser->parse("(x + y + z) / (y + x + z)"); self::assertInstanceOf(ConstantExpression::class, $expression); @@ -222,6 +250,12 @@ public function testDivisionOperatorStrengthReductionForLeftOperandZeroWithGroup self::assertEquals(0, $expression->evaluate()); } + public function testDivisionOperatorStrengthReductionForRightOperandNan() : void{ + $expression = $this->parser->parse("mt_rand(1, 2) / nan"); + self::assertInstanceOf(ConstantExpression::class, $expression); + self::assertNan($expression->evaluate()); + } + public function testDivisionOperatorStrengthReductionForRightOperandOne() : void{ $actual = $this->parser->parse("x / 1 + y / 1"); $expected = $this->unoptimized_parser->parse("x + y"); @@ -288,6 +322,16 @@ public function testAdditionOperatorStrengthReductionForOperandZeroWithGrouping( self::assertExpressionsEqual($expected, $actual); } + public function testAdditionOperatorStrengthReductionForNanOperands() : void{ + $expression = $this->parser->parse("nan + x"); + self::assertInstanceOf(ConstantExpression::class, $expression); + self::assertNan($expression->evaluate()); + + $expression = $this->parser->parse("x + nan"); + self::assertInstanceOf(ConstantExpression::class, $expression); + self::assertNan($expression->evaluate()); + } + public function testAdditionOperatorStrengthReductionForNegativeLeftOperand() : void{ $actual = $this->parser->parse("-x + y"); $expected = $this->unoptimized_parser->parse("y - x"); @@ -354,6 +398,16 @@ public function testSubtractionOperatorStrengthReductionForCommutativeFunctions( self::assertEquals(0, $expression->evaluate()); } + public function testSubtractionOperatorStrengthReductionForNanOperands() : void{ + $expression = $this->parser->parse("nan - x"); + self::assertInstanceOf(ConstantExpression::class, $expression); + self::assertNan($expression->evaluate()); + + $expression = $this->parser->parse("x - nan"); + self::assertInstanceOf(ConstantExpression::class, $expression); + self::assertNan($expression->evaluate()); + } + public function testSubtractionOperatorStrengthReductionForNegativeLeftOperand() : void{ $actual = $this->parser->parse("-x - y");