Skip to content

Commit 8259ae4

Browse files
committed
minor #448 [Platform][HuggingFace] Add comprehensive tests for Classification (OskarStark)
This PR was squashed before being merged into the main branch. Discussion ---------- [Platform][HuggingFace] Add comprehensive tests for `Classification` | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | Docs? | no | Issues | -- | License | MIT Commits ------- 515bb7e [Platform][HuggingFace] Add comprehensive tests for `Classification`
2 parents f23e1d1 + 515bb7e commit 8259ae4

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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\Classification;
20+
21+
/**
22+
* @author Oskar Stark <[email protected]>
23+
*/
24+
#[CoversClass(Classification::class)]
25+
#[Small]
26+
final class ClassificationTest extends TestCase
27+
{
28+
#[TestDox('Construction with label and score creates valid instance')]
29+
public function testConstruction()
30+
{
31+
$classification = new Classification('positive', 0.95);
32+
33+
$this->assertSame('positive', $classification->label);
34+
$this->assertSame(0.95, $classification->score);
35+
}
36+
37+
#[TestDox('Constructor accepts various label and score combinations')]
38+
#[TestWith(['positive', 0.99])]
39+
#[TestWith(['negative', 0.01])]
40+
#[TestWith(['neutral', 0.5])]
41+
#[TestWith(['', 0.5])]
42+
#[TestWith(['this_is_a_very_long_classification_label_that_might_be_used_in_some_models', 0.75])]
43+
#[TestWith(['minimum', 0.0])]
44+
#[TestWith(['maximum', 1.0])]
45+
#[TestWith(['émoji 🎉', 0.8])]
46+
#[TestWith(['special-chars_123!@#', 0.65])]
47+
public function testConstructorWithDifferentValues(string $label, float $score)
48+
{
49+
$classification = new Classification($label, $score);
50+
51+
$this->assertSame($label, $classification->label);
52+
$this->assertSame($score, $classification->score);
53+
}
54+
55+
#[TestDox('Instance is immutable')]
56+
public function testImmutability()
57+
{
58+
$classification = new Classification('original', 0.7);
59+
60+
// Create a new instance with different values
61+
$newClassification = new Classification('modified', 0.3);
62+
63+
// Ensure original instance is unchanged
64+
$this->assertSame('original', $classification->label);
65+
$this->assertSame(0.7, $classification->score);
66+
67+
$this->assertSame('modified', $newClassification->label);
68+
$this->assertSame(0.3, $newClassification->score);
69+
}
70+
71+
#[TestDox('Special score values are handled correctly')]
72+
#[TestWith(['precision', 0.123456789])]
73+
#[TestWith(['negative', -0.5])]
74+
#[TestWith(['above_one', 1.5])]
75+
public function testSpecialScoreValues(string $label, float $score)
76+
{
77+
$classification = new Classification($label, $score);
78+
79+
$this->assertSame($score, $classification->score);
80+
}
81+
}

0 commit comments

Comments
 (0)