Skip to content

Commit 4426cf0

Browse files
committed
Fix types accepted by $round
1 parent 0ed8dff commit 4426cf0

File tree

5 files changed

+59
-13
lines changed

5 files changed

+59
-13
lines changed

generator/config/expression/round.yaml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,12 @@ type:
88
- resolvesToLong
99
encode: array
1010
description: |
11-
Rounds a number to to a whole integer or to a specified decimal place.
11+
Rounds a number to a whole integer or to a specified decimal place.
1212
arguments:
1313
-
1414
name: number
1515
type:
16-
- resolvesToInt
17-
- resolvesToDouble
18-
- resolvesToDecimal
19-
- resolvesToLong
16+
- resolvesToNumber
2017
description: |
2118
Can be any valid expression that resolves to a number. Specifically, the expression must resolve to an integer, double, decimal, or long.
2219
$round returns an error if the expression resolves to a non-numeric data type.
@@ -38,3 +35,14 @@ tests:
3835
$round:
3936
- '$value'
4037
- 1
38+
-
39+
name: 'Round Average Rating'
40+
pipeline:
41+
-
42+
$project:
43+
roundedAverageRating:
44+
$round:
45+
-
46+
$avg:
47+
- '$averageRating'
48+
- 2

src/Builder/Expression/FactoryTrait.php

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Builder/Expression/RoundOperator.php

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/Builder/Expression/Pipelines.php

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/Builder/Expression/RoundOperatorTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,20 @@ public function testExample(): void
2727

2828
$this->assertSamePipeline(Pipelines::RoundExample, $pipeline);
2929
}
30+
31+
public function testRoundAverageRating(): void
32+
{
33+
$pipeline = new Pipeline(
34+
Stage::project(
35+
roundedAverageRating: Expression::round(
36+
Expression::avg(
37+
Expression::doubleFieldPath('averageRating'),
38+
),
39+
2,
40+
),
41+
),
42+
);
43+
44+
$this->assertSamePipeline(Pipelines::RoundRoundAverageRating, $pipeline);
45+
}
3046
}

0 commit comments

Comments
 (0)