[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-wallet-kotlin] branch master updated: Fix Amount multiplication w
From: |
gnunet |
Subject: |
[taler-wallet-kotlin] branch master updated: Fix Amount multiplication with zero and add more multiplication tests |
Date: |
Wed, 29 Jul 2020 20:57:28 +0200 |
This is an automated email from the git hooks/post-receive script.
torsten-grote pushed a commit to branch master
in repository wallet-kotlin.
The following commit(s) were added to refs/heads/master by this push:
new 9befa8d Fix Amount multiplication with zero and add more
multiplication tests
9befa8d is described below
commit 9befa8db8317758ad9e5dad5e7698efff76f1a71
Author: Torsten Grote <t@grobox.de>
AuthorDate: Thu Jul 16 10:18:19 2020 -0300
Fix Amount multiplication with zero and add more multiplication tests
---
src/commonMain/kotlin/net/taler/wallet/kotlin/Amount.kt | 2 ++
src/commonTest/kotlin/net/taler/wallet/kotlin/AmountTest.kt | 6 ++++++
2 files changed, 8 insertions(+)
diff --git a/src/commonMain/kotlin/net/taler/wallet/kotlin/Amount.kt
b/src/commonMain/kotlin/net/taler/wallet/kotlin/Amount.kt
index 87c147d..2d39bb3 100644
--- a/src/commonMain/kotlin/net/taler/wallet/kotlin/Amount.kt
+++ b/src/commonMain/kotlin/net/taler/wallet/kotlin/Amount.kt
@@ -151,6 +151,8 @@ data class Amount(
}
operator fun times(factor: Int): Amount {
+ // TODO consider replacing with a faster implementation
+ if (factor == 0) return zero(currency)
var result = this
for (i in 1 until factor) result += this
return result
diff --git a/src/commonTest/kotlin/net/taler/wallet/kotlin/AmountTest.kt
b/src/commonTest/kotlin/net/taler/wallet/kotlin/AmountTest.kt
index 578874d..08ee618 100644
--- a/src/commonTest/kotlin/net/taler/wallet/kotlin/AmountTest.kt
+++ b/src/commonTest/kotlin/net/taler/wallet/kotlin/AmountTest.kt
@@ -152,6 +152,12 @@ class AmountTest {
Amount.fromJSONString("EUR:4.5"),
Amount.fromJSONString("EUR:1.5") * 3
)
+ assertEquals(Amount.fromJSONString("EUR:0"),
Amount.fromJSONString("EUR:1.11") * 0)
+ assertEquals(Amount.fromJSONString("EUR:1.11"),
Amount.fromJSONString("EUR:1.11") * 1)
+ assertEquals(Amount.fromJSONString("EUR:2.22"),
Amount.fromJSONString("EUR:1.11") * 2)
+ assertEquals(Amount.fromJSONString("EUR:3.33"),
Amount.fromJSONString("EUR:1.11") * 3)
+ assertEquals(Amount.fromJSONString("EUR:4.44"),
Amount.fromJSONString("EUR:1.11") * 4)
+ assertEquals(Amount.fromJSONString("EUR:5.55"),
Amount.fromJSONString("EUR:1.11") * 5)
assertEquals(
Amount.fromJSONString("EUR:1500000000.00000003"),
Amount.fromJSONString("EUR:500000000.00000001") * 3
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [taler-wallet-kotlin] branch master updated: Fix Amount multiplication with zero and add more multiplication tests,
gnunet <=