Began work on unit tests

This commit is contained in:
Deukhoofd 2021-08-25 21:18:41 +02:00
parent 113c05b381
commit c2ff18a48c
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
9 changed files with 132 additions and 3 deletions

View File

@ -2,6 +2,7 @@ shared interface Battle {
const BattleLibrary@ Library { get const; } const BattleLibrary@ Library { get const; }
bool CanUse(BaseTurnChoice@ choice); bool CanUse(BaseTurnChoice@ choice);
bool CanFlee { get const; } bool CanFlee { get const; }
uint CurrentTurn { get const; }
BattleRandom@ Random { get const; } BattleRandom@ Random { get const; }
ChoiceQueue@ TurnQueue { get const; } ChoiceQueue@ TurnQueue { get const; }
ref AddVolatile(const constString &in name); ref AddVolatile(const constString &in name);

View File

@ -2,4 +2,5 @@ shared interface BattleSide {
bool SwapPositions(uint8 a, uint8 b); bool SwapPositions(uint8 a, uint8 b);
uint8 SideIndex { get const; } uint8 SideIndex { get const; }
uint8 GetPokemonIndex(const Pokemon@ pokemon) const; uint8 GetPokemonIndex(const Pokemon@ pokemon) const;
Pokemon@ GetPokemon(uint8 index) const;
} }

View File

@ -0,0 +1,6 @@
shared interface EvolutionData {
const Species& NewSpecies { get const; }
EvolutionMethod Method { get const; }
uint64 DataCount { get const; }
EffectParameter@ GetData(uint64 index) const;
}

View File

@ -0,0 +1,17 @@
shared enum EvolutionMethod {
Level = 0,
HighFriendship = 1,
HighFriendshipTime = 2,
KnownMove = 3,
LocationBased = 4,
TimeBased = 5,
HoldsItem = 6,
HoldsItemTime = 7,
IsGenderAndLevel = 8,
EvolutionItemUse = 9,
EvolutionItemUseWithGender = 10,
Trade = 11,
TradeWithHeldItem = 12,
TradeWithSpecificPokemon = 13,
Custom = 14,
}

View File

@ -0,0 +1,3 @@
shared abstract class EvolutionScript {
void DoesEvolveFromLevelUp(bool &out, const EvolutionData@, const Pokemon@){};
}

View File

@ -8,7 +8,7 @@ shared interface Pokemon {
bool Shiny { get const; } bool Shiny { get const; }
const Item@ HeldItem { get const; } const Item@ HeldItem { get const; }
bool HasHeldItem(const constString &in name) const; bool HasHeldItem(const constString &in name) const;
void SetHeldItem(const string &in name); void SetHeldItem(const constString &in name);
void SetHeldItem(const Item@ item); void SetHeldItem(const Item@ item);
uint CurrentHealth { get const; } uint CurrentHealth { get const; }
const string& Nickname { get const; } const string& Nickname { get const; }

View File

@ -2,4 +2,5 @@ shared interface constString {
bool opEquals(const constString &in) const; bool opEquals(const constString &in) const;
bool opEquals(const string &in) const; bool opEquals(const string &in) const;
uint opImplConv(); uint opImplConv();
string opImplConv();
} }

View File

@ -24,3 +24,33 @@ namespace Gen7 {
} }
} }
} }
#if TESTS
void RunHits(uint seed, uint8 expectedHits){
auto battle = CreateSimpleBattle(seed, "charizard", "venusaur", 100);
auto mon1 = battle.GetBattleSide(0).GetPokemon(0);
auto choice = CreateMoveTurnChoice("tackle", mon1, 1, 0);
auto script = cast<Gen7::MultiHitMove>(CreateMoveScript("2_5HitMove"));
uint8 numberHits = 1;
script.ModifyNumberOfHits(choice, numberHits);
RequireEquals(expectedHits, numberHits);
}
[Test name="2-5 Hit Move"]
void MultiHitMove_HasMultiHits(){
RunHits(684, 3);
RunHits(78216, 4);
RunHits(123640, 3);
RunHits(280282, 2);
RunHits(353353, 3);
RunHits(388667, 2);
RunHits(436269, 2);
RunHits(784419, 5);
RunHits(800144, 2);
RunHits(901811, 5);
RunHits(992841, 4);
}
#endif

View File

@ -9,3 +9,73 @@ namespace Gen7 {
}; };
} }
} }
#if TESTS
[Test name="Acrobatics: Base Power without item"]
void Acrobatics_BasePowerWithoutItem(){
auto battle = CreateSimpleBattle(684, "charizard", "venusaur", 100);
auto mon1 = battle.GetBattleSide(0).GetPokemon(0);
auto mon2 = battle.GetBattleSide(1).GetPokemon(0);
auto script = cast<Gen7::Acrobatics>(CreateMoveScript("Acrobatics"));
Require(script !is null);
uint8 bp = 20;
auto executingMove = CreateExecutingMove("Acrobatics", mon1, mon2);
script.OverrideBasePower(executingMove, mon2, 0x0, bp);
RequireEquals(40, bp);
}
[Test name="Acrobatics: Base Power with item"]
void Acrobatics_BasePowerWithItem(){
auto battle = CreateSimpleBattle(684, "charizard", "venusaur", 100);
auto mon1 = battle.GetBattleSide(0).GetPokemon(0);
auto mon2 = battle.GetBattleSide(1).GetPokemon(0);
mon1.SetHeldItem("poke_ball");
auto script = cast<Gen7::Acrobatics>(CreateMoveScript("Acrobatics"));
Require(script !is null);
uint8 bp = 20;
auto executingMove = CreateExecutingMove("Acrobatics", mon1, mon2);
script.OverrideBasePower(executingMove, mon2, 0x0, bp);
RequireEquals(20, bp);
}
[Test name="Acrobatics: Base Power without item with base power > 128"]
void Acrobatics_BasePowerWithoutItemWithHighBasePower(){
auto battle = CreateSimpleBattle(684, "charizard", "venusaur", 100);
auto mon1 = battle.GetBattleSide(0).GetPokemon(0);
auto mon2 = battle.GetBattleSide(1).GetPokemon(0);
auto script = cast<Gen7::Acrobatics>(CreateMoveScript("Acrobatics"));
Require(script !is null);
uint8 bp = 140;
auto executingMove = CreateExecutingMove("Acrobatics", mon1, mon2);
script.OverrideBasePower(executingMove, mon2, 0x0, bp);
RequireEquals(255, bp);
}
[Test name="Acrobatics: Damage without item"]
void Acrobatics_TestDamageWithoutItem(){
auto battle = CreateSimpleBattle(684, "charizard", "venusaur", 100);
auto mon1 = battle.GetBattleSide(0).GetPokemon(0);
auto mon2 = battle.GetBattleSide(1).GetPokemon(0);
auto startHealth = mon2.CurrentHealth;
Require(mon1.UseMove("acrobatics", 1, 0));
Require(mon2.PassTurn());
RequireEquals(272, startHealth - mon2.CurrentHealth);
}
[Test name="Acrobatics: Damage with item"]
void Acrobatics_TestDamageWithItem(){
auto battle = CreateSimpleBattle(684, "charizard", "venusaur", 100);
auto mon1 = battle.GetBattleSide(0).GetPokemon(0);
auto mon2 = battle.GetBattleSide(1).GetPokemon(0);
mon1.SetHeldItem("poke_ball");
auto startHealth = mon2.CurrentHealth;
Require(mon1.UseMove("acrobatics", 1, 0));
Require(mon2.PassTurn());
RequireEquals(139, startHealth - mon2.CurrentHealth);
}
#endif