StevensSEC / pokemonbattlelib

A portable library for accurately simulating Pokemon battles.
GNU General Public License v3.0
12 stars 2 forks source link

Better Test Utilities #291

Closed adapap closed 3 years ago

adapap commented 3 years ago

This PR adds more descriptive messages to failing tests.

Example 1

A missing/incorrect field in ordered transactions is difficult to deduce from the error message.

For the following code:

Expect(t).To(HaveTransactionsInOrder(
    HealTransaction{
        Target: charmander,
        Amount: 0,
    },
    DamageTransaction{
        User: bulbasaur,
        Target: target{
            Pokemon:   *charmander,
            party:     1,
            partySlot: 0,
            Team:      1,
        },
        Move:   GetMove(MoveTackle), // Should be MovePound
        Damage: 3,
    },
))

The current error is as follows:

Expected the sequence of transactions to have these transactions in this order:
    0: pokemonbattlelib.HealTransaction: {Target:Charmander Amount:0}
    1: pokemonbattlelib.DamageTransaction: {User:Bulbasaur Target:Party 1 (Slot 0) | Team 1 | Pokemon:
    Charmander Move:Fire Blast Damage:3 StatusEffect:}

This is my attempt at a solution:

Expected the sequence of transactions to have these transactions in this order:
    1. pokemonbattlelib.DamageTransaction
    2. pokemonbattlelib.DamageTransaction

    Received the following transactions:
    1. pokemonbattlelib.DamageTransaction
    2. pokemonbattlelib.DamageTransaction

    The closest transaction that failed to match is shown below:
    pokemonbattlelib.DamageTransaction has 1/5 fields that do not match:
    - Move
    Expected: Tackle
    Received: Pound

Example 2

When matching single transactions, it is sometimes tricky to see which fields are affected when two transactions are not equivalent. The following error is not the best example, but I've had cases where it's really difficult to find the field that is wrong, especially when working with arrays.

        pokemonbattlelib.DamageTransaction: {User:Bulbasaur Target:Party 0 (Slot 0) | Team 1 | Pokemon:
    Charmander Move:Pound Damage:3 StatusEffect:}

    Instead, got:
        pokemonbattlelib.DamageTransaction: {User:Bulbasaur Target:Party 1 (Slot 0) | Team 1 | Pokemon:
    Charmander Move:Pound Damage:3 StatusEffect:}

Becomes this:

pokemonbattlelib.DamageTransaction has 1/5 fields that do not match:
    - Target
    Expected: Party 0 (Slot 0) | Team 1 | Pokemon:
    Charmander
    Received: Party 1 (Slot 0) | Team 1 | Pokemon:
    Charmander

Example 3

We should be able to see which transactions occurred instead of knowing that one is missing.

Currently, we get the following message:

Expected the sequence of transactions to include: pokemonbattlelib.InflictStatusTransaction, but none of the same type were found in 2 transactions.

Now, we get this message:

Expected the sequence of transactions to include pokemonbattlelib.InflictStatusTransaction, but received:
    - pokemonbattlelib.DamageTransaction
    - pokemonbattlelib.HealTransaction

Additionally, made Move check a strict match similar to how Pokemon are compared in the matchers. Closes #289

codecov[bot] commented 3 years ago

Codecov Report

Merging #291 (073c84e) into main (f52177f) will not change coverage. The diff coverage is n/a.

:exclamation: Current head 073c84e differs from pull request most recent head 2022549. Consider uploading reports for the commit 2022549 to get more accurate results Impacted file tree graph

@@             Coverage Diff             @@
##               main       #291   +/-   ##
===========================================
  Coverage   94.3111%   94.3111%           
===========================================
  Files            13         13           
  Lines          1125       1125           
===========================================
  Hits           1061       1061           
  Misses           56         56           
  Partials          8          8           

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update f52177f...2022549. Read the comment docs.