A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/AlmasB/FXGL/commit/3ff7d2e2f below:

improved test coverage for Inventory · AlmasB/FXGL@3ff7d2e · GitHub

File tree Expand file treeCollapse file tree 2 files changed

+36

-3

lines changed

Filter options

Expand file treeCollapse file tree 2 files changed

+36

-3

lines changed Original file line number Diff line number Diff line change

@@ -112,10 +112,9 @@ class Inventory<T>(

112 112

if (isFull)

113 113

return false

114 114 115 -

// TODO: if == 0?

116 115

// adding a new item, so check if quantity > 0

117 -

if (quantity < 0) {

118 -

log.warning("Attempted to add a new item with negative quantity. Ignoring")

116 +

if (quantity <= 0) {

117 +

log.warning("Attempted to add a *NEW* item with 0 or negative quantity. Ignoring")

119 118

return false

120 119

}

121 120 Original file line number Diff line number Diff line change

@@ -239,6 +239,22 @@ class InventoryTest {

239 239

assertTrue(inventory.incrementQuantity("Hello", -10))

240 240

}

241 241 242 +

@Test

243 +

fun `Cannot add a new item with 0 or negative amount`() {

244 +

inventory = Inventory(5)

245 + 246 +

assertFalse(inventory.add("Hello", quantity = 0))

247 +

assertFalse(inventory.add("Hello", quantity = -1))

248 +

}

249 + 250 +

@Test

251 +

fun `Cannot increment qty of existing item by 0`() {

252 +

inventory = Inventory(5)

253 +

inventory.add("Hello")

254 + 255 +

assertFalse(inventory.incrementQuantity("Hello", 0))

256 +

}

257 + 242 258

@Test

243 259

fun `Transfer from another inventory`() {

244 260

inventory = Inventory(5)

@@ -269,4 +285,22 @@ class InventoryTest {

269 285

assertTrue(result)

270 286

assertTrue(!inventory.hasItem("Hello"))

271 287

}

288 + 289 +

@Test

290 +

fun `Transfer from inventory does not work if no item in inventory`() {

291 +

inventory = Inventory(5)

292 +

val other = Inventory<String>(2)

293 + 294 +

assertFalse(other.transferFrom(inventory, "Hello"))

295 +

}

296 + 297 +

@Test

298 +

fun `Transfer from inventory does not work if inventory is full`() {

299 +

inventory = Inventory(5)

300 +

inventory.add("Hello")

301 + 302 +

val other = Inventory<String>(0)

303 + 304 +

assertFalse(other.transferFrom(inventory, "Hello"))

305 +

}

272 306

}

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4