| @@ 18-31 (lines=14) @@ | ||
| 15 | /** |
|
| 16 | * @group functional |
|
| 17 | */ |
|
| 18 | public function testAvgAggregation(): void |
|
| 19 | { |
|
| 20 | $agg = new Avg('avg'); |
|
| 21 | $agg->setField('price'); |
|
| 22 | ||
| 23 | $query = new Query(); |
|
| 24 | $query->addAggregation($agg); |
|
| 25 | ||
| 26 | $resultSet = $this->_getIndexForTest()->search($query); |
|
| 27 | $results = $resultSet->getAggregations(); |
|
| 28 | ||
| 29 | $this->assertTrue($resultSet->hasAggregations()); |
|
| 30 | $this->assertEquals((5 + 8 + 1 + 3) / 4.0, $results['avg']['value']); |
|
| 31 | } |
|
| 32 | ||
| 33 | /** |
|
| 34 | * @group functional |
|
| @@ 36-50 (lines=15) @@ | ||
| 33 | /** |
|
| 34 | * @group functional |
|
| 35 | */ |
|
| 36 | public function testAvgAggregationWithMissingValue(): void |
|
| 37 | { |
|
| 38 | $agg = new Avg('avg'); |
|
| 39 | $agg->setField('price'); |
|
| 40 | $agg->setMissing(72); |
|
| 41 | ||
| 42 | $query = new Query(); |
|
| 43 | $query->addAggregation($agg); |
|
| 44 | ||
| 45 | $resultSet = $this->_getIndexForTest()->search($query); |
|
| 46 | $results = $resultSet->getAggregations(); |
|
| 47 | ||
| 48 | $this->assertTrue($resultSet->hasAggregations()); |
|
| 49 | $this->assertEquals((5 + 8 + 1 + 3 + 72) / 5.0, $results['avg']['value']); |
|
| 50 | } |
|
| 51 | ||
| 52 | protected function _getIndexForTest(): Index |
|
| 53 | { |
|