Adds more unit tests

This commit is contained in:
Deukhoofd 2021-08-26 19:25:38 +02:00
parent c2ff18a48c
commit e54c7bd02b
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
7 changed files with 159 additions and 9 deletions

View File

@ -3,11 +3,52 @@ namespace Gen7{
class Acupressure : PkmnScript {
void OnSecondaryEffect(ExecutingMove@ attack, Pokemon@ target, uint8 hit) override {
if (attack.User is target){
// TODO: Fail.
attack.GetHitData(target, hit).Fail();
return;
}
auto randStat = Statistic(target.Battle.Random.Get(0, 6));
auto randStat = Statistic(target.Battle.Random.Get(1, 6));
target.ChangeStatBoost(randStat, 2);
};
}
}
}
#if TESTS
void TestWithRandomSeed(uint seed, Statistic stat){
auto battle = CreateSimpleBattle(seed, "charizard", "venusaur", 100);
auto mon1 = battle.GetBattleSide(0).GetPokemon(0);
auto mon2 = battle.GetBattleSide(1).GetPokemon(0);
auto script = cast<Gen7::Acupressure>(CreateMoveScript("Acupressure"));
auto executingMove = CreateExecutingMove("Acupressure", mon1, mon2);
script.OnSecondaryEffect(executingMove, mon2, 0x0);
RequireEquals(2, mon2.GetStatBoost(stat));
}
[Test name="Acupressure: Random stat increases by two"]
void Acupressure_RandomStatIncreasesBy2(){
TestWithRandomSeed(684, Statistic::SpecialDefense);
TestWithRandomSeed(1037038, Statistic::SpecialDefense);
TestWithRandomSeed(3572948, Statistic::Attack);
TestWithRandomSeed(4087125, Statistic::SpecialDefense);
TestWithRandomSeed(4199056, Statistic::Speed);
TestWithRandomSeed(7291450, Statistic::Attack);
TestWithRandomSeed(8639137, Statistic::SpecialAttack);
TestWithRandomSeed(8918584, Statistic::Attack);
TestWithRandomSeed(9564376, Statistic::Defense);
TestWithRandomSeed(9859436, Statistic::SpecialDefense);
}
[Test name="Acupressure: Fails When Targets Self"]
void Acupressure_FailsOnSelfTarget(){
auto battle = CreateSimpleBattle(684, "charizard", "venusaur", 100);
auto mon1 = battle.GetBattleSide(0).GetPokemon(0);
auto script = cast<Gen7::Acupressure>(CreateMoveScript("Acupressure"));
auto executingMove = CreateExecutingMove("Acupressure", mon1, mon1);
script.OnSecondaryEffect(executingMove, mon1, 0x0);
Require(executingMove.GetHitData(mon1, 0x0).HasFailed);
}
#endif

View File

@ -4,7 +4,7 @@ namespace Gen7 {
void OnSecondaryEffect(ExecutingMove@ attack, Pokemon@ target, uint8 hit) override {
bool result = target.Battle.TurnQueue.MovePokemonChoiceNext(target);
if (!result){
// TODO: Failed
attack.GetHitData(target, hit).Fail();
}
};
}

View File

@ -15,4 +15,29 @@ namespace Gen7 {
target.ChangeStatBoost(Statistic::Speed, _amount);
}
}
}
}
#if TESTS
void TestChangeAllStats(int8 amount){
auto battle = CreateSimpleBattle(684, "charizard", "venusaur", 100);
auto mon1 = battle.GetBattleSide(0).GetPokemon(0);
auto script = cast<Gen7::ChangeAllTargetStats>(CreateMoveScript("ChangeAllTargetStats"));
auto executingMove = CreateExecutingMove("Tackle", mon1, mon1);
script._amount = amount;
script.OnSecondaryEffect(executingMove, mon1, 0x0);
RequireEquals(amount, mon1.GetStatBoost(Statistic::Attack));
RequireEquals(amount, mon1.GetStatBoost(Statistic::Defense));
RequireEquals(amount, mon1.GetStatBoost(Statistic::SpecialAttack));
RequireEquals(amount, mon1.GetStatBoost(Statistic::SpecialDefense));
RequireEquals(amount, mon1.GetStatBoost(Statistic::Speed));
}
[Test name="ChangeAllTargetStats: Does as the name suggests"]
void ChangeAllTargetStats_Test(){
for (int8 i = -6; i <= 6; i++){
TestChangeAllStats(i);
}
}
#endif

