Passed
Push — master ( 1f2e81...28a1aa )
by Andrii
01:21
created

PartitionSearchTest::prepareKdTree()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 10
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Search;
4
5
use KDTree\Interfaces\KDTreeInterface;
6
use KDTree\Search\PartitionSearch;
7
use KDTree\Structure\KDTree;
8
use KDTree\Structure\PointsList;
9
use KDTree\ValueObject\Partition;
10
use KDTree\ValueObject\Point;
11
use PHPUnit\Framework\TestCase;
12
13
class PartitionSearchTest extends TestCase
14
{
15
    public function testSearch(): void
16
    {
17
        $partitionSearch = new PartitionSearch($this->prepareKdTree());
18
        $pointsList = new PointsList(2);
19
        $pointsList->addPoint(new Point(80, 80))
20
            ->addPoint(new Point(99,99))
21
            ->addPoint(new Point(70, 70))
22
            ->addPoint(new Point(60, 70));
23
        $partition = new Partition($pointsList);
24
25
        $points = $partitionSearch->find($partition);
26
        $this->assertCount(1, $points);
27
        $this->assertEquals([91, 91], $points->current()->getAxises());
28
    }
29
30
    /**
31
     * @return KDTreeInterface
32
     */
33
    private function prepareKdTree(): KDTreeInterface
34
    {
35
        $kdTree = new KDTree(2);
36
        $kdTree->put(new Point(1, 1))
37
            ->put(new Point(3, 3))
38
            ->put(new Point(9, 9))
39
            ->put(new Point(91, 91))
40
            ->put(new Point(4, 4));
41
42
        return $kdTree;
43
    }
44
}
45