<?php

use PHPUnit\Framework\TestCase;

class PiTest extends TestCase
{
    private const SCRIPT_PATH = '/Users/einand/Code/test/php/print_hej.php';
    
    private function runScript(?string $decimals = null): string
    {
        $cmd = ['php', self::SCRIPT_PATH];
        if ($decimals !== null) {
            $cmd[] = $decimals;
        }
        
        $output = [];
        exec(implode(' ', $cmd), $output);
        return trim(implode("\n", $output));
    }
    
    public function test10Decimals(): void
    {
        $result = $this->runScript('10');
        $expected = '3.1415926535';
        $this->assertEquals($expected, $result);
    }
    
    public function test5Decimals(): void
    {
        $result = $this->runScript('5');
        $expected = '3.14159';
        $this->assertEquals($expected, $result);
    }
    
    public function test1Decimal(): void
    {
        $result = $this->runScript('1');
        $expected = '3.1';
        $this->assertEquals($expected, $result);
    }
    
    public function test100Decimals(): void
    {
        $result = $this->runScript('100');
        $expected = '3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679';
        $this->assertEquals($expected, $result);
    }
    
    public function testDefault100Decimals(): void
    {
        $result = $this->runScript();
        $expected = '3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679';
        $this->assertEquals($expected, $result);
    }
    
    public function test10000Decimals(): void
    {
        $result = $this->runScript('10000');
        // Check length: "3." + 10000 digits = 10002 characters
        $this->assertEquals(10002, strlen($result));
        $this->assertTrue(strpos($result, '3.14159') === 0);
    }
}