Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[UNTIL-11491] Support up-to 4 decimal places for quantity #16

Merged
merged 1 commit into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion input-engine/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ afterEvaluate {
create<MavenPublication>("input-engine") {
groupId = "de.tillhub.inputengine"
artifactId = "input-engine"
version = "1.0.3"
version = "1.0.4"

from(components.getByName("release"))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import java.math.MathContext

/**
* Quantity input/output which supports up to two decimal places
* Int 1 -> x1 BigInteger(value=100)
* Double 1.56 -> x1,56 BigInteger(value=156)
* Int 1 -> x1 BigInteger(value=10000)
* Double 1.56 -> x1,56 BigInteger(value=15600)
* Float 1.2345F -> x1,2345 BigInteger(value=12345)
*/
class QuantityIO private constructor(
val value: BigInteger
Expand Down Expand Up @@ -191,7 +192,7 @@ class QuantityIO private constructor(
companion object {

private val PRECISION: MathContext = MathContext.DECIMAL128
internal const val FRACTIONS = 2
internal const val FRACTIONS = 4

private val FRACTIONS_FACTOR: BigDecimal = pow10decimal(FRACTIONS)
private val FRACTIONS_FACTOR_INT: BigInteger = pow10(FRACTIONS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import java.math.RoundingMode

internal class NumberInputController(
private val maxMajorDigits: Int = 8,
private val maxMinorDigits: Int = 2
private val maxMinorDigits: Int = 4
) {
private var switchToMinorDigits = false
private var switchToNegate = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,30 @@ class QuantityIOTest : DescribeSpec({

describe("constructors") {
it("Int") {
QuantityIO.of(1).value shouldBe 100.toBigInteger()
QuantityIO.of(1).value shouldBe 10000.toBigInteger()
QuantityIO.of(1).getDecimal() shouldBe 1.toBigDecimal()
QuantityIO.of(25).value shouldBe 2500.toBigInteger()
QuantityIO.of(10000).value shouldBe 1000000.toBigInteger()
QuantityIO.of(25).value shouldBe 250000.toBigInteger()
QuantityIO.of(10000).value shouldBe 100000000.toBigInteger()
QuantityIO.of(1).toInt() shouldBe 1
QuantityIO.of(1).toDouble() shouldBe 1.0
}
it("Double") {
QuantityIO.of(1.00).value shouldBe 100.toBigInteger()
QuantityIO.of(25.78).value shouldBe 2578.toBigInteger()
QuantityIO.of(328.98).value shouldBe 32898.toBigInteger()
QuantityIO.of(1.00).value shouldBe 10000.toBigInteger()
QuantityIO.of(25.78).value shouldBe 257800.toBigInteger()
QuantityIO.of(328.98).value shouldBe 3289800.toBigInteger()
QuantityIO.of(328.98).toDouble() shouldBe 328.98
QuantityIO.of(328.98).toInt() shouldBe 328
}
it("BigInteger") {
QuantityIO.of(BigInteger.ONE).value shouldBe 100.toBigInteger()
QuantityIO.of(BigInteger.ONE).value shouldBe 10000.toBigInteger()
QuantityIO.of(BigInteger.ONE).toInt() shouldBe 1
QuantityIO.of(BigInteger.TEN).value shouldBe 1000.toBigInteger()
QuantityIO.of(BigInteger.TEN).value shouldBe 100000.toBigInteger()
QuantityIO.of(BigInteger.TEN).toDouble() shouldBe 10.0
}
it("BigDecimal") {
QuantityIO.of(BigDecimal.ONE).value shouldBe 100.toBigInteger()
QuantityIO.of(BigDecimal.ONE).value shouldBe 10000.toBigInteger()
QuantityIO.of(BigDecimal.ONE).toInt() shouldBe 1
QuantityIO.of(BigDecimal.TEN).value shouldBe 1000.toBigInteger()
QuantityIO.of(BigDecimal.TEN).value shouldBe 100000.toBigInteger()
QuantityIO.of(BigDecimal.TEN).toDouble() shouldBe 10.0
}
}
Expand All @@ -47,7 +47,9 @@ class QuantityIOTest : DescribeSpec({
it("minorDigits") {
QuantityIO.of(98).getMinorDigits() shouldBe emptyList()
QuantityIO.of(98.45).getMinorDigits() shouldBe listOf(Digit.FOUR, Digit.FIVE)
QuantityIO.of(0.369).getMinorDigits() shouldBe listOf(Digit.THREE, Digit.SIX)
QuantityIO.of(0.369).getMinorDigits() shouldBe listOf(Digit.THREE, Digit.SIX, Digit.NINE)
QuantityIO.of(0.3692).getMinorDigits() shouldBe listOf(Digit.THREE, Digit.SIX, Digit.NINE, Digit.TWO)
QuantityIO.of(0.36921).getMinorDigits() shouldBe listOf(Digit.THREE, Digit.SIX, Digit.NINE, Digit.TWO)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ class NumberInputControllerTest : FunSpec({
target.value() shouldBe 9876.toBigInteger()

target.setValue(567.126.toBigDecimal())
target.value() shouldBe 567.13.toBigDecimal()
target.value() shouldBe 567.126.toBigDecimal()

target.setValue(567.1267.toBigDecimal())
target.value() shouldBe 567.1267.toBigDecimal()

target.setValue(567.12671.toBigDecimal())
target.value() shouldBe 567.1267.toBigDecimal()

target.setValue(367.12)
target.value() shouldBe 367.12.toBigDecimal()
Expand Down