package uniswap import ( "math/big" "testing" "github.com/stretchr/testify/assert" ) func TestCachedFunctionAccuracy(t *testing.T) { // Test SqrtPriceX96ToPrice vs SqrtPriceX96ToPriceCached sqrtPriceX96 := new(big.Int) sqrtPriceX96.SetString("79228162514264337593543950336", 10) // 2^96 (price = 1.0) originalResult := SqrtPriceX96ToPrice(sqrtPriceX96) cachedResult := SqrtPriceX96ToPriceCached(sqrtPriceX96) // Compare the results originalFloat, _ := originalResult.Float64() cachedFloat, _ := cachedResult.Float64() assert.InDelta(t, originalFloat, cachedFloat, 0.0001, "SqrtPriceX96ToPrice and SqrtPriceX96ToPriceCached should produce similar results") // Test PriceToSqrtPriceX96 vs PriceToSqrtPriceX96Cached price := new(big.Float).SetFloat64(1.0) originalResult2 := PriceToSqrtPriceX96(price) cachedResult2 := PriceToSqrtPriceX96Cached(price) // Compare the results diff := new(big.Int).Sub(originalResult2, cachedResult2) assert.True(t, diff.Cmp(big.NewInt(1000000000000)) < 0, "PriceToSqrtPriceX96 and PriceToSqrtPriceX96Cached should produce similar results") }