Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ExcludeLowPopulationTest.php « Filter « DataTable « Core « PHPUnit « tests - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 757c0104722e7c7ed05c1cb744cbf8e107700884 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
/**
 * Piwik - free/libre analytics platform
 *
 * @link http://piwik.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */
use Piwik\DataTable\Filter\ExcludeLowPopulation;
use Piwik\DataTable;
use Piwik\DataTable\Row;

class DataTable_Filter_ExcludeLowPopulationTest extends PHPUnit_Framework_TestCase
{
    protected function getTestDataTable()
    {
        $table = new DataTable;
        $table->addRowsFromArray(
            array(
                 array(Row::COLUMNS => array('label' => 'zero', 'count' => 0)),
                 array(Row::COLUMNS => array('label' => 'one', 'count' => 1)),
                 array(Row::COLUMNS => array('label' => 'onedotfive', 'count' => 1.5)),
                 array(Row::COLUMNS => array('label' => 'ten', 'count' => 10)),
                 array(Row::COLUMNS => array('label' => 'ninety', 'count' => 90)),
                 array(Row::COLUMNS => array('label' => 'hundred', 'count' => 100)),
            )
        );
        return $table;
    }

    /**
     * @group Core
     **/
    public function testStandardTable()
    {
        $table = $this->getTestDataTable();
        $filter = new ExcludeLowPopulation($table, 'count', 1.1);
        $filter->filter($table);
        $this->assertEquals(4, $table->getRowsCount());
        $this->assertEquals(array(1.5, 10, 90, 100), $table->getColumn('count'));
    }

    /**
     * @group Core
     **/
    public function testFilterEqualOneDoesFilter()
    {
        $table = $this->getTestDataTable();
        $filter = new ExcludeLowPopulation($table, 'count', 1);
        $filter->filter($table);
        $this->assertEquals(5, $table->getRowsCount());
    }

    /**
     * @group Core
     **/
    public function testFilterEqualZeroDoesFilter()
    {
        $table = $this->getTestDataTable();
        $filter = new ExcludeLowPopulation($table, 'count', 0);
        $filter->filter($table);
        $this->assertEquals(3, $table->getRowsCount());
        $this->assertEquals(array(10, 90, 100), $table->getColumn('count'));
    }

    /**
     * @group Core
    */
    public function testFilterSpecifyExcludeLowPopulationThresholdDoesFilter()
    {
        $table = $this->getTestDataTable();
        $filter = new ExcludeLowPopulation($table, 'count', 0, 0.4); //40%
        $filter->filter($table);
        $this->assertEquals(2, $table->getRowsCount());
        $this->assertEquals(array(90, 100), $table->getColumn('count'));
    }


    /**
     * 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)), //0
            array($idcol => array('label' => 'ask', 'nb_visits' => -152)), //1
            array($idcol => array('label' => 'piwik', 'nb_visits' => 1.5)), //2
            array($idcol => array('label' => 'piwik2', 'nb_visits' => 1.4)), //2
            array($idcol => array('label' => 'yahoo', 'nb_visits' => 154)), //3
            array($idcol => array('label' => 'amazon', 'nb_visits' => 30)), //4
            array($idcol => array('label' => '238949', 'nb_visits' => 0)), //5
            array($idcol => array('label' => 'Q*(%&*', 'nb_visits' => 1)), //6
            array($idcol => array('label' => 'Q*(%&*2', 'nb_visits' => -1.5)), //6
        );
        $table->addRowsFromArray($rows);

        $expectedtable = new DataTable();
        $rows = array(
            array($idcol => array('label' => 'google', 'nb_visits' => 897)), //0
            array($idcol => array('label' => 'piwik', 'nb_visits' => 1.5)), //2
            array($idcol => array('label' => 'piwik2', 'nb_visits' => 1.4)), //2
            array($idcol => array('label' => 'yahoo', 'nb_visits' => 154)), //3
            array($idcol => array('label' => 'amazon', 'nb_visits' => 30)), //4
        );
        $expectedtable->addRowsFromArray($rows);

        $filter = new ExcludeLowPopulation($table, 'nb_visits', 1.4);
        $filter->filter($table);

        $this->assertTrue(DataTable::isEqual($table, $expectedtable));
    }
}