cii-text-analysis/vendor/rubix/ml/tests/Extractors/JSONTest.php

60 lines
1.5 KiB
PHP
Raw Permalink Normal View History

2026-02-10 16:19:59 +01:00
<?php
namespace Rubix\ML\Tests\Extractors;
use Rubix\ML\Extractors\JSON;
use Rubix\ML\Extractors\Extractor;
use PHPUnit\Framework\TestCase;
use IteratorAggregate;
use Traversable;
/**
* @group Extractors
* @covers \Rubix\ML\Extractors\JSON
*/
class JSONTest extends TestCase
{
/**
* @var \Rubix\ML\Extractors\JSON;
*/
protected $extractor;
/**
* @before
*/
protected function setUp() : void
{
$this->extractor = new JSON('tests/test.json');
}
/**
* @test
*/
public function build() : void
{
$this->assertInstanceOf(JSON::class, $this->extractor);
$this->assertInstanceOf(Extractor::class, $this->extractor);
$this->assertInstanceOf(IteratorAggregate::class, $this->extractor);
$this->assertInstanceOf(Traversable::class, $this->extractor);
}
/**
* @test
*/
public function extract() : void
{
$expected = [
['attitude' => 'nice', 'texture' => 'furry', 'sociability' => 'friendly', 'rating' => 4, 'class' => 'not monster'],
['attitude' => 'mean', 'texture' => 'furry', 'sociability' => 'loner', 'rating' => -1.5, 'class' => 'monster'],
['nice', 'rough', 'friendly', 2.6, 'not monster'],
['mean', 'rough', 'friendly', -1, 'monster'],
['nice', 'rough', 'friendly', 2.9, 'not monster'],
['nice', 'furry', 'loner', -5, 'not monster'],
];
$records = iterator_to_array($this->extractor);
$this->assertEquals($expected, $records);
}
}