Skip to content

Commit

Permalink
🧪 Created failed test to verify the bug
Browse files Browse the repository at this point in the history
  • Loading branch information
jernejk authored and JustAn0therDev committed Feb 4, 2024
1 parent 87a98c8 commit cca2f06
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using PokemonAdventureGame.Interfaces;
using PokemonAdventureGame.Pokemon;
using PokemonAdventureGame.PokemonTeam;
using System.Linq;
using Xunit;

namespace PokemonAdventureGame.Tests.Battles
{
public static class BattleTestUtils
{
public static void FaintPokemon<TPokemon>(ITrainer trainer)
where TPokemon : IPokemon
{
TrainerPokemon pokemon = trainer.PokemonTeam.FirstOrDefault(x => x.Pokemon is Gyarados);
FaintSpecificPokemon(pokemon);
}

public static void FaintSpecificPokemon(TrainerPokemon pokemon)
{
pokemon.Pokemon.ReceiveDamage(9999);
pokemon.SetAsFainted();
}

public static IPokemon GetCurrentPokemonForBattle(ITrainer trainer)
{
// This will set the "Current" property to true for the first available Pokemon.
_ = trainer.GetNextAvailablePokemon();

// This will return the Pokemon that will be used in the battle.
// NOTE: This might return a different instance of the Pokemon
// than "GetNextAvailablePokemon" when multiple of the same are in the team.
return trainer.GetCurrentPokemon();
}

public static void AssertPokemonAndNotFainted<TPokemon>(IPokemon pokemon)
where TPokemon : IPokemon
{
//string pokemonName = typeof(TPokemon).Name;
//Assert.Equal(pokemonName, pokemon?.GetType().Name);
Assert.False(pokemon.HasFainted());
Assert.IsType<TPokemon>(pokemon);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using PokemonAdventureGame.Factories;
using PokemonAdventureGame.Interfaces;
using PokemonAdventureGame.Pokemon;
using PokemonAdventureGame.PokemonTeam;
using PokemonAdventureGame.Trainers;
using System.Linq;
using Xunit;

namespace PokemonAdventureGame.Tests.Battles
{
public class LanceBattleTests
{
[Fact]
public void LanceFirstPokemon()
{
ITrainer trainer = TrainerFactory.CreateTrainer<Lance>();

IPokemon currentPokemon = BattleTestUtils.GetCurrentPokemonForBattle(trainer);

BattleTestUtils.AssertPokemonAndNotFainted<Gyarados>(currentPokemon);
}

[Fact]
public void LanceSecondPokemon()
{
ITrainer trainer = TrainerFactory.CreateTrainer<Lance>();

// Simulate Gyarados fainting
TrainerPokemon gyarados = trainer.PokemonTeam.FirstOrDefault(x => x.Pokemon is Gyarados);
gyarados.Fainted = true;

// Check next Pokemon is Dragonite
IPokemon currentPokemon = BattleTestUtils.GetCurrentPokemonForBattle(trainer);

BattleTestUtils.AssertPokemonAndNotFainted<Dragonite>(currentPokemon);
}

[Fact]
public void LanceThirdPokemon()
{
ITrainer trainer = TrainerFactory.CreateTrainer<Lance>();

// Simulate Gyarados fainting
BattleTestUtils.FaintPokemon<Gyarados>(trainer);

// Simulate first Dragonite fainting
TrainerPokemon firstDragonite = trainer.PokemonTeam.FirstOrDefault(x => x.Pokemon is Dragonite);
BattleTestUtils.FaintSpecificPokemon(firstDragonite);

// Check next Pokemon is Dragonite
IPokemon currentPokemon = BattleTestUtils.GetCurrentPokemonForBattle(trainer);

BattleTestUtils.AssertPokemonAndNotFainted<Dragonite>(currentPokemon);
}

[Fact]
public void LanceAllDragoniteDown()
{
ITrainer trainer = TrainerFactory.CreateTrainer<Lance>();

// Simulate Gyarados fainting
BattleTestUtils.FaintPokemon<Gyarados>(trainer);

// Simulate all Dragonites fainting
trainer.PokemonTeam
.Where(x => x.Pokemon is Dragonite)
.ToList()
.ForEach(x => BattleTestUtils.FaintSpecificPokemon(x));

// Check next Pokemon is Dragonite
IPokemon currentPokemon = BattleTestUtils.GetCurrentPokemonForBattle(trainer);

BattleTestUtils.AssertPokemonAndNotFainted<Aerodactyl>(currentPokemon);
}
}
}

0 comments on commit cca2f06

Please sign in to comment.