Skip to content

Commit

Permalink
Get tests in FightRequestTest to clean up after themselves (#991)
Browse files Browse the repository at this point in the history
* Get tests in FightRequestTest to clean up after themselves

* Since we already had some test files that can do it, increase coverage for june cleaver elements

* Improve based on feedback

* Remove fight from desert exploration fixtures
  • Loading branch information
gausie committed Aug 20, 2022
1 parent bf45e83 commit dcc3309
Show file tree
Hide file tree
Showing 3 changed files with 489 additions and 378 deletions.
8 changes: 5 additions & 3 deletions src/net/sourceforge/kolmafia/request/FightRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5416,6 +5416,7 @@ private static void processAnapestResult(
public static class TagStatus {
public String name;
public String familiar;
public int familiarId;
public String familiarName;
public String enthroned;
public String enthronedName;
Expand Down Expand Up @@ -5461,8 +5462,8 @@ public static class TagStatus {

public TagStatus() {
FamiliarData current = KoLCharacter.getFamiliar();
int familiarId = current.getId();
this.familiar = current.getFightImageLocation();
this.familiarId = current.getId();
this.familiarName = current.getName();
this.camel = (familiarId == FamiliarPool.MELODRAMEDARY);
this.doppel =
Expand Down Expand Up @@ -7790,8 +7791,9 @@ private static boolean handleGreyYou(String text, TagStatus status) {
// Your nanites absorb your fallen enemy. Cool.
// Your nanites absorb the remains and become more stylish.
//
// But, it only seems to happen when you've won the combat.
if (FightRequest.won) {
// It only happens when you've won the combat or reprocessed the monster with your Goose
var fam = KoLCharacter.getFamiliar();
if (FightRequest.won || fam != null && status.familiarId == FamiliarPool.GREY_GOOSE) {
GreyYouManager.absorbMonster(status.monster);
Matcher matcher = GOO_GAIN_PATTERN.matcher(text);
String gain = null;
Expand Down
56 changes: 53 additions & 3 deletions test/internal/helpers/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,34 @@ public static Cleanups withFamiliar(final int familiarId) {
* @return Reset current familiar
*/
public static Cleanups withFamiliar(final int familiarId, final int experience) {
return withFamiliar(familiarId, experience, null);
}

/**
* Takes familiar as player's current familiar
*
* @param familiarId Familiar to take
* @param name Name for familiar to have
* @return Reset current familiar
*/
public static Cleanups withFamiliar(final int familiarId, final String name) {
return withFamiliar(familiarId, 1, name);
}

/**
* Takes familiar as player's current familiar
*
* @param familiarId Familiar to take
* @param experience Experience for familiar to have
* @param name Name for familiar to have
* @return Reset current familiar
*/
public static Cleanups withFamiliar(
final int familiarId, final int experience, final String name) {
var old = KoLCharacter.getFamiliar();
KoLCharacter.setFamiliar(FamiliarData.registerFamiliar(familiarId, experience));
var fam = FamiliarData.registerFamiliar(familiarId, experience);
if (name != null) fam.setName(name);
KoLCharacter.setFamiliar(fam);
return new Cleanups(() -> KoLCharacter.setFamiliar(old));
}

Expand Down Expand Up @@ -534,6 +560,17 @@ public static Cleanups withSkill(final int skillId) {
return new Cleanups(() -> KoLCharacter.removeAvailableSkill(skillId));
}

/**
* Ensures player does not have a skill
*
* @param skillId Skill to ensure is removed
* @return Removes the skill if it was gained
*/
public static Cleanups withoutSkill(final int skillId) {
KoLCharacter.removeAvailableSkill(skillId);
return new Cleanups(() -> KoLCharacter.removeAvailableSkill(skillId));
}

/**
* Sets player's stats to given values. Substats are set to stat squared
*
Expand Down Expand Up @@ -1185,9 +1222,22 @@ public static Cleanups withLastLocation(final KoLAdventure lastLocation) {
* @return Restores previous value
*/
public static Cleanups withFight() {
return withFight(1);
}

/**
* Acts like the player is currently on the given round of a fight
*
* @return Restores previous value
*/
public static Cleanups withFight(final int round) {
var old = FightRequest.currentRound;
FightRequest.currentRound = 1;
return new Cleanups(() -> FightRequest.currentRound = 0);
FightRequest.currentRound = round;
return new Cleanups(
() -> {
FightRequest.currentRound = 0;
FightRequest.clearInstanceData();
});
}

/**
Expand Down

0 comments on commit dcc3309

Please sign in to comment.