isEqual() public static method

DataTables are equal if they have the same number of rows, if each row has a label that exists in the other table, and if each row is equal to the row in the other table with the same label. The order of rows is not important.
public static isEqual ( DataTable $table1, DataTable $table2 ) : boolean
$table1 DataTable
$table2 DataTable
return boolean
コード例 #1
0
 /**
  * Test to exclude low population filter
  *
  * @group Core
  */
 public function testFilterLowpop1()
 {
     $idcol = Row::COLUMNS;
     $table = new DataTable();
     $rows = array(array($idcol => array('label' => 'google', 'nb_visits' => 897)), array($idcol => array('label' => 'ask', 'nb_visits' => -152)), array($idcol => array('label' => 'piwik', 'nb_visits' => 1.5)), array($idcol => array('label' => 'piwik2', 'nb_visits' => 1.4)), array($idcol => array('label' => 'yahoo', 'nb_visits' => 154)), array($idcol => array('label' => 'amazon', 'nb_visits' => 30)), array($idcol => array('label' => '238949', 'nb_visits' => 0)), array($idcol => array('label' => 'Q*(%&*', 'nb_visits' => 1)), array($idcol => array('label' => 'Q*(%&*2', 'nb_visits' => -1.5)));
     $table->addRowsFromArray($rows);
     $expectedtable = new DataTable();
     $rows = array(array($idcol => array('label' => 'google', 'nb_visits' => 897)), array($idcol => array('label' => 'piwik', 'nb_visits' => 1.5)), array($idcol => array('label' => 'piwik2', 'nb_visits' => 1.4)), array($idcol => array('label' => 'yahoo', 'nb_visits' => 154)), array($idcol => array('label' => 'amazon', 'nb_visits' => 30)));
     $expectedtable->addRowsFromArray($rows);
     $filter = new ExcludeLowPopulation($table, 'nb_visits', 1.4);
     $filter->filter($table);
     $this->assertTrue(DataTable::isEqual($table, $expectedtable));
 }
コード例 #2
0
ファイル: TruncateTest.php プロジェクト: mgou-net/piwik
 public function testAddOneTableWithSummaryRow()
 {
     // row0, row1, row2, rowSummary1
     $table1 = $this->getDataTableCount5();
     $filter = new Truncate($table1, 3);
     $filter->filter($table1);
     // row0, row1, row2, row3, row4
     $table2 = $this->getDataTableCount5();
     // we expect row0+row0, row1+row1, row2+row2, row3, row4, rowSummary1
     $expectedTable = new DataTable();
     $expectedTable->addRow(new Row(array(Row::COLUMNS => array('label' => 'amazon', 'nb' => 20000))));
     $expectedTable->addRow(new Row(array(Row::COLUMNS => array('label' => 'yahoo', 'nb' => 2000))));
     $expectedTable->addRow(new Row(array(Row::COLUMNS => array('label' => 'piwik', 'nb' => 200))));
     $expectedTable->addRow($this->getRow3());
     $expectedTable->addRow($this->getRow4());
     $expectedTable->addRow(new Row(array(Row::COLUMNS => array('label' => DataTable::LABEL_SUMMARY_ROW, 'nb' => 11))));
     $table1->addDataTable($table2);
     $this->assertTrue(DataTable::isEqual($expectedTable, $table1));
 }
コード例 #3
0
 /**
  * test add 2 different tables to the same table
  */
 public function testAddDataTable2times()
 {
     $idcol = Row::COLUMNS;
     $rows = array(array($idcol => array('label' => 'google', 'visits' => 1)), array($idcol => array('label' => 'ask', 'visits' => 0)), array($idcol => array('label' => '123', 'visits' => 2)), DataTable::ID_SUMMARY_ROW => array($idcol => array('label' => DataTable::LABEL_SUMMARY_ROW, 'visits' => 1)));
     $table = new DataTable();
     $table->addRowsFromArray($rows);
     $rows2 = array(array($idcol => array('label' => 'google2', 'visits' => -1)), array($idcol => array('label' => 'ask', 'visits' => 100)), array($idcol => array('label' => '123456', 'visits' => 1.5)));
     $table2 = new DataTable();
     $table2->addRowsFromArray($rows2);
     $rows3 = array(array($idcol => array('label' => 'google2', 'visits' => -1)), array($idcol => array('label' => 'ask', 'visits' => -10)), array($idcol => array('label' => '123ab', 'visits' => 1.5)), DataTable::ID_SUMMARY_ROW => array($idcol => array('label' => DataTable::LABEL_SUMMARY_ROW, 'visits' => 3)));
     $table3 = new DataTable();
     $table3->addRowsFromArray($rows3);
     // add the 2 tables
     $table->addDataTable($table2);
     $table->addDataTable($table3);
     $rowsExpected = array(array($idcol => array('label' => 'google', 'visits' => 1)), array($idcol => array('label' => 'ask', 'visits' => 90)), array($idcol => array('label' => '123', 'visits' => 2)), array($idcol => array('label' => 'google2', 'visits' => -2)), array($idcol => array('label' => '123456', 'visits' => 1.5)), array($idcol => array('label' => '123ab', 'visits' => 1.5)), DataTable::ID_SUMMARY_ROW => array($idcol => array('label' => DataTable::LABEL_SUMMARY_ROW, 'visits' => 4)));
     $tableExpected = new DataTable();
     $tableExpected->addRowsFromArray($rowsExpected);
     $this->assertTrue(DataTable::isEqual($table, $tableExpected));
 }
