package main

import (
	"os/exec"
	"strings"
	"testing"
)

const scriptPath = "/Users/einand/Code/test/go/print_hej"

func runScript(decimals ...int) string {
	args := []string{}
	if len(decimals) > 0 {
		args = append(args, string(rune(decimals[0])))
	}
	cmd := exec.Command(scriptPath, args...)
	output, err := cmd.Output()
	if err != nil {
		panic(err)
	}
	return strings.TrimSpace(string(output))
}

func Test10Decimals(t *testing.T) {
	result := runScript(10)
	expected := "3.1415926535"
	if result != expected {
		t.Errorf("Expected %s, got %s", expected, result)
	}
}

func Test5Decimals(t *testing.T) {
	result := runScript(5)
	expected := "3.14159"
	if result != expected {
		t.Errorf("Expected %s, got %s", expected, result)
	}
}

func Test1Decimal(t *testing.T) {
	result := runScript(1)
	expected := "3.1"
	if result != expected {
		t.Errorf("Expected %s, got %s", expected, result)
	}
}

func Test100Decimals(t *testing.T) {
	result := runScript(100)
	expected := "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679"
	if result != expected {
		t.Errorf("Expected %s, got %s", expected, result)
	}
}

func TestDefault100Decimals(t *testing.T) {
	result := runScript()
	expected := "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679"
	if result != expected {
		t.Errorf("Expected %s, got %s", expected, result)
	}
}

func Test10000Decimals(t *testing.T) {
	result := runScript(10000)
	// Check length: "3." + 10000 digits = 10002 characters
	if len(result) != 10002 {
		t.Errorf("Expected 10002 characters, got %d", len(result))
	}
	if !strings.HasPrefix(result, "3.14159") {
		t.Errorf("Result should start with 3.14159, got %s", result[:10])
	}
}