public function testAggregationValueContainerRemoveClear()
 {
     $a = new \CrazyCodr\Data\Grouper\GroupResult();
     $a->addAggregationValue(6, 'test1');
     $a->addAggregationValue(6, 'test2');
     $a->addAggregationValue(6, 'test3');
     $a->addAggregationValue(6, 'test4');
     $this->assertCount(4, $a->getAggregationValues());
     $a->removeAggregationValue('test4');
     $this->assertCount(3, $a->getAggregationValues());
     $a->clearAggregationValues();
     $this->assertCount(0, $a->getAggregationValues());
 }
Esempio n. 2
0
 public function testProcess()
 {
     //Create the GroupResult
     $a = new \CrazyCodr\Data\Grouper\GroupResult();
     //Prepare the data
     $data = array(array('name' => 'Mathieu', 'type' => 'programmer', 'sex' => 'male', 'age' => 30), array('name' => 'David', 'type' => 'manager', 'sex' => 'male', 'age' => 35), array('name' => 'Jean-Michel', 'type' => 'manager', 'sex' => 'male', 'age' => 30), array('name' => 'Frédéric', 'type' => 'integrator', 'sex' => 'male', 'age' => 25), array('name' => 'Éric', 'type' => 'integrator', 'sex' => 'male', 'age' => 30), array('name' => 'Philippe', 'type' => 'designer', 'sex' => 'male', 'age' => 30), array('name' => 'Caroline', 'type' => 'project manager', 'sex' => 'female', 'age' => 30), array('name' => 'Joelle', 'type' => 'project manager', 'sex' => 'female', 'age' => 30), array('name' => 'Jocelyne', 'type' => 'project manager', 'sex' => 'female', 'age' => 45), array('name' => 'Capucine', 'type' => 'sales', 'sex' => 'female', 'age' => 30), array('name' => 'Françis', 'type' => 'sales', 'sex' => 'male', 'age' => 30), array('name' => 'Manon', 'type' => 'manager', 'sex' => 'female', 'age' => 45));
     //Process each line and test the count
     foreach ($data as $row_key => $row_data) {
         $a->process($row_data, $row_key, array(), array());
     }
     //Check the count
     $this->assertCount(12, $a->getData());
     $a->clear();
     //Add a group to the lot
     $sex_grouper = new \CrazyCodr\Data\Grouper\ClosureGrouper(function ($a) {
         return $a['sex'];
     }, $groupName = 'sex');
     $groupers[] = $sex_grouper;
     //Process each line and test the count
     foreach ($data as $row_key => $row_data) {
         $a->process($row_data, $row_key, $groupers, array());
     }
     //Check the count of data items which should be the same as we are not actually grouping at this level
     $this->assertCount(12, $a->getData());
     //Check there are resulting groups (2)
     $this->assertCount(2, $a->getGroups());
     //Check that each group should exist
     $this->assertTrue($a->hasGroup('male'));
     $this->assertTrue($a->hasGroup('female'));
     //Check that each group contains the expected data
     $this->assertCount(7, $a->getGroup('male')->getData());
     $this->assertCount(5, $a->getGroup('female')->getData());
     //Add some aggregators to the lot, clear up and reset
     $a->clear();
     //Add aggregators to the lot
     $average_age_aggregator = new \CrazyCodr\Data\Grouper\AverageClosureAggregator(function ($a) {
         return $a['age'];
     }, $groupName = 'average_age');
     $aggregators[] = $average_age_aggregator;
     //Process each line and test
     foreach ($data as $row_key => $row_data) {
         $a->process($row_data, $row_key, $groupers, $aggregators);
     }
     //Check the count of data items which should be the same as we are not actually grouping at this level
     //Also check the aggregator now
     $this->assertCount(12, $a->getData());
     $this->assertTrue($a->hasAggregationValue('average_age'));
     $this->assertEquals(32.5, $a->getAggregationValue('average_age'));
     //Check there are resulting groups (2)
     $this->assertCount(2, $a->getGroups());
     //Check that each group should exist
     $this->assertTrue($a->hasGroup('male'));
     $this->assertTrue($a->hasGroup('female'));
     //Check that each group contains the expected data
     //Alos check the aggregator
     $this->assertCount(7, $a->getGroup('male')->getData());
     $this->assertCount(5, $a->getGroup('female')->getData());
     $this->assertTrue($a->getGroup('male')->hasAggregationValue('average_age'));
     $this->assertEquals(30, $a->getGroup('male')->getAggregationValue('average_age'));
     $this->assertTrue($a->getGroup('female')->hasAggregationValue('average_age'));
     $this->assertEquals(36, $a->getGroup('female')->getAggregationValue('average_age'));
 }