Skip to content

Commit

Permalink
Fix types accepted by $round (#1401)
Browse files Browse the repository at this point in the history
  • Loading branch information
GromNaN authored Sep 16, 2024
1 parent 7093d9b commit f2842bc
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 13 deletions.
20 changes: 15 additions & 5 deletions generator/config/expression/round.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,12 @@ type:
- resolvesToLong
encode: array
description: |
Rounds a number to to a whole integer or to a specified decimal place.
Rounds a number to a whole integer or to a specified decimal place.
arguments:
-
name: number
type:
- resolvesToInt
- resolvesToDouble
- resolvesToDecimal
- resolvesToLong
- resolvesToNumber
description: |
Can be any valid expression that resolves to a number. Specifically, the expression must resolve to an integer, double, decimal, or long.
$round returns an error if the expression resolves to a non-numeric data type.
Expand All @@ -38,3 +35,16 @@ tests:
$round:
- '$value'
- 1
-
name: 'Round Average Rating'
pipeline:
-
$project:
roundedAverageRating:
$avg:
-
$round:
-
$avg:
- '$averageRating'
- 2
6 changes: 3 additions & 3 deletions src/Builder/Expression/FactoryTrait.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions src/Builder/Expression/RoundOperator.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions tests/Builder/Expression/Pipelines.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions tests/Builder/Expression/RoundOperatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,22 @@ public function testExample(): void

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

public function testRoundAverageRating(): void
{
$pipeline = new Pipeline(
Stage::project(
roundedAverageRating: Expression::avg(
Expression::round(
Expression::avg(
Expression::doubleFieldPath('averageRating'),
),
2,
),
),
),
);

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

0 comments on commit f2842bc

Please sign in to comment.