View File

@ -11,4 +11,25 @@ namespace Gen7 {
target.ChangeStatBoost(Statistic::Attack, _amount);
}
}
}
}
#if TESTS
void TestChangeAttackStat(int8 amount){
auto battle = CreateSimpleBattle(684, "charizard", "venusaur", 100);
auto mon1 = battle.GetBattleSide(0).GetPokemon(0);
auto script = cast<Gen7::ChangeTargetAttack>(CreateMoveScript("ChangeTargetAtt"));
auto executingMove = CreateExecutingMove("Tackle", mon1, mon1);
script._amount = amount;
script.OnSecondaryEffect(executingMove, mon1, 0x0);
RequireEquals(amount, mon1.GetStatBoost(Statistic::Attack));
}
[Test name="ChangeTargetAttack: Does as the name suggests"]
void ChangeTargetAttack_Test(){
for (int8 i = -6; i <= 6; i++){
TestChangeAttackStat(i);
}
}
#endif

View File

@ -11,4 +11,25 @@ namespace Gen7 {
target.ChangeStatBoost(Statistic::Defense, _amount);
}
}
}
}
#if TESTS
void TestChangeDefenseStat(int8 amount){
auto battle = CreateSimpleBattle(684, "charizard", "venusaur", 100);
auto mon1 = battle.GetBattleSide(0).GetPokemon(0);
auto script = cast<Gen7::ChangeTargetDefense>(CreateMoveScript("ChangeTargetDef"));
auto executingMove = CreateExecutingMove("Tackle", mon1, mon1);
script._amount = amount;
script.OnSecondaryEffect(executingMove, mon1, 0x0);
RequireEquals(amount, mon1.GetStatBoost(Statistic::Defense));
}
[Test name="ChangeTargetDefense: Does as the name suggests"]
void ChangeTargetDefense_Test(){
for (int8 i = -6; i <= 6; i++){
TestChangeDefenseStat(i);
}
}
#endif

View File

@ -11,4 +11,25 @@ namespace Gen7 {
target.ChangeStatBoost(Statistic::SpecialDefense, _amount);
}
}
}
}
#if TESTS
void TestChangeDefense(int8 amount){
auto battle = CreateSimpleBattle(684, "charizard", "venusaur", 100);
auto mon1 = battle.GetBattleSide(0).GetPokemon(0);
auto script = cast<Gen7::ChangeTargetSpecialDefense>(CreateMoveScript("ChangeTargetSpDef"));
auto executingMove = CreateExecutingMove("Tackle", mon1, mon1);
script._amount = amount;
script.OnSecondaryEffect(executingMove, mon1, 0x0);
RequireEquals(amount, mon1.GetStatBoost(Statistic::SpecialDefense));
}
[Test name="ChangeTargetSpecialDefense: Does as the name suggests"]
void ChangeTargetSpecialDefense_Test(){
for (int8 i = -6; i <= 6; i++){
TestChangeDefense(i);
}
}
#endif

View File

@ -11,4 +11,25 @@ namespace Gen7 {
target.ChangeStatBoost(Statistic::Speed, _amount);
}
}
}
}
#if TESTS
void TestChangeTargetSpeed(int8 amount){
auto battle = CreateSimpleBattle(684, "charizard", "venusaur", 100);
auto mon1 = battle.GetBattleSide(0).GetPokemon(0);
auto script = cast<Gen7::ChangeTargetSpeed>(CreateMoveScript("ChangeTargetSpeed"));
auto executingMove = CreateExecutingMove("Tackle", mon1, mon1);
script._amount = amount;
script.OnSecondaryEffect(executingMove, mon1, 0x0);
RequireEquals(amount, mon1.GetStatBoost(Statistic::Speed));
}
[Test name="ChangeTargetSpeed: Does as the name suggests"]
void ChangeTargetSpeed_Test(){
for (int8 i = -6; i <= 6; i++){
TestChangeTargetSpeed(i);
}
}
#endif