コード例 #4
0
ファイル: Row.php プロジェクト: josl/CGE-File-Sharing
 /**
  * Helper function that tests if two rows are equal.
  *
  * Two rows are equal if:
  *
  * - they have exactly the same columns / metadata
  * - they have a subDataTable associated, then we check that both of them are the same.
  *
  * Column order is not important.
  *
  * @param \Piwik\DataTable\Row $row1 first to compare
  * @param \Piwik\DataTable\Row $row2 second to compare
  * @return bool
  */
 public static function isEqual(Row $row1, Row $row2)
 {
     //same columns
     $cols1 = $row1->getColumns();
     $cols2 = $row2->getColumns();
     $diff1 = array_udiff($cols1, $cols2, array(__CLASS__, 'compareElements'));
     $diff2 = array_udiff($cols2, $cols1, array(__CLASS__, 'compareElements'));
     if ($diff1 != $diff2) {
         return false;
     }
     $dets1 = $row1->getMetadata();
     $dets2 = $row2->getMetadata();
     ksort($dets1);
     ksort($dets2);
     if ($dets1 != $dets2) {
         return false;
     }
     // either both are null
     // or both have a value
     if (!(is_null($row1->getIdSubDataTable()) && is_null($row2->getIdSubDataTable()))) {
         $subtable1 = $row1->getSubtable();
         $subtable2 = $row2->getSubtable();
         if (!DataTable::isEqual($subtable1, $subtable2)) {
             return false;
         }
     }
     return true;
 }
コード例 #5
0
ファイル: SortTest.php プロジェクト: carriercomm/piwik
 /**
  * Test to sort by visit
  *
  * @group Core
  */
 public function testFilterSortNumeric()
 {
     $idcol = Row::COLUMNS;
     $table = new DataTable();
     $rows = array(array($idcol => array('label' => 'google', 'nb_visits' => 897)), array($idcol => array('label' => 'ask', 'nb_visits' => -152)), array($idcol => array('label' => 'piwik', 'nb_visits' => 1.5)), array($idcol => array('label' => 'yahoo', 'nb_visits' => 154)), array($idcol => array('label' => 'amazon', 'nb_visits' => 30)), array($idcol => array('label' => '238949', 'nb_visits' => 0)), array($idcol => array('label' => 'Q*(%&*', 'nb_visits' => 1)));
     $table->addRowsFromArray($rows);
     $expectedtable = new DataTable();
     $rows = array(array($idcol => array('label' => 'ask', 'nb_visits' => -152)), array($idcol => array('label' => '238949', 'nb_visits' => 0)), array($idcol => array('label' => 'Q*(%&*', 'nb_visits' => 1)), array($idcol => array('label' => 'piwik', 'nb_visits' => 1.5)), array($idcol => array('label' => 'amazon', 'nb_visits' => 30)), array($idcol => array('label' => 'yahoo', 'nb_visits' => 154)), array($idcol => array('label' => 'google', 'nb_visits' => 897)));
     $expectedtable->addRowsFromArray($rows);
     $expectedtableReverse = new DataTable();
     $expectedtableReverse->addRowsFromArray(array_reverse($rows));
     $filter = new Sort($table, 'nb_visits', 'asc');
     $filter->filter($table);
     $this->assertTrue(DataTable::isEqual($table, $expectedtable));
     $filter = new Sort($table, 'nb_visits', 'desc');
     $filter->filter($table);
     $this->assertTrue(DataTable::isEqual($table, $expectedtableReverse));
 }
コード例 #6
0
ファイル: SortTest.php プロジェクト: FluentDevelopment/piwik
 public function test_sortingArrayValues_doesNotError()
 {
     $table = new DataTable();
     $table->addRowsFromArray(array(array(Row::COLUMNS => array('label' => 'ask', 'count_array' => array(100, 1, 2))), array(Row::COLUMNS => array('label' => 'nintendo', 'count_array' => array(0, 'hello'))), array(Row::COLUMNS => array('label' => 'yahoo', 'count_array' => array(10, 'test')))));
     $tableOriginal = clone $table;
     $filter = new Sort($table, 'count_array', 'desc');
     $filter->filter($table);
     $this->assertTrue(DataTable::isEqual($tableOriginal, $table));
 }
コード例 #7
0
ファイル: RowTest.php プロジェクト: TensorWrenchOSS/piwik
 public function test_sumSubTable_whenSubTableAlreadyExists_overwriteExistingSubtable()
 {
     $testRow = $this->getTestRowWithSubDataTableNotLoaded();
     $this->assertFalse($testRow->isSubtableLoaded());
     $subTable = $this->getTestSubDataTable();
     $testRow->setSubtable($subTable);
     $testRow->switchFlagSubtableIsLoaded();
     $this->assertFalse($testRow->isSubtableLoaded());
     $testRow->sumSubtable($subTable);
     $this->assertTrue(DataTable::isEqual($testRow->getSubtable(), $subTable));
 }