require "spec"
require "../print_hej"

SCRIPT_PATH = "/Users/einand/Code/test/crystal/print_hej"

def run_script(args = nil)
  cmd = [SCRIPT_PATH]
  cmd << args.to_s if args
  output = `#{cmd.join(" ")}`
  output.strip
end

describe "Pi calculation" do
  it "calculates 10 decimals" do
    result = run_script(10)
    expected = "3.1415926535"
    result.should eq(expected)
  end
  
  it "calculates 5 decimals" do
    result = run_script(5)
    expected = "3.14159"
    result.should eq(expected)
  end
  
  it "calculates 1 decimal" do
    result = run_script(1)
    expected = "3.1"
    result.should eq(expected)
  end
  
  it "calculates 100 decimals" do
    result = run_script(100)
    expected = "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679"
    result.should eq(expected)
  end
  
  it "calculates default 100 decimals" do
    result = run_script
    expected = "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679"
    result.should eq(expected)
  end
  
  it "calculates 10000 decimals" do
    result = run_script(10000)
    # Check length: "3." + 10000 digits = 10002 characters
    result.size.should eq(10002)
    result.starts_with?("3.14159").should be_true
  end
end