-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make Money comparable and and allow comparison accross currencies and…
… also add tests for sorting.
- Loading branch information
1 parent
905bd74
commit 902ce63
Showing
5 changed files
with
50 additions
and
7 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
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
42 changes: 42 additions & 0 deletions
42
money/src/test/java/de/tobiasschuerg/money/MoneySortingTest.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,42 @@ | ||
package de.tobiasschuerg.money | ||
|
||
import de.tobiasschuerg.money.Currencies.EURO | ||
import de.tobiasschuerg.money.Currencies.USDOLLAR | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Assert.assertNotEquals | ||
import org.junit.Test | ||
|
||
class MoneySortingTest { | ||
|
||
@Test | ||
fun `test money sorting`() { | ||
|
||
val money1 = Money(2, EURO) | ||
val money2 = Money(17.11, EURO) | ||
val money3 = Money(4.25, EURO) | ||
|
||
val moneyListUnsorted = listOf(money1, money2, money3) | ||
|
||
val sortedlist = moneyListUnsorted.sorted() | ||
assertNotEquals(moneyListUnsorted, sortedlist) | ||
|
||
val moneyListSortedManually = listOf(money1, money3, money2) | ||
assertEquals(moneyListSortedManually, sortedlist) | ||
} | ||
|
||
@Test | ||
fun `test money sorting with different currencies`() { | ||
|
||
val money1 = Money(2, EURO) | ||
val money2 = Money(2, USDOLLAR) | ||
val money3 = Money(3, EURO) | ||
|
||
val moneyListUnsorted = listOf(money1, money2, money3) | ||
|
||
val sortedlist = moneyListUnsorted.sorted() | ||
assertNotEquals(moneyListUnsorted, sortedlist) | ||
|
||
val moneyListSortedManually = listOf(money2, money1, money3) | ||
assertEquals(moneyListSortedManually, sortedlist) | ||
} | ||
} |
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