1<?php 2 3namespace Rubix\ML\Tests; 4 5use Rubix\ML\Report; 6use Rubix\ML\Encoding; 7use PHPUnit\Framework\TestCase; 8use IteratorAggregate; 9use JsonSerializable; 10use ArrayAccess; 11use Stringable; 12 13/** 14 * @group Results 15 * @covers \Rubix\ML\Report 16 */ 17class ReportTest extends TestCase 18{ 19 /** 20 * @var \Rubix\ML\Report 21 */ 22 protected $results; 23 24 /** 25 * @before 26 */ 27 protected function setUp() : void 28 { 29 $this->results = new Report([ 30 'accuracy' => 0.9, 31 'f1_score' => 0.75, 32 'cardinality' => 5, 33 ]); 34 } 35 36 /** 37 * @test 38 */ 39 public function build() : void 40 { 41 $this->assertInstanceOf(Report::class, $this->results); 42 $this->assertInstanceOf(ArrayAccess::class, $this->results); 43 $this->assertInstanceOf(JsonSerializable::class, $this->results); 44 $this->assertInstanceOf(IteratorAggregate::class, $this->results); 45 $this->assertInstanceOf(Stringable::class, $this->results); 46 } 47 48 /** 49 * @test 50 */ 51 public function toArray() : void 52 { 53 $expected = [ 54 'accuracy' => 0.9, 55 'f1_score' => 0.75, 56 'cardinality' => 5, 57 ]; 58 59 $this->assertEquals($expected, $this->results->toArray()); 60 } 61 62 /** 63 * @test 64 */ 65 public function toJSON() : void 66 { 67 $expected = '{"accuracy":0.9,"f1_score":0.75,"cardinality":5}'; 68 69 $encoding = $this->results->toJSON(false); 70 71 $this->assertInstanceOf(Encoding::class, $encoding); 72 $this->assertEquals($expected, (string) $encoding); 73 } 74 75 /** 76 * @test 77 */ 78 public function arrayAccess() : void 79 { 80 $this->assertEquals(0.9, $this->results['accuracy']); 81 $this->assertEquals(0.75, $this->results['f1_score']); 82 $this->assertEquals(5, $this->results['cardinality']); 83 } 84} 85