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