Skip to content

Did canTakeItemAmounts In A Smart Way#20

Open
CelestialHoney wants to merge 3 commits into123ishaTest:masterfrom
CelestialHoney:doCanTakeItemAmountsInASmartWay
Open

Did canTakeItemAmounts In A Smart Way#20
CelestialHoney wants to merge 3 commits into123ishaTest:masterfrom
CelestialHoney:doCanTakeItemAmountsInASmartWay

Conversation

@CelestialHoney
Copy link
Contributor

@CelestialHoney CelestialHoney commented Feb 15, 2024

Did canTakeItemAmounts in a smart way, removed lodash-es from dependencies, and add tests for canTakeItemAmounts in IgtInventory.ts

* This method very inefficiently clones the inventory, and simulates adding the items see if they can be taken.
* It's also the only reason we're using lodash...
* TODO do this in a smart way.
* Returns if the inventory can lose the given amounts of items
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you misunderstood this (admittedly weirdly-named) method. It checked whether we could add all these items to the inventory without it overflowing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that is really badly named.

Copy link
Contributor Author

@CelestialHoney CelestialHoney Feb 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, it looks like IgtInventory.getSpotsLeftForItem() does that....
Are you sure I didn't get this right the first time?

test('Correct spots left', () => {
    // Arrange
    const inventory: IgtInventory = new IgtInventory(2);
    expect(inventory.getSpotsLeftForItem(item1)).toBe(2 * maxExampleStack);

    // Act
    inventory.gainItem(item1, maxExampleStack + 1);

    // Assert
    expect(inventory.getSpotsLeftForItem(item1)).toBe(maxExampleStack - 1);
    expect(inventory.canTakeItem(item1, maxExampleStack - 1)).toBe(true);
    expect(inventory.canTakeItem(item1, maxExampleStack)).toBe(false);
  });

  test('Correct spots left with multiple items', () => {
    // Arrange
    const inventory: IgtInventory = new IgtInventory(2);

    // Act
    inventory.gainItem(item1);
    inventory.gainItem(item2);

    // Assert
    expect(inventory.getSpotsLeftForItem(item1)).toBe(maxExampleStack - 1);
    expect(inventory.getSpotsLeftForItem(item2)).toBe(maxExampleStack - 1);
  });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants