Skip to content

Commit

Permalink
Fix item charges check
Browse files Browse the repository at this point in the history
  • Loading branch information
GregHib committed Apr 11, 2024
1 parent 0496e7b commit 7602bee
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Item(
private val defOrNull: ItemDefinition?
get() = KoinPlatformTools.defaultContext().getOrNull()?.get<ItemDefinitions>()?.getOrNull(id)
private val itemCharge: Boolean
get() = defOrNull?.contains("charges") == true && defOrNull?.contains("charge") == true
get() = defOrNull?.contains("charges") == true && defOrNull?.contains("charge") != true
val amount: Int
get() = if (itemCharge) 1 else value
val charges: Int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ sealed class TransactionError {
* An error indicating that the inventory is full and cannot accept any more items.
* @property amount The number of items that could be successfully added before running out of space.
*/
class Full(val amount: Int = 0) : TransactionError()
data class Full(val amount: Int = 0) : TransactionError()

/**
* An error indicating that the inventory does not have enough of the item to fulfill the request.
* @property amount The number of items that could be successfully removed.
*/
class Deficient(val amount: Int = 0) : TransactionError()
data class Deficient(val amount: Int = 0) : TransactionError()

/**
* The transaction completed without error or is no longer in progress.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ internal class AddChargeTest : TransactionOperationTest() {
transaction.charge(0, amountToAdd)

assertFalse(transaction.commit())
assertEquals(TransactionError.Full(5), transaction.error)
}

@Test
Expand All @@ -105,6 +106,7 @@ internal class AddChargeTest : TransactionOperationTest() {
transaction.charge(0, amountToAdd)

assertFalse(transaction.commit())
assertEquals(TransactionError.Full(10), transaction.error)
}

@Test
Expand All @@ -117,5 +119,6 @@ internal class AddChargeTest : TransactionOperationTest() {

assertFalse(transaction.commit())
assertEquals(0, inventory[0].charges)
assertEquals(TransactionError.Invalid, transaction.error)
}
}

0 comments on commit 7602bee

Please sign in to comment.