|
| 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\AI\Platform\Tests\Bridge\HuggingFace\Output; |
| 13 | + |
| 14 | +use PHPUnit\Framework\Attributes\CoversClass; |
| 15 | +use PHPUnit\Framework\Attributes\Small; |
| 16 | +use PHPUnit\Framework\Attributes\TestDox; |
| 17 | +use PHPUnit\Framework\Attributes\TestWith; |
| 18 | +use PHPUnit\Framework\TestCase; |
| 19 | +use Symfony\AI\Platform\Bridge\HuggingFace\Output\DetectedObject; |
| 20 | + |
| 21 | +/** |
| 22 | + * @author Oskar Stark <[email protected]> |
| 23 | + */ |
| 24 | +#[CoversClass(DetectedObject::class)] |
| 25 | +#[Small] |
| 26 | +final class DetectedObjectTest extends TestCase |
| 27 | +{ |
| 28 | + #[TestDox('Construction with all parameters creates valid instance')] |
| 29 | + public function testConstruction() |
| 30 | + { |
| 31 | + $object = new DetectedObject( |
| 32 | + label: 'person', |
| 33 | + score: 0.95, |
| 34 | + xmin: 10.5, |
| 35 | + ymin: 20.5, |
| 36 | + xmax: 100.5, |
| 37 | + ymax: 200.5 |
| 38 | + ); |
| 39 | + |
| 40 | + $this->assertSame('person', $object->label); |
| 41 | + $this->assertSame(0.95, $object->score); |
| 42 | + $this->assertSame(10.5, $object->xmin); |
| 43 | + $this->assertSame(20.5, $object->ymin); |
| 44 | + $this->assertSame(100.5, $object->xmax); |
| 45 | + $this->assertSame(200.5, $object->ymax); |
| 46 | + } |
| 47 | + |
| 48 | + #[TestDox('Constructor accepts various bounding box coordinates')] |
| 49 | + #[TestWith(['car', 0.88, 0.0, 0.0, 50.0, 50.0])] |
| 50 | + #[TestWith(['dog', 0.75, -10.0, -10.0, 10.0, 10.0])] |
| 51 | + #[TestWith(['tree', 0.6, 100.5, 200.5, 300.5, 400.5])] |
| 52 | + #[TestWith(['building', 0.99, 0.0, 0.0, 1920.0, 1080.0])] |
| 53 | + #[TestWith(['', 0.5, 1.0, 2.0, 3.0, 4.0])] |
| 54 | + public function testConstructorWithVariousValues( |
| 55 | + string $label, |
| 56 | + float $score, |
| 57 | + float $xmin, |
| 58 | + float $ymin, |
| 59 | + float $xmax, |
| 60 | + float $ymax, |
| 61 | + ) { |
| 62 | + $object = new DetectedObject($label, $score, $xmin, $ymin, $xmax, $ymax); |
| 63 | + |
| 64 | + $this->assertSame($label, $object->label); |
| 65 | + $this->assertSame($score, $object->score); |
| 66 | + $this->assertSame($xmin, $object->xmin); |
| 67 | + $this->assertSame($ymin, $object->ymin); |
| 68 | + $this->assertSame($xmax, $object->xmax); |
| 69 | + $this->assertSame($ymax, $object->ymax); |
| 70 | + } |
| 71 | + |
| 72 | + #[TestDox('Constructor handles various edge cases and patterns')] |
| 73 | + #[TestWith(['person', 0.0, 0.0, 0.0, 1.0, 1.0])] // Zero score |
| 74 | + #[TestWith(['UPPERCASE_LABEL', 1.0, 0.0, 0.0, 1.0, 1.0])] // Perfect score |
| 75 | + #[TestWith(['label-with-dashes', 0.000001, 0.0, 0.0, 1.0, 1.0])] // Very low score |
| 76 | + #[TestWith(['label_with_underscores', 0.999999, 0.0, 0.0, 1.0, 1.0])] // Very high score |
| 77 | + #[TestWith(['label with spaces', 0.5, 0.0, 0.0, 1.0, 1.0])] // Space in label |
| 78 | + #[TestWith(['123', 0.8, 0.0, 0.0, 1.0, 1.0])] // Numeric label |
| 79 | + #[TestWith(['', 0.3, 0.0, 0.0, 1.0, 1.0])] // Empty label |
| 80 | + #[TestWith(['véhicule', 0.7, 0.0, 0.0, 1.0, 1.0])] // Accented characters |
| 81 | + #[TestWith(['🚗', 0.9, 0.0, 0.0, 1.0, 1.0])] // Emoji label |
| 82 | + public function testConstructorWithEdgeCasesAndPatterns(string $label, float $score, float $xmin, float $ymin, float $xmax, float $ymax) |
| 83 | + { |
| 84 | + $object = new DetectedObject($label, $score, $xmin, $ymin, $xmax, $ymax); |
| 85 | + |
| 86 | + $this->assertSame($label, $object->label); |
| 87 | + $this->assertSame($score, $object->score); |
| 88 | + $this->assertSame($xmin, $object->xmin); |
| 89 | + $this->assertSame($ymin, $object->ymin); |
| 90 | + $this->assertSame($xmax, $object->xmax); |
| 91 | + $this->assertSame($ymax, $object->ymax); |
| 92 | + } |
| 93 | + |
| 94 | + #[TestDox('Bounding box can represent different coordinate systems')] |
| 95 | + #[TestWith(['object', 0.9, 0.1, 0.2, 0.9, 0.8, 'normalized coordinates (0-1)'])] |
| 96 | + #[TestWith(['object', 0.9, 100.0, 200.0, 500.0, 600.0, 'pixel coordinates'])] |
| 97 | + #[TestWith(['object', 0.9, -50.0, -100.0, 50.0, 100.0, 'negative coordinates (possible in some coordinate systems)'])] |
| 98 | + public function testBoundingBoxCoordinateSystems( |
| 99 | + string $label, |
| 100 | + float $score, |
| 101 | + float $xmin, |
| 102 | + float $ymin, |
| 103 | + float $xmax, |
| 104 | + float $ymax, |
| 105 | + string $description, |
| 106 | + ) { |
| 107 | + $object = new DetectedObject($label, $score, $xmin, $ymin, $xmax, $ymax); |
| 108 | + |
| 109 | + $this->assertSame($xmin, $object->xmin); |
| 110 | + $this->assertSame($ymin, $object->ymin); |
| 111 | + $this->assertSame($xmax, $object->xmax); |
| 112 | + $this->assertSame($ymax, $object->ymax); |
| 113 | + } |
| 114 | +} |
0 commit comments