This repository has been archived by the owner on Nov 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 740
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Draft of the Domain layer architecture (#3151)
* Update the modules graph * Add `NonZeroDouble` * WIP: Re-work and draft the domain layer * WIP: Draft stuff * Model the domain * Draft v0.0.1 * Fix Detekt * Fix the unit tests
- Loading branch information
1 parent
7453ec5
commit 03638b8
Showing
26 changed files
with
1,272 additions
and
839 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,18 @@ | ||
package com.ivy.data.model | ||
|
||
import com.ivy.data.model.primitive.AssetCode | ||
import com.ivy.data.model.primitive.NonZeroDouble | ||
import com.ivy.data.model.primitive.PositiveDouble | ||
|
||
/** | ||
* Represents monetary value. (like 10 USD, 5 EUR, 0.005 BTC, 12 GOLD_GRAM) | ||
*/ | ||
data class Value( | ||
data class PositiveValue( | ||
val amount: PositiveDouble, | ||
val asset: AssetCode, | ||
) | ||
|
||
data class Value( | ||
val amount: NonZeroDouble, | ||
val asset: AssetCode, | ||
) |
18 changes: 18 additions & 0 deletions
18
shared/data/model/src/main/kotlin/com/ivy/data/model/primitive/NonZeroDouble.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.ivy.data.model.primitive | ||
|
||
import arrow.core.raise.Raise | ||
import arrow.core.raise.ensure | ||
import com.ivy.data.model.exact.Exact | ||
|
||
@JvmInline | ||
value class NonZeroDouble private constructor(val value: Double) { | ||
companion object : Exact<Double, NonZeroDouble> { | ||
override val exactName = "NonZeroDouble" | ||
|
||
override fun Raise<String>.spec(raw: Double): NonZeroDouble { | ||
ensure(raw != 0.0) { "$raw is zero! It should be non-zero" } | ||
ensure(raw.isFinite()) { "Is not a finite number" } | ||
return NonZeroDouble(raw) | ||
} | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
shared/data/model/src/main/kotlin/com/ivy/data/model/util/ValueRounding.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
shared/data/model/src/test/java/com/ivy/data/model/primitive/NonZeroDoubleTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.ivy.data.model.primitive | ||
|
||
import io.kotest.assertions.arrow.core.shouldBeLeft | ||
import io.kotest.property.Arb | ||
import io.kotest.property.arbitrary.double | ||
import io.kotest.property.arbitrary.filter | ||
import io.kotest.property.forAll | ||
import kotlinx.coroutines.test.runTest | ||
import org.junit.Test | ||
|
||
class NonZeroDoubleTest { | ||
|
||
@Test | ||
fun `fails for zero`() { | ||
NonZeroDouble.from(0.0).shouldBeLeft() | ||
} | ||
|
||
@Test | ||
fun `fails for infinity`() { | ||
NonZeroDouble.from(Double.POSITIVE_INFINITY).shouldBeLeft() | ||
NonZeroDouble.from(Double.NEGATIVE_INFINITY).shouldBeLeft() | ||
} | ||
|
||
@Test | ||
fun `property - valid for all non-zero finite doubles`() = runTest { | ||
forAll( | ||
Arb.double(includeNonFiniteEdgeCases = false) | ||
.filter { it != 0.0 } | ||
) { double -> | ||
NonZeroDouble.from(double).getOrNull()?.value == double | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 0 additions & 17 deletions
17
shared/domain/src/main/java/com/ivy/domain/model/AccountStats.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.