import unittest
import osproc
import strutils

const SCRIPT_PATH = "/Users/einand/Code/test/nim/print_hej"

proc runScript(decimals: int = -1): string =
  var cmd = SCRIPT_PATH
  if decimals >= 0:
    cmd = cmd & " " & $decimals
  
  let (output, exitCode) = execCmdEx(cmd)
  result = output.strip()

suite "Pi calculation tests":
  test "10 decimals":
    let result = runScript(10)
    let expected = "3.1415926535"
    check result == expected
  
  test "5 decimals":
    let result = runScript(5)
    let expected = "3.14159"
    check result == expected
  
  test "1 decimal":
    let result = runScript(1)
    let expected = "3.1"
    check result == expected
  
  test "100 decimals":
    let result = runScript(100)
    let expected = "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679"
    check result == expected
  
  test "default 100 decimals":
    let result = runScript()
    let expected = "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679"
    check result == expected
  
  test "10000 decimals":
    let result = runScript(10000)
    # Check length: "3." + 10000 digits = 10002 characters
    check len(result) == 10002
    check result.startsWith("3.14159")