Skip to content

Commit

Permalink
added more test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterOu8 committed Oct 18, 2022
1 parent 5ac46ce commit c8c54a5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,15 @@ public void removePotion(int inputIndex) {
quickBarQuantity[inputIndex] = 0;
}

/**
* Set the quantity of the potion based on its index on the quick bar
* @param index index of the potion
*/
public void setPotionQuantity(int index, int quantity) {
if (index >= QUICKBAR_SIZE || quantity > MAX_QTY) return;
quickBarQuantity[index] = quantity;
}

/**
* Consume the potion from quickbar based on the input index.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ void cancelAnimation() {
InventoryComponent inventory = player.getComponent(InventoryComponent.class);
Entity combatAnimator = mock(Entity.class);

inventory.cancelAnimation();

AnimationRenderComponent animator = new AnimationRenderComponent(
ServiceLocator.getResourceService().getAsset(
"images/CombatItems/animations/combatItemsAnimation.atlas", TextureAtlas.class));
Expand Down Expand Up @@ -613,6 +615,19 @@ void removePotion() {
assertEquals(expectedList, testInventory6.getInventory());
}

@Test
void setPotionQuantity() {
Entity player = PlayerFactory.createTestPlayer();
Entity testPotion1 = PotionFactory.createTestSpeedPotion();
Entity speedPotion = PotionFactory.createSpeedPotion();
int[] expectedList = new int[3];
int expectedQuantity = 3;
expectedList[0] = expectedQuantity;
InventoryComponent inventory = player.getComponent(InventoryComponent.class);
inventory.setPotionQuantity(0, expectedQuantity);
assertArrayEquals(expectedList, inventory.getQuickBarQuantity());
}

/**
* This test checks that when a potion is consumed that it is removed from the quickbar and
* applies the intended effect to the player
Expand All @@ -635,7 +650,6 @@ void consumePotion() {
inventory.consumePotion(1);
//Test if the function has properly ended or not
inventory.consumePotion(5);
inventory.consumePotion(1);

assertTrue(pmComponent.
checkModifier(PlayerModifier.MOVESPEED, 1.5f, true, 3000));
Expand All @@ -648,5 +662,7 @@ void consumePotion() {

inventory.consumePotion(1);
assertEquals(expectedQuantity, inventory.getQuickBarQuantity()[inventory.getPotionIndex(speedPotion)]);
inventory.setPotionQuantity(0, -1);
inventory.consumePotion(1);
}
}

0 comments on commit c8c54a5

Please sign in to comment.