require 'test/unit'
require 'open3'

class PiTest < Test::Unit::TestCase
  SCRIPT_PATH = '/Users/einand/Code/test/ruby/print_hej.rb'
  
  def run_script(*args)
    cmd = ['ruby', SCRIPT_PATH] + args.map(&:to_s)
    stdout, _ = Open3.capture2(*cmd)
    stdout.strip
  end
  
  def test_10_decimals
    result = run_script(10)
    expected = '3.1415926535'
    assert_equal expected, result
  end
  
  def test_5_decimals
    result = run_script(5)
    expected = '3.14159'
    assert_equal expected, result
  end
  
  def test_1_decimal
    result = run_script(1)
    expected = '3.1'
    assert_equal expected, result
  end
  
  def test_100_decimals
    result = run_script(100)
    expected = '3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679'
    assert_equal expected, result
  end
  
  def test_default_100_decimals
    result = run_script
    expected = '3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679'
    assert_equal expected, result
  end
  
  def test_10000_decimals
    result = run_script(10000)
    # Check length: "3." + 10000 digits = 10002 characters
    assert_equal 10002, result.length
    assert result.start_with?('3.14159')
  end
end