Skip to content
This repository was archived by the owner on Feb 28, 2025. It is now read-only.

PHPLIB-1357 Add tests on Trigonometry Expression Operators #48

Merged
merged 1 commit into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions generator/config/expression/acos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,16 @@ arguments:
$acos takes any valid expression that resolves to a number between -1 and 1, e.g. -1 <= value <= 1.
$acos returns values in radians. Use $radiansToDegrees operator to convert the output value from radians to degrees.
By default $acos returns values as a double. $acos can also return values as a 128-bit decimal as long as the expression resolves to a 128-bit decimal value.
tests:
-
name: 'Example'
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/acos/#example'
pipeline:
-
$addFields:
angle_a:
$radiansToDegrees:
$acos:
$divide:
- '$side_b'
- '$hypotenuse'
10 changes: 10 additions & 0 deletions generator/config/expression/acosh.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,13 @@ arguments:
$acosh takes any valid expression that resolves to a number between 1 and +Infinity, e.g. 1 <= value <= +Infinity.
$acosh returns values in radians. Use $radiansToDegrees operator to convert the output value from radians to degrees.
By default $acosh returns values as a double. $acosh can also return values as a 128-bit decimal as long as the expression resolves to a 128-bit decimal value.
tests:
-
name: 'Example'
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/acosh/#example'
pipeline:
-
$addFields:
y-coordinate:
$radiansToDegrees:
$acosh: '$x-coordinate'
13 changes: 13 additions & 0 deletions generator/config/expression/asin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,16 @@ arguments:
$asin takes any valid expression that resolves to a number between -1 and 1, e.g. -1 <= value <= 1.
$asin returns values in radians. Use $radiansToDegrees operator to convert the output value from radians to degrees.
By default $asin returns values as a double. $asin can also return values as a 128-bit decimal as long as the expression resolves to a 128-bit decimal value.
tests:
-
name: 'Example'
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/asin/#example'
pipeline:
-
$addFields:
angle_a:
$radiansToDegrees:
$asin:
$divide:
- '$side_a'
- '$hypotenuse'
10 changes: 10 additions & 0 deletions generator/config/expression/asinh.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,13 @@ arguments:
$asinh takes any valid expression that resolves to a number.
$asinh returns values in radians. Use $radiansToDegrees operator to convert the output value from radians to degrees.
By default $asinh returns values as a double. $asinh can also return values as a 128-bit decimal as long as the expression resolves to a 128-bit decimal value.
tests:
-
name: 'Example'
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/asinh/#example'
pipeline:
-
$addFields:
y-coordinate:
$radiansToDegrees:
$asinh: '$x-coordinate'
13 changes: 13 additions & 0 deletions generator/config/expression/atan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,16 @@ arguments:
$atan takes any valid expression that resolves to a number.
$atan returns values in radians. Use $radiansToDegrees operator to convert the output value from radians to degrees.
By default $atan returns values as a double. $atan can also return values as a 128-bit decimal as long as the expression resolves to a 128-bit decimal value.
tests:
-
name: 'Example'
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/atan/#example'
pipeline:
-
$addFields:
angle_a:
$radiansToDegrees:
$atan:
$divide:
- '$side_b'
- '$side_a'
12 changes: 12 additions & 0 deletions generator/config/expression/atan2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,15 @@ arguments:
name: x
type:
- resolvesToNumber
tests:
-
name: 'Example'
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/atan2/#example'
pipeline:
-
$addFields:
angle_a:
$radiansToDegrees:
$atan2:
- '$side_b'
- '$side_a'
10 changes: 10 additions & 0 deletions generator/config/expression/atanh.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,13 @@ arguments:
$atanh takes any valid expression that resolves to a number between -1 and 1, e.g. -1 <= value <= 1.
$atanh returns values in radians. Use $radiansToDegrees operator to convert the output value from radians to degrees.
By default $atanh returns values as a double. $atanh can also return values as a 128-bit decimal as long as the expression resolves to a 128-bit decimal value.
tests:
-
name: 'Example'
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/atanh/#example'
pipeline:
-
$addFields:
y-coordinate:
$radiansToDegrees:
$atanh: '$x-coordinate'
13 changes: 13 additions & 0 deletions generator/config/expression/cos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,16 @@ arguments:
description: |
$cos takes any valid expression that resolves to a number. If the expression returns a value in degrees, use the $degreesToRadians operator to convert the result to radians.
By default $cos returns values as a double. $cos can also return values as a 128-bit decimal as long as the <expression> resolves to a 128-bit decimal value.
tests:
-
name: 'Example'
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/cos/#example'
pipeline:
-
$addFields:
side_a:
$multiply:
-
$cos:
$degreesToRadians: '$angle_a'
- '$hypotenuse'
10 changes: 10 additions & 0 deletions generator/config/expression/cosh.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,13 @@ arguments:
description: |
$cosh takes any valid expression that resolves to a number, measured in radians. If the expression returns a value in degrees, use the $degreesToRadians operator to convert the value to radians.
By default $cosh returns values as a double. $cosh can also return values as a 128-bit decimal if the <expression> resolves to a 128-bit decimal value.
tests:
-
name: 'Example'
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/cosh/#example'
pipeline:
-
$addFields:
cosh_output:
$cosh:
$degreesToRadians: '$angle'
13 changes: 13 additions & 0 deletions generator/config/expression/degreesToRadians.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,16 @@ arguments:
description: |
$degreesToRadians takes any valid expression that resolves to a number.
By default $degreesToRadians returns values as a double. $degreesToRadians can also return values as a 128-bit decimal as long as the <expression> resolves to a 128-bit decimal value.
tests:
-
name: 'Example'
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/degreesToRadians/#example'
pipeline:
-
$addFields:
angle_a_rad:
$degreesToRadians: '$angle_a'
angle_b_rad:
$degreesToRadians: '$angle_b'
angle_c_rad:
$degreesToRadians: '$angle_c'
13 changes: 13 additions & 0 deletions generator/config/expression/radiansToDegrees.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,16 @@ arguments:
name: expression
type:
- resolvesToNumber
tests:
-
name: 'Example'
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/radiansToDegrees/#example'
pipeline:
-
$addFields:
angle_a_deg:
$radiansToDegrees: '$angle_a'
angle_b_deg:
$radiansToDegrees: '$angle_b'
angle_c_deg:
$radiansToDegrees: '$angle_c'
13 changes: 13 additions & 0 deletions generator/config/expression/sin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,16 @@ arguments:
description: |
$sin takes any valid expression that resolves to a number. If the expression returns a value in degrees, use the $degreesToRadians operator to convert the result to radians.
By default $sin returns values as a double. $sin can also return values as a 128-bit decimal as long as the expression resolves to a 128-bit decimal value.
tests:
-
name: 'Example'
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/sin/#example'
pipeline:
-
$addFields:
side_b:
$multiply:
-
$sin:
$degreesToRadians: '$angle_a'
- '$hypotenuse'
10 changes: 10 additions & 0 deletions generator/config/expression/sinh.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,13 @@ arguments:
description: |
$sinh takes any valid expression that resolves to a number, measured in radians. If the expression returns a value in degrees, use the $degreesToRadians operator to convert the value to radians.
By default $sinh returns values as a double. $sinh can also return values as a 128-bit decimal if the expression resolves to a 128-bit decimal value.
tests:
-
name: 'Example'
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/sinh/#example'
pipeline:
-
$addFields:
sinh_output:
$sinh:
$degreesToRadians: '$angle'
13 changes: 13 additions & 0 deletions generator/config/expression/tan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,16 @@ arguments:
description: |
$tan takes any valid expression that resolves to a number. If the expression returns a value in degrees, use the $degreesToRadians operator to convert the result to radians.
By default $tan returns values as a double. $tan can also return values as a 128-bit decimal as long as the expression resolves to a 128-bit decimal value.
tests:
-
name: 'Example'
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/tan/#example'
pipeline:
-
$addFields:
side_b:
$multiply:
-
$tan:
$degreesToRadians: '$angle_a'
- '$side_a'
10 changes: 10 additions & 0 deletions generator/config/expression/tanh.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,13 @@ arguments:
description: |
$tanh takes any valid expression that resolves to a number, measured in radians. If the expression returns a value in degrees, use the $degreesToRadians operator to convert the value to radians.
By default $tanh returns values as a double. $tanh can also return values as a 128-bit decimal if the expression resolves to a 128-bit decimal value.
tests:
-
name: 'Example'
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/tanh/#example'
pipeline:
-
$addFields:
tanh_output:
$tanh:
$degreesToRadians: '$angle'
34 changes: 34 additions & 0 deletions tests/Builder/Expression/AcosOperatorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace MongoDB\Tests\Builder\Expression;

