using System;
using System.Diagnostics;
using Xunit;

namespace PiTests
{
    public class PiTests
    {
        private const string ScriptPath = "/Users/einand/Code/test/csharp/print_hej";
        
        private string RunScript(string args = null)
        {
            var startInfo = new ProcessStartInfo
            {
                FileName = ScriptPath,
                Arguments = args ?? "",
                RedirectStandardOutput = true,
                UseShellExecute = false
            };
            
            using (var process = Process.Start(startInfo))
            {
                var result = process.StandardOutput.ReadToEnd().Trim();
                process.WaitForExit();
                return result;
            }
        }
        
        [Fact]
        public void Test10Decimals()
        {
            var result = RunScript("10");
            var expected = "3.1415926535";
            Assert.Equal(expected, result);
        }
        
        [Fact]
        public void Test5Decimals()
        {
            var result = RunScript("5");
            var expected = "3.14159";
            Assert.Equal(expected, result);
        }
        
        [Fact]
        public void Test1Decimal()
        {
            var result = RunScript("1");
            var expected = "3.1";
            Assert.Equal(expected, result);
        }
        
        [Fact]
        public void Test100Decimals()
        {
            var result = RunScript("100");
            var expected = "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679";
            Assert.Equal(expected, result);
        }
        
        [Fact]
        public void TestDefault100Decimals()
        {
            var result = RunScript();
            var expected = "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679";
            Assert.Equal(expected, result);
        }
        
        [Fact]
        public void Test10000Decimals()
        {
            var result = RunScript("10000");
            // Check length: "3." + 10000 digits = 10002 characters
            Assert.Equal(10002, result.Length);
            Assert.StartsWith("3.14159", result);
        }
    }
}