Skip to content

Commit

Permalink
Fix types accepted by $round
Browse files Browse the repository at this point in the history
  • Loading branch information
GromNaN committed Sep 13, 2024
1 parent 0ed8dff commit 4426cf0
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 13 deletions.
18 changes: 13 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,14 @@ tests:
$round:
- '$value'
- 1
-
name: 'Round Average Rating'
pipeline:
-
$project:
roundedAverageRating:
$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.

22 changes: 22 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.

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

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

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

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

0 comments on commit 4426cf0

Please sign in to comment.