Passed
Push — master ( 645ae2...0beaa6 )
by Andrii
01:35
created

KDTreeTest::testDelete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 8
rs 10
1
<?php
2
3
namespace Structure;
4
5
use KDTree\Exceptions\InvalidDimensionsCount;
6
use KDTree\Exceptions\PointAlreadyExists;
7
use KDTree\Structure\KDTree;
8
use KDTree\ValueObject\Point;
9
use PHPUnit\Framework\TestCase;
10
11
class KDTreeTest extends TestCase
12
{
13
    public function testEmptyConstruction(): void
14
    {
15
        $dimensions = 2;
16
        $kdTree = new KDTree($dimensions);
17
18
        $this->assertEquals(0, $kdTree->size());
19
        $this->assertTrue($kdTree->isEmpty());
20
        $this->assertEquals($dimensions, $kdTree->getDimensions());
21
        $this->assertNull($kdTree->getRoot());
22
    }
23
24
    public function testInvalidDimensionsCount()
25
    {
26
        $this->expectException(InvalidDimensionsCount::class);
27
        new KDTree(0);
28
    }
29
30
    public function testPut(): void
31
    {
32
        $point = new Point(1, 1);
33
        $kdTree = new KDTree(2);
34
        $kdTree->put($point);
35
36
        $this->assertTrue($kdTree->contains($point));
37
        $this->assertEquals(1, $kdTree->size());
38
        $this->assertEquals($point, $kdTree->points()->current());
39
        $this->assertEquals($point, $kdTree->getRoot()->getPoint());
40
41
        $this->expectException(PointAlreadyExists::class);
42
        $kdTree->put($point);
43
    }
44
45
    public function testDelete(): void
46
    {
47
        $point = new Point(1, 1);
48
        $kdTree = new KDTree(2);
49
        $kdTree->put($point);
50
        $kdTree->delete($point);
51
52
        $this->assertFalse($kdTree->contains($point));
53
    }
54
}
55