-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
158 additions
and
45 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
src/test/java/dinkplugin/util/AbstractRarityServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package dinkplugin.util; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.inject.testing.fieldbinder.Bind; | ||
import dinkplugin.MockedTestBase; | ||
import net.runelite.api.ItemComposition; | ||
import net.runelite.client.game.ItemManager; | ||
import net.runelite.http.api.RuneLiteAPI; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.mockito.Mockito; | ||
|
||
import java.util.OptionalDouble; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.mockito.ArgumentMatchers.anyInt; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
abstract class AbstractRarityServiceTest extends MockedTestBase { | ||
private static final double DELTA = MathUtils.EPSILON; | ||
|
||
@Bind | ||
protected final Gson gson = RuneLiteAPI.GSON; | ||
|
||
@Bind | ||
protected final ItemManager itemManager = Mockito.mock(ItemManager.class); | ||
|
||
protected abstract AbstractRarityService getService(); | ||
|
||
@Override | ||
@BeforeEach | ||
protected void setUp() { | ||
super.setUp(); | ||
|
||
// default item mock | ||
Mockito.doAnswer(invocation -> { | ||
ItemComposition comp = mock(ItemComposition.class); | ||
when(comp.getMembersName()).thenReturn("?"); | ||
when(comp.getNote()).thenReturn(-1); | ||
return comp; | ||
}).when(itemManager).getItemComposition(anyInt()); | ||
} | ||
|
||
protected void test(String npcName, int itemId, int quantity, double expectedProbability) { | ||
OptionalDouble rarity = getService().getRarity(npcName, itemId, quantity); | ||
assertTrue(rarity.isPresent()); | ||
assertEquals(expectedProbability, rarity.getAsDouble(), DELTA); | ||
} | ||
|
||
protected void mockItem(int id, String name, boolean noted) { | ||
ItemComposition item = mock(ItemComposition.class); | ||
when(item.getName()).thenReturn(name); | ||
when(item.getMembersName()).thenReturn(name); | ||
when(item.getNote()).thenReturn(noted ? 799 : -1); | ||
when(item.getLinkedNoteId()).thenReturn(noted ? id - 1 : id + 1); | ||
when(itemManager.getItemComposition(id)).thenReturn(item); | ||
} | ||
|
||
protected void mockItem(int id, String name) { | ||
this.mockItem(id, name, false); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package dinkplugin.util; | ||
|
||
import com.google.inject.testing.fieldbinder.Bind; | ||
import lombok.Getter; | ||
import net.runelite.api.ItemID; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mockito; | ||
|
||
class ThievingServiceTest extends AbstractRarityServiceTest { | ||
|
||
@Bind | ||
@Getter | ||
private final ThievingService service = Mockito.spy(new ThievingService(gson, itemManager)); | ||
|
||
@Override | ||
@BeforeEach | ||
protected void setUp() { | ||
super.setUp(); | ||
|
||
// item mocks | ||
mockItem(ItemID.BLOOD_SHARD, "Blood shard"); | ||
mockItem(ItemID.ENHANCED_CRYSTAL_TELEPORT_SEED, "Enhanced crystal teleport seed"); | ||
mockItem(ItemID.UNCUT_DIAMOND, "Uncut diamond"); | ||
mockItem(ItemID.CLUE_SCROLL_EASY, "Clue scroll (easy)"); | ||
mockItem(ItemID.CLUE_SCROLL_EASY_2711, "Clue scroll (easy)"); | ||
mockItem(ItemID.CLUE_SCROLL_MEDIUM, "Clue scroll (medium)"); | ||
mockItem(ItemID.CLUE_SCROLL_MEDIUM_2809, "Clue scroll (medium)"); | ||
mockItem(ItemID.CLUE_SCROLL_HARD, "Clue scroll (hard)"); | ||
mockItem(ItemID.CLUE_SCROLL_HARD_3560, "Clue scroll (hard)"); | ||
mockItem(ItemID.CLUE_SCROLL_ELITE, "Clue scroll (elite)"); | ||
mockItem(ItemID.CLUE_SCROLL_ELITE_12157, "Clue scroll (elite)"); | ||
mockItem(ItemID.CLUE_SCROLL_ELITE_12075, "Clue scroll (elite)"); | ||
mockItem(ItemID.HAM_CLOAK, "Ham cloak"); | ||
mockItem(ItemID.HAM_BOOTS, "Ham boots"); | ||
mockItem(ItemID.SNAPE_GRASS_SEED, "Snape grass seed"); | ||
mockItem(ItemID.SNAPDRAGON_SEED, "Snapdragon seed"); | ||
} | ||
|
||
@Test | ||
void testFarmer() { | ||
test("Master Farmer", ItemID.SNAPE_GRASS_SEED, 1, 1.0 / 260); | ||
test("Master Farmer", ItemID.SNAPDRAGON_SEED, 1, 1.0 / 2083); | ||
} | ||
|
||
@Test | ||
void testHam() { | ||
test("H.A.M. Member", ItemID.HAM_CLOAK, 1, 1.0 / 100); | ||
test("H.A.M. Member", ItemID.HAM_BOOTS, 1, 1.0 / 100); | ||
} | ||
|
||
@Test | ||
void testCitizen() { | ||
test("Wealthy citizen", ItemID.CLUE_SCROLL_EASY, 1, 1.0 / 85); | ||
} | ||
|
||
@Test | ||
void testPaladin() { | ||
test("Paladin", ItemID.CLUE_SCROLL_HARD, 1, 1.0 / 1000); | ||
} | ||
|
||
@Test | ||
void testGnome() { | ||
test("Gnome", ItemID.CLUE_SCROLL_MEDIUM, 1, 1.0 / 150); | ||
} | ||
|
||
@Test | ||
void testHero() { | ||
test("Hero", ItemID.CLUE_SCROLL_ELITE, 1, 1.0 / 1400); | ||
test("Hero", ItemID.CLUE_SCROLL_ELITE_12075, 1, 1.0 / 1400); | ||
test("Hero", ItemID.CLUE_SCROLL_ELITE_12157, 1, 1.0 / 1400); | ||
} | ||
|
||
@Test | ||
void testVyre() { | ||
test("Caninelle Draynar", ItemID.BLOOD_SHARD, 1, 1.0 / 5000); | ||
test("Grigor Rasputin", ItemID.BLOOD_SHARD, 1, 1.0 / 5000); | ||
test("Valentina Diaemus", ItemID.BLOOD_SHARD, 1, 1.0 / 5000); | ||
} | ||
|
||
@Test | ||
void testElf() { | ||
test("Arvel", ItemID.ENHANCED_CRYSTAL_TELEPORT_SEED, 1, 1.0 / 1024); | ||
test("Indis", ItemID.ENHANCED_CRYSTAL_TELEPORT_SEED, 1, 1.0 / 1024); | ||
} | ||
|
||
@Test | ||
void testHur() { | ||
test("TzHaar-Hur", ItemID.UNCUT_DIAMOND, 1, 1.0 / 195); | ||
} | ||
|
||
} |