Skip to content

Commit f2842bc

Browse files
authored
Fix types accepted by $round (#1401)
1 parent 7093d9b commit f2842bc

File tree

5 files changed

+67
-13
lines changed

5 files changed

+67
-13
lines changed

generator/config/expression/round.yaml

Lines changed: 15 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,16 @@ tests:
3835
$round:
3936
- '$value'
4037
- 1
38+
-
39+
name: 'Round Average Rating'
40+
pipeline:
41+
-
42+
$project:
43+
roundedAverageRating:
44+
$avg:
45+
-
46+
$round:
47+
-
48+
$avg:
49+
- '$averageRating'
50+
- 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: 26 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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,22 @@ 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::avg(
36+
Expression::round(
37+
Expression::avg(
38+
Expression::doubleFieldPath('averageRating'),
39+
),
40+
2,
41+
),
42+
),
43+
),
44+
);
45+
46+
$this->assertSamePipeline(Pipelines::RoundRoundAverageRating, $pipeline);
47+
}
3048
}

0 commit comments

Comments
 (0)