|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <[email protected]> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Symfony\UX\Map\Tests\Cluster; |
| 13 | + |
| 14 | +use PHPUnit\Framework\TestCase; |
| 15 | +use Symfony\UX\Map\Cluster\Cluster; |
| 16 | +use Symfony\UX\Map\Point; |
| 17 | + |
| 18 | +class ClusterTest extends TestCase |
| 19 | +{ |
| 20 | + public function testAddPointAndGetCenter(): void |
| 21 | + { |
| 22 | + $point1 = new Point(10.0, 20.0); |
| 23 | + $cluster = new Cluster($point1); |
| 24 | + |
| 25 | + $this->assertEquals(10.0, $cluster->getCenterLat()); |
| 26 | + $this->assertEquals(20.0, $cluster->getCenterLng()); |
| 27 | + |
| 28 | + $point2 = new Point(12.0, 22.0); |
| 29 | + $cluster->addPoint($point2); |
| 30 | + |
| 31 | + $this->assertEquals(11.0, $cluster->getCenterLat()); |
| 32 | + $this->assertEquals(21.0, $cluster->getCenterLng()); |
| 33 | + } |
| 34 | + |
| 35 | + public function testGetPoints(): void |
| 36 | + { |
| 37 | + $point1 = new Point(10.0, 20.0); |
| 38 | + $point2 = new Point(12.0, 22.0); |
| 39 | + $cluster = new Cluster($point1); |
| 40 | + $cluster->addPoint($point2); |
| 41 | + |
| 42 | + $points = $cluster->getPoints(); |
| 43 | + $this->assertCount(2, $points); |
| 44 | + $this->assertSame($point1, $points[0]); |
| 45 | + $this->assertSame($point2, $points[1]); |
| 46 | + } |
| 47 | + |
| 48 | + public function testEmptyCluster(): void |
| 49 | + { |
| 50 | + $point1 = new Point(10.0, 20.0); |
| 51 | + $cluster = new Cluster($point1); // Start an empty cluster |
| 52 | + $points = $cluster->getPoints(); |
| 53 | + $this->assertCount(1, $points); |
| 54 | + $this->assertEquals(10.0, $cluster->getCenterLat()); |
| 55 | + $this->assertEquals(20.0, $cluster->getCenterLng()); |
| 56 | + } |
| 57 | +} |
0 commit comments