Skip to content

Instantly share code, notes, and snippets.

@bmc08gt
Last active November 5, 2025 02:19
Show Gist options
  • Select an option

  • Save bmc08gt/2405eea95fe23b9e0b55bcbe3a693176 to your computer and use it in GitHub Desktop.

Select an option

Save bmc08gt/2405eea95fe23b9e0b55bcbe3a693176 to your computer and use it in GitHub Desktop.
CSV table comparison test
@Test
fun `estimate csv table`() {
val startValue = 10_000L
val endValue = 1_000_000_000_000_000L
val output = buildString {
appendLine("value locked,payment value,payment quarks,sell value")
var valueLocked = startValue
while (valueLocked <= endValue) {
val (circulatingSupply, _) = Estimator.buy(
amountInQuarks = valueLocked,
currentSupplyInQuarks = 0L,
mintDecimals = 6,
feeBps = 0
).getOrThrow()
var paymentValue = startValue
while (paymentValue <= valueLocked) {
val paymentQuarks = Estimator.valueExchangeAsQuarks(
valueInQuarks = paymentValue,
currentSupplyInQuarks = circulatingSupply.setScale(0, RoundingMode.HALF_UP).toDouble().roundToLong(),
mintDecimals = 6,
).getOrThrow()
val (sellValue, _) = Estimator.sell(
amountInQuarks = paymentQuarks.toLong(),
currentValueInQuarks = valueLocked,
mintDecimals = 6,
feeBps = 0
).getOrThrow()
assertTrue { abs(paymentValue.toDouble() - sellValue.toDouble()) <= 1.0 }
appendLine("$valueLocked,$paymentValue,${paymentQuarks.toBigInteger()},${sellValue.toBigInteger()}")
paymentValue *= 10L
}
valueLocked *= 10L
}
}.trim()
println(output)
val generatedLines = output.lines()
val expectedLines = EXPECTED_CSV_OUTPUT.lines()
// Check lengths
if (generatedLines.size != expectedLines.size) {
fail("Generated csv has ${generatedLines.size} lines, expected ${expectedLines.size}")
}
// Compare line by line
for (i in generatedLines.indices) {
val expected = expectedLines[i].trim()
val generated = generatedLines[i].trim()
if (generated != expected) {
fail(
"""
Mismatch at line ${i + 1}:
Expected: $expected
Generated:$generated
""".trimIndent()
)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment