inventory_mock tests #17

Merged
erns6604 merged 16 commits from inventory_mocks into main 2025-10-30 07:52:55 +01:00
3 changed files with 18 additions and 3 deletions
Showing only changes of commit adcba0468b - Show all commits

View File

@@ -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;
}

View File

@@ -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));
}
}

View File

@@ -42,5 +42,4 @@ public class LootTableTest {
assertThat(result, equalTo("Iron"));
}
}