use MongoDB\Builder\Expression;
use MongoDB\Builder\Pipeline;
use MongoDB\Builder\Stage;
use MongoDB\Tests\Builder\PipelineTestCase;

/**
* Test $acos expression
*/
class AcosOperatorTest extends PipelineTestCase
{
public function testExample(): void
{
$pipeline = new Pipeline(
Stage::addFields(
angle_a: Expression::radiansToDegrees(
Expression::acos(
Expression::divide(
Expression::numberFieldPath('side_b'),
Expression::numberFieldPath('hypotenuse'),
),
),
),
),
);

$this->assertSamePipeline(Pipelines::AcosExample, $pipeline);
}
}
33 changes: 33 additions & 0 deletions tests/Builder/Expression/AcoshOperatorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace MongoDB\Tests\Builder\Expression;

use MongoDB\Builder\Expression;
use MongoDB\Builder\Pipeline;
use MongoDB\Builder\Stage;
use MongoDB\Tests\Builder\PipelineTestCase;

/**
* Test $acosh expression
*/
class AcoshOperatorTest extends PipelineTestCase
{
public function testExample(): void
{
$pipeline = new Pipeline(
Stage::addFields(
...[
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this only necessary because y-coordinate is an invalid parameter name?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. The name can't be used as named argument.

'y-coordinate' => Expression::radiansToDegrees(
Expression::acosh(
Expression::numberFieldPath('x-coordinate'),
),
),
],
),
);

$this->assertSamePipeline(Pipelines::AcoshExample, $pipeline);
}
}
34 changes: 34 additions & 0 deletions tests/Builder/Expression/AsinOperatorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace MongoDB\Tests\Builder\Expression;

