-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
count
aggregate rule. Update wording in error messages (#38)
Introduced a new aggregate rule, ComboCount in Csv-Blueprint. This counts the total number of rows in the CSV file. Also updated the existing 'average' aggregate rules to convert array values to float before calculation. The schema examples and README are updated to demonstrate the new 'count' aggregate rule. A new test case for the 'count' rule has also been added.
- Loading branch information
Showing
12 changed files
with
176 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
/** | ||
* JBZoo Toolbox - Csv-Blueprint. | ||
* | ||
* This file is part of the JBZoo Toolbox project. | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @license MIT | ||
* @copyright Copyright (C) JBZoo.com, All rights reserved. | ||
* @see https://github.com/JBZoo/Csv-Blueprint | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace JBZoo\CsvBlueprint\Rules\Aggregate; | ||
|
||
final class ComboCount extends AbstarctAggregateRuleCombo | ||
{ | ||
protected const NAME = 'count of rows'; | ||
|
||
protected const HELP_TOP = [ | ||
'Total(!) count of rows in the CSV file.', | ||
'Since any values are taken into account, it only makes sense to use these rules once in any column.', | ||
]; | ||
|
||
protected const HELP_OPTIONS = [ | ||
self::EQ => ['5', ''], | ||
self::NOT => ['4', ''], | ||
self::MIN => ['1', ''], | ||
self::MAX => ['10', ''], | ||
]; | ||
|
||
protected function getActualAggregate(array $colValues): float | ||
{ | ||
return \count($colValues); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php | ||
|
||
/** | ||
* JBZoo Toolbox - Csv-Blueprint. | ||
* | ||
* This file is part of the JBZoo Toolbox project. | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @license MIT | ||
* @copyright Copyright (C) JBZoo.com, All rights reserved. | ||
* @see https://github.com/JBZoo/Csv-Blueprint | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace JBZoo\PHPUnit\Rules\Aggregate; | ||
|
||
use JBZoo\CsvBlueprint\Rules\AbstarctRule as Combo; | ||
use JBZoo\CsvBlueprint\Rules\Aggregate\ComboCount; | ||
use JBZoo\PHPUnit\Rules\AbstractAggregateRuleCombo; | ||
|
||
use function JBZoo\PHPUnit\isSame; | ||
|
||
class ComboCountTest extends AbstractAggregateRuleCombo | ||
{ | ||
protected string $ruleClass = ComboCount::class; | ||
|
||
public function testEqual(): void | ||
{ | ||
$rule = $this->create(3, Combo::EQ); | ||
|
||
isSame('', $rule->test(['1', '2', '3'])); | ||
|
||
isSame( | ||
'The count of rows in the column is "4", which is not equal than the expected "3"', | ||
$rule->test(['1', '2', '3', '4.5']), | ||
); | ||
} | ||
|
||
public function testNotEqual(): void | ||
{ | ||
$rule = $this->create(3, Combo::NOT); | ||
|
||
isSame('', $rule->test(['1', '2', '3', '4.5'])); | ||
|
||
isSame( | ||
'The count of rows in the column is "3", which is equal than the not expected "3"', | ||
$rule->test(['1', '2', '3']), | ||
); | ||
} | ||
|
||
public function testMin(): void | ||
{ | ||
$rule = $this->create(3, Combo::MIN); | ||
|
||
isSame('', $rule->test(['1', '2', '3'])); | ||
|
||
isSame( | ||
'The count of rows in the column is "2", which is less than the expected "3"', | ||
$rule->test(['1', '2']), | ||
); | ||
} | ||
|
||
public function testMax(): void | ||
{ | ||
$rule = $this->create(3, Combo::MAX); | ||
|
||
isSame('', $rule->test(['1', '2', '3'])); | ||
|
||
isSame( | ||
'The count of rows in the column is "4", which is greater than the expected "3"', | ||
$rule->test(['1', '2', '3', '4.5']), | ||
); | ||
} | ||
|
||
public function testInvalidOption(): void | ||
{ | ||
$this->expectExceptionMessage( | ||
'Invalid option "[1, 2]" for the "ag:count_max" rule. It should be integer/float.', | ||
); | ||
$rule = $this->create([1, 2], Combo::MAX); | ||
$rule->validate(['1', '2', '3']); | ||
} | ||
|
||
public function testInvalidParsing(): void | ||
{ | ||
$rule = $this->create(0, Combo::EQ); | ||
isSame('', $rule->test([])); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters