diff --git a/src/platform/tests/Bridge/HuggingFace/Output/ClassificationTest.php b/src/platform/tests/Bridge/HuggingFace/Output/ClassificationTest.php new file mode 100644 index 000000000..c5f5c2f77 --- /dev/null +++ b/src/platform/tests/Bridge/HuggingFace/Output/ClassificationTest.php @@ -0,0 +1,81 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\AI\Platform\Tests\Bridge\HuggingFace\Output; + +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\Small; +use PHPUnit\Framework\Attributes\TestDox; +use PHPUnit\Framework\Attributes\TestWith; +use PHPUnit\Framework\TestCase; +use Symfony\AI\Platform\Bridge\HuggingFace\Output\Classification; + +/** + * @author Oskar Stark + */ +#[CoversClass(Classification::class)] +#[Small] +final class ClassificationTest extends TestCase +{ + #[TestDox('Construction with label and score creates valid instance')] + public function testConstruction() + { + $classification = new Classification('positive', 0.95); + + $this->assertSame('positive', $classification->label); + $this->assertSame(0.95, $classification->score); + } + + #[TestDox('Constructor accepts various label and score combinations')] + #[TestWith(['positive', 0.99])] + #[TestWith(['negative', 0.01])] + #[TestWith(['neutral', 0.5])] + #[TestWith(['', 0.5])] + #[TestWith(['this_is_a_very_long_classification_label_that_might_be_used_in_some_models', 0.75])] + #[TestWith(['minimum', 0.0])] + #[TestWith(['maximum', 1.0])] + #[TestWith(['émoji 🎉', 0.8])] + #[TestWith(['special-chars_123!@#', 0.65])] + public function testConstructorWithDifferentValues(string $label, float $score) + { + $classification = new Classification($label, $score); + + $this->assertSame($label, $classification->label); + $this->assertSame($score, $classification->score); + } + + #[TestDox('Instance is immutable')] + public function testImmutability() + { + $classification = new Classification('original', 0.7); + + // Create a new instance with different values + $newClassification = new Classification('modified', 0.3); + + // Ensure original instance is unchanged + $this->assertSame('original', $classification->label); + $this->assertSame(0.7, $classification->score); + + $this->assertSame('modified', $newClassification->label); + $this->assertSame(0.3, $newClassification->score); + } + + #[TestDox('Special score values are handled correctly')] + #[TestWith(['precision', 0.123456789])] + #[TestWith(['negative', -0.5])] + #[TestWith(['above_one', 1.5])] + public function testSpecialScoreValues(string $label, float $score) + { + $classification = new Classification($label, $score); + + $this->assertSame($score, $classification->score); + } +}