use MongoDB\Builder\Expression;
use MongoDB\Builder\Pipeline;
use MongoDB\Builder\Stage;
use MongoDB\Tests\Builder\PipelineTestCase;

/**
* Test $asin expression
*/
class AsinOperatorTest extends PipelineTestCase
{
public function testExample(): void
{
$pipeline = new Pipeline(
Stage::addFields(
angle_a: Expression::radiansToDegrees(
Expression::asin(
Expression::divide(
Expression::numberFieldPath('side_a'),
Expression::numberFieldPath('hypotenuse'),
),
),
),
),
);

$this->assertSamePipeline(Pipelines::AsinExample, $pipeline);
}
}
33 changes: 33 additions & 0 deletions tests/Builder/Expression/AsinhOperatorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace MongoDB\Tests\Builder\Expression;

use MongoDB\Builder\Expression;
use MongoDB\Builder\Pipeline;
use MongoDB\Builder\Stage;
use MongoDB\Tests\Builder\PipelineTestCase;

/**
* Test $asinh expression
*/
class AsinhOperatorTest extends PipelineTestCase
{
public function testExample(): void
{
$pipeline = new Pipeline(
Stage::addFields(
...[
'y-coordinate' => Expression::radiansToDegrees(
Expression::asinh(
Expression::numberFieldPath('x-coordinate'),
),
),
],
),
);

$this->assertSamePipeline(Pipelines::AsinhExample, $pipeline);
}
}
Loading