Skip to content

Commit

Permalink
Rename ATT, DEF and IV with padding and hexadecimal. Tested.
Browse files Browse the repository at this point in the history
  • Loading branch information
igoticecream committed Oct 9, 2016
1 parent 238dbff commit e7d8f78
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 2 deletions.
4 changes: 4 additions & 0 deletions app/src/main/java/com/icecream/snorlax/common/Decimals.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ public static String format(double value, int integerDigits, int fractionDigits)
return getDecimalFormat(integerDigits, fractionDigits).format(value);
}

public static String format(int value, int integerDigits, int fractionDigits) {
return getDecimalFormat(integerDigits, fractionDigits).format(value);
}

private Decimals() {
throw new AssertionError("No instances");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import com.icecream.snorlax.module.Pokemons;

import static POGOProtos.Data.PokemonDataOuterClass.PokemonData;
import static android.R.attr.level;
import static java.lang.Integer.parseInt;

@Singleton
Expand All @@ -35,6 +34,9 @@ final class RenameFormat {
private static final String BASE_NICK = "NICK";
private static final String BASE_LVL = "LVL";
private static final String BASE_IV = "IV";
private static final String BASE_ATT = "ATT";
private static final String BASE_DEF = "DEF";
private static final String BASE_STA = "STA";

private final Pokemons mPokemons;
private final RenamePreferences mRenamePreferences;
Expand Down Expand Up @@ -114,6 +116,45 @@ private String processIv(String target, double iv) {
return null;
}

private String processAttack(String target, int attack) {
if (target.equals(BASE_ATT)) {
return Decimals.format(attack, 1, 0);
}
if (target.equals(BASE_ATT.concat("P"))) {
return Decimals.format(attack, 2, 0);
}
if (target.equals(BASE_ATT.concat("H"))) {
return Integer.toHexString(attack).toUpperCase();
}
return null;
}

private String processDefense(String target, int defense) {
if (target.equals(BASE_DEF)) {
return Decimals.format(defense, 1, 0);
}
if (target.equals(BASE_DEF.concat("P"))) {
return Decimals.format(defense, 2, 0);
}
if (target.equals(BASE_DEF.concat("H"))) {
return Integer.toHexString(defense).toUpperCase();
}
return null;
}

private String processStamina(String target, int stamina) {
if (target.equals(BASE_STA)) {
return Decimals.format(stamina, 1, 0);
}
if (target.equals(BASE_STA.concat("P"))) {
return Decimals.format(stamina, 2, 0);
}
if (target.equals(BASE_STA.concat("H"))) {
return Integer.toHexString(stamina).toUpperCase();
}
return null;
}

private String processFormat(Pokemons.Data pokemonsData, String command) throws NullPointerException {
final String target = command.toUpperCase();

Expand All @@ -128,6 +169,15 @@ else if (target.startsWith(BASE_LVL)) {
else if (target.startsWith(BASE_IV)) {
processed = processIv(target, pokemonsData.getIvRatio() * 100);
}
else if (target.startsWith(BASE_ATT)) {
processed = processAttack(target, pokemonsData.getAttack());
}
else if (target.startsWith(BASE_DEF)) {
processed = processDefense(target, pokemonsData.getDefense());
}
else if (target.startsWith(BASE_STA)) {
processed = processStamina(target, pokemonsData.getStamina());
}

return Strings.isNullOrEmpty(processed) ? "%" + command + "%" : processed;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,4 +283,70 @@ public void testIvWithPaddingWrongDecimal() throws Exception {
setRenameFormat("%IVP.A%");
}
//endregion
}

//region Attack
@Test
public void testAttack() throws Exception {
mExpected = "1";
setRenameFormat("%ATT%");
}

@Test
public void testAttackWithPadding() throws Exception {
mExpected = "01";
setRenameFormat("%ATTP%");
}

@Test
public void testAttackHex() throws Exception {
Mockito.doReturn(15).when(mPokemonsData).getAttack();

mExpected = "F";
setRenameFormat("%ATTH%");
}
//endregion

//region Defense
@Test
public void testDefense() throws Exception {
mExpected = "1";
setRenameFormat("%DEF%");
}

@Test
public void testDefenseWithPadding() throws Exception {
mExpected = "01";
setRenameFormat("%DEFP%");
}

@Test
public void testDefenseHex() throws Exception {
Mockito.doReturn(15).when(mPokemonsData).getDefense();

mExpected = "F";
setRenameFormat("%DEFH%");
}
//endregion

//region Stamina
@Test
public void testStamina() throws Exception {
mExpected = "1";
setRenameFormat("%STA%");
}

@Test
public void testStaminaWithPadding() throws Exception {
mExpected = "01";
setRenameFormat("%STAP%");
}

@Test
public void testStaminaHex() throws Exception {
Mockito.doReturn(15).when(mPokemonsData).getStamina();

mExpected = "F";
setRenameFormat("%STAH%");
}
//endregion
}

0 comments on commit e7d8f78

Please sign in to comment.