Compare commits
2 Commits
3f02799284
...
32441f7de6
Author | SHA1 | Date | |
---|---|---|---|
32441f7de6 | |||
7204246dc9 |
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -15,8 +15,11 @@ object MoneyConfig {
|
|||||||
* Value is the rate
|
* Value is the rate
|
||||||
*/
|
*/
|
||||||
private val config: MutableMap<String, Double> = mutableMapOf()
|
private val config: MutableMap<String, Double> = mutableMapOf()
|
||||||
private var valid: Boolean = false
|
|
||||||
fun isValid() = valid
|
// validate the config, if have it's valid
|
||||||
|
fun isValid(): Boolean {
|
||||||
|
return this.config.isNotEmpty()
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Money properties for money config format
|
* Money properties for money config format
|
||||||
@ -58,9 +61,6 @@ object MoneyConfig {
|
|||||||
throw MoneyCurrencyStateException("money config format is not valid!")
|
throw MoneyCurrencyStateException("money config format is not valid!")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// validate the config is load or not
|
|
||||||
this.valid = this.config.isNotEmpty()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// all currencies with its rate
|
// all currencies with its rate
|
||||||
|
@ -9,13 +9,16 @@ import org.junit.Test
|
|||||||
|
|
||||||
class MoneyTests {
|
class MoneyTests {
|
||||||
@Test
|
@Test
|
||||||
fun test() {
|
fun money_operator_test() {
|
||||||
val money = Money(10.0)
|
val money = Money(10.0)
|
||||||
val money2 = Money(20.0)
|
val money2 = Money(20.0)
|
||||||
money *= money
|
money *= money
|
||||||
println((money + money2) * money2)
|
println((money + money2) * money2)
|
||||||
Assert.assertEquals(10, 10)
|
Assert.assertEquals(100.0, money.value, 0.0)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun exchange_2usd_to_khr_test() {
|
||||||
val properties = MoneyConfig
|
val properties = MoneyConfig
|
||||||
.MoneyConfigProperties
|
.MoneyConfigProperties
|
||||||
.MoneyConfigPropertiesBuilder()
|
.MoneyConfigPropertiesBuilder()
|
||||||
@ -27,11 +30,13 @@ class MoneyTests {
|
|||||||
.setProperties(properties)
|
.setProperties(properties)
|
||||||
.parse("USD:1,KHR:4000")
|
.parse("USD:1,KHR:4000")
|
||||||
|
|
||||||
|
Assert.assertTrue(MoneyConfig.isValid())
|
||||||
|
|
||||||
println(MoneyConfig.getConfig())
|
println(MoneyConfig.getConfig())
|
||||||
|
|
||||||
val moneyUsd = Money(10.0)
|
val moneyUsd = Money(2.0)
|
||||||
val moneyKhr = MoneyExchangeUtils.exchange(moneyUsd, "KHR")
|
val moneyKhr = MoneyExchangeUtils.exchange(moneyUsd, "KHR")
|
||||||
|
|
||||||
Assert.assertEquals(40000.0, moneyKhr.getMoneyValue(), 0.0)
|
Assert.assertEquals(8000.0, moneyKhr.getMoneyValue(), 0.0)
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user