inventory_mock tests #17
@@ -47,8 +47,8 @@ public class Inventory {
|
||||
|
||||
public int getCurrentWeight() {
|
||||
int currentWeight = 0;
|
||||
for (ItemStack item : items) {
|
||||
currentWeight += item.getItem().getWeight();
|
||||
for (ItemStack stack : items) {
|
||||
currentWeight += stack.getWeight();
|
||||
}
|
||||
return currentWeight;
|
||||
}
|
||||
|
||||
@@ -59,4 +59,20 @@ public class InventoryTest {
|
||||
|
||||
));
|
||||
}
|
||||
|
||||
@Test
|
||||
void current_weight_is_zero_if_no_item_is_added() {
|
||||
var inventory = new Inventory(5);
|
||||
assertThat(inventory.getCurrentWeight(), is(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
void current_weight_calculates_correctly() {
|
||||
var inventory = new Inventory(10);
|
||||
var item = new BasicItem("iron_sword", "Iron Sword", 5);
|
||||
var item2 = new BasicItem("berry", "Berry", 1);
|
||||
inventory.addItem(new ItemStack(item, 1));
|
||||
inventory.addItem(new ItemStack(item2, 2));
|
||||
assertThat(inventory.getCurrentWeight(), is(7));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,5 +42,4 @@ public class LootTableTest {
|
||||
assertThat(result, equalTo("Iron"));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user