Rewrote blast furnace

This commit is contained in:
Ceikry
2023-08-27 13:35:14 +00:00
committed by Ryan
parent e9fa9d0d41
commit 50dce880c1
21 changed files with 1825 additions and 886 deletions
@@ -0,0 +1,44 @@
package content.activity.blastfurnace
import TestUtils
import content.minigame.blastfurnace.BFBeltOre
import content.minigame.blastfurnace.BlastFurnace
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import org.rs09.consts.Items
class BFBeltOreTests {
init {TestUtils.preTestSetup()}
@Test fun oreShouldMoveCloserToPotWhenTicked() {
TestUtils.getMockPlayer("bf-oremove-test").use { p ->
p.location = BFBeltOre.ORE_START_LOC
val ore = BlastFurnace.addOreToBelt(p, Items.IRON_ORE_440, 5)
Assertions.assertEquals(BFBeltOre.ORE_START_LOC, ore.location)
Assertions.assertEquals(BFBeltOre.ORE_START_LOC, ore.npcInstance?.location)
ore.tick()
val expectedLoc = BFBeltOre.ORE_START_LOC.transform(0, -1, 0)
Assertions.assertEquals(expectedLoc, ore.location)
Assertions.assertEquals(expectedLoc, ore.npcInstance?.properties?.teleportLocation)
TestUtils.advanceTicks(1, false)
ore.tick()
Assertions.assertEquals(expectedLoc, ore.npcInstance?.location)
}
}
@Test fun oreShouldBeAddedToOreContainerAfterReachingEnd() {
TestUtils.getMockPlayer("bf-oremoveadd-test").use { p ->
p.location = BFBeltOre.ORE_START_LOC
val ore = BlastFurnace.addOreToBelt(p, Items.IRON_ORE_440, 5)
for (i in 0 until 4)
if (ore.tick()) BlastFurnace.getPlayerState(p).oresOnBelt.remove(ore)
val container = BlastFurnace.getOreContainer(p)
Assertions.assertEquals(5, container.getOreAmount(Items.IRON_ORE_440))
Assertions.assertEquals(0, BlastFurnace.getAmountOnBelt(p, Items.IRON_ORE_440))
}
}
}
@@ -0,0 +1,101 @@
package content.activity.blastfurnace
import TestUtils
import content.global.skill.smithing.smelting.Bar
import content.minigame.blastfurnace.BFPlayerState
import content.minigame.blastfurnace.BlastFurnace
import core.api.addItem
import core.api.amountInInventory
import core.api.setVarbit
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import org.rs09.consts.Items
class BFPlayerStateTests {
init { TestUtils.preTestSetup() }
@Test fun processOreIntoBarsShouldDoNothingIfBarsNotCooled() {
TestUtils.getMockPlayer("bf-barsnotcooled").use { p ->
val state = BlastFurnace.getPlayerState(p)
state.container.addOre(Items.IRON_ORE_440, 28)
Assertions.assertEquals(true, state.processOresIntoBars())
Assertions.assertEquals(28, state.container.getBarAmount(Bar.IRON))
state.container.addCoal(40)
state.container.addOre(Items.RUNITE_ORE_451, 10)
Assertions.assertEquals(false, state.processOresIntoBars())
Assertions.assertEquals(0, state.container.getBarAmount(Bar.RUNITE))
}
}
@Test fun processOreIntoBarsShouldDoNothingIfBarsUnchecked() {
TestUtils.getMockPlayer("bf-barsnotchecked").use { p ->
val state = BlastFurnace.getPlayerState(p)
state.container.addOre(Items.IRON_ORE_440, 28)
Assertions.assertEquals(true, state.processOresIntoBars())
state.coolBars()
state.container.addCoal(40)
state.container.addOre(Items.RUNITE_ORE_451, 10)
Assertions.assertEquals(false, state.processOresIntoBars())
Assertions.assertEquals(0, state.container.getBarAmount(Bar.RUNITE))
state.checkBars()
Assertions.assertEquals(true, state.processOresIntoBars())
Assertions.assertEquals(10, state.container.getBarAmount(Bar.RUNITE))
}
}
@Test fun shouldBeAbleToClaimBars() {
TestUtils.getMockPlayer("bf-barclaiminig").use { p ->
val state = BlastFurnace.getPlayerState(p)
state.container.addOre(Items.IRON_ORE_440, 28)
Assertions.assertEquals(true, state.processOresIntoBars())
state.coolBars()
Assertions.assertEquals(true, state.claimBars(Bar.IRON, 5))
Assertions.assertEquals(5, amountInInventory(p, Items.IRON_BAR_2351))
Assertions.assertEquals(23, state.container.getBarAmount(Bar.IRON))
}
}
@Test fun shouldNotBeAbleToClaimMoreBarsThanFreeInventorySlots() {
TestUtils.getMockPlayer("bf-claimbarslessslots").use { p ->
val state = BlastFurnace.getPlayerState(p)
state.container.addOre(Items.IRON_ORE_440, 28)
Assertions.assertEquals(true, state.processOresIntoBars())
state.coolBars()
addItem(p, Items.ABYSSAL_WHIP_4151, 27)
Assertions.assertEquals(true, state.claimBars(Bar.IRON, 5))
Assertions.assertEquals(1, amountInInventory(p, Items.IRON_BAR_2351))
Assertions.assertEquals(27, state.container.getBarAmount(Bar.IRON))
}
}
@Test fun claimBarsShouldDoNothingAndGrantNoItemIfInventoryFull() {
TestUtils.getMockPlayer("bf-claimbarsnoslots").use { p ->
val state = BlastFurnace.getPlayerState(p)
state.container.addOre(Items.IRON_ORE_440, 28)
Assertions.assertEquals(true, state.processOresIntoBars())
state.coolBars()
addItem(p, Items.ABYSSAL_WHIP_4151, 28)
Assertions.assertEquals(false, state.claimBars(Bar.IRON, 5))
Assertions.assertEquals(0, amountInInventory(p, Items.IRON_BAR_2351))
Assertions.assertEquals(28, state.container.getBarAmount(Bar.IRON))
}
}
@Test fun claimBarsShouldDoNothingIfBarsNotCooled() {
TestUtils.getMockPlayer("bf-claimbarsnotcooled").use { p ->
val state = BlastFurnace.getPlayerState(p)
state.container.addOre(Items.IRON_ORE_440, 28)
Assertions.assertEquals(true, state.processOresIntoBars())
Assertions.assertEquals(false, state.claimBars(Bar.IRON, 5))
}
}
}
@@ -0,0 +1,42 @@
package content.activity.blastfurnace
import content.minigame.blastfurnace.BFSceneryController
import core.api.getScenery
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
class BFSceneryControllerTests {
init { TestUtils.preTestSetup(); BFSceneryController().resetAllScenery() }
@Test
fun updateBrokenShouldReplaceWithCorrectVariants() {
val scenCont = BFSceneryController()
scenCont.updateBreakable(true, true, true, true)
Assertions.assertEquals(BFSceneryController.BROKEN_BELT, getScenery(BFSceneryController.beltGearRight)?.id)
Assertions.assertEquals(BFSceneryController.BROKEN_COG, getScenery(BFSceneryController.cogRightLoc)?.id)
Assertions.assertEquals(BFSceneryController.BROKEN_POT_PIPE, getScenery(BFSceneryController.potPipeLoc)?.id)
Assertions.assertEquals(BFSceneryController.BROKEN_PUMP_PIPE, getScenery(BFSceneryController.pumpPipeLoc)?.id)
scenCont.updateBreakable(false, false, false, false)
Assertions.assertEquals(BFSceneryController.DEFAULT_BELT, getScenery(BFSceneryController.beltGearRight)?.id)
Assertions.assertEquals(BFSceneryController.DEFAULT_COG, getScenery(BFSceneryController.cogRightLoc)?.id)
Assertions.assertEquals(BFSceneryController.DEFAULT_POT_PIPE, getScenery(BFSceneryController.potPipeLoc)?.id)
Assertions.assertEquals(BFSceneryController.DEFAULT_PUMP_PIPE, getScenery(BFSceneryController.pumpPipeLoc)?.id)
}
@Test
fun stoveIdShouldCorrespondToTemperature() {
val testData = arrayOf(
Pair(0, BFSceneryController.STOVE_COLD),
Pair(40, BFSceneryController.STOVE_WARM),
Pair(80, BFSceneryController.STOVE_HOT)
)
for ((temp, expectedId) in testData) {
val cont = BFSceneryController()
cont.resetAllScenery()
cont.updateStove(temp)
Assertions.assertEquals(expectedId, getScenery(BFSceneryController.stoveLoc)!!.id)
}
}
}
@@ -0,0 +1,245 @@
package content.activity.blastfurnace
import TestUtils
import content.minigame.blastfurnace.BlastFurnace
import content.minigame.blastfurnace.BlastFurnaceListeners
import content.minigame.blastfurnace.BlastConsts
import core.ServerConstants
import core.api.addItem
import core.api.amountInInventory
import core.game.node.entity.skill.Skills
import core.game.world.map.Location
import core.game.world.map.RegionManager
import org.json.simple.JSONObject
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import org.rs09.consts.Items
class BlastFurnaceAreaTests {
@Test fun shouldBeAbleToEnterBfArea() {
TestUtils.getMockPlayer("bf-enterable").use { p ->
p.skills.setStaticLevel(Skills.SMITHING, 60)
p.location = Location(2932, 10195, 0)
TestUtils.simulateInteraction(p, RegionManager.getObject(BlastConsts.STAIRLOC_ENTRANCE)!!, 0)
TestUtils.advanceTicks(5, false)
Assertions.assertEquals(BlastConsts.ENTRANCE_LOC, p.location)
}
}
@Test fun shouldBeAbleToLeaveBfArea() {
TestUtils.getMockPlayer("bf-leavable").use { p ->
p.location = BlastConsts.ENTRANCE_LOC
TestUtils.simulateInteraction(p, RegionManager.getObject(BlastConsts.STAIRLOC_EXIT)!!, 0)
TestUtils.advanceTicks(5, false)
Assertions.assertEquals(BlastConsts.EXIT_LOC, p.location)
}
}
@Test fun shouldNotBeAbleToEnterWithLessThan60Smithing() {
TestUtils.getMockPlayer("bf-60smith").use { p ->
p.location = Location(2932, 10195, 0)
TestUtils.simulateInteraction(p, RegionManager.getObject(BlastConsts.STAIRLOC_ENTRANCE)!!, 0)
TestUtils.advanceTicks(5, false)
Assertions.assertNotEquals(BlastConsts.ENTRANCE_LOC, p.location)
}
}
@Test fun getFeePriceReturnsExpectedValues() {
val testData = arrayOf(
Triple(false, 10, 2500),
Triple(true, 10, 1250),
Triple(false, 60, 0),
Triple(true, 60, 0),
Triple(false, 59, 2500),
Triple(true, 59, 1250)
)
for ((hasCharos, smithLevel, expected) in testData)
Assertions.assertEquals(expected, BlastFurnace.getEntranceFee(hasCharos, smithLevel))
}
@Test fun enterWithFeeShouldKickPlayerOutAfter10Minutes() {
TestUtils.getMockPlayer("bf-fee-kickout").use { p ->
BlastFurnace.enter(p, true)
TestUtils.advanceTicks(BlastConsts.FEE_ENTRANCE_DURATION + 2, false)
Assertions.assertNotEquals(BlastConsts.ENTRANCE_LOC, p.location)
}
}
@Test fun shouldBeAbleToLeaveAndEnterFreelyWhileTimerActive() {
TestUtils.getMockPlayer("bf-fee-reentry").use { p ->
BlastFurnace.enter(p, true)
TestUtils.advanceTicks(2, false)
Assertions.assertEquals(BlastConsts.ENTRANCE_LOC, p.location)
TestUtils.simulateInteraction(p, RegionManager.getObject(BlastConsts.STAIRLOC_EXIT)!!, 0)
TestUtils.advanceTicks(2, false)
Assertions.assertEquals(BlastConsts.EXIT_LOC, p.location)
TestUtils.simulateInteraction(p, RegionManager.getObject(BlastConsts.STAIRLOC_ENTRANCE)!!, 0)
TestUtils.advanceTicks(2, false)
Assertions.assertEquals(BlastConsts.ENTRANCE_LOC, p.location)
p.location = BlastConsts.EXIT_LOC
TestUtils.advanceTicks(BlastConsts.FEE_ENTRANCE_DURATION, false)
//should not allow free reentry if timer has run out
TestUtils.simulateInteraction(p, RegionManager.getObject(BlastConsts.STAIRLOC_ENTRANCE)!!, 0)
TestUtils.advanceTicks(2, false)
Assertions.assertEquals(BlastConsts.EXIT_LOC, p.location)
}
}
@Test fun playerShouldOnlyBeTeleportedIfInsideBFArea() {
TestUtils.getMockPlayer("bf-fee-timeout-notele-outside-bf").use { p ->
BlastFurnace.enter(p, true)
TestUtils.advanceTicks(2, false)
Assertions.assertEquals(BlastConsts.ENTRANCE_LOC, p.location)
p.location = ServerConstants.HOME_LOCATION
TestUtils.advanceTicks(BlastConsts.FEE_ENTRANCE_DURATION, false)
Assertions.assertEquals(ServerConstants.HOME_LOCATION, p.location)
}
}
@Test fun playerShouldBeAbleToPlaceOreOnBelt() {
TestUtils.getMockPlayer("bf-placeoreonbelt").use { p ->
addItem(p, Items.COAL_453, 2)
BlastFurnace.placeAllOre(p)
Assertions.assertEquals(2, BlastFurnace.getAmountOnBelt(p, Items.COAL_453))
Assertions.assertEquals(0, amountInInventory(p, Items.COAL_453))
}
}
@Test fun playerShouldNotBeAbleToPlaceMoreOreThanCanFitOnBelt() {
TestUtils.getMockPlayer("bf-toomuchoreonbelt").use { p ->
val cont = BlastFurnace.getOreContainer(p)
cont.addCoal(BlastConsts.COAL_LIMIT - 15)
cont.addOre(Items.IRON_ORE_440, BlastConsts.ORE_LIMIT - 13)
addItem(p, Items.COAL_453, 15)
addItem(p, Items.IRON_ORE_440, 13)
BlastFurnace.placeAllOre(p)
addItem(p, Items.COAL_453, 15)
addItem(p, Items.IRON_ORE_440, 13)
BlastFurnace.placeAllOre(p)
Assertions.assertEquals(15, amountInInventory(p, Items.COAL_453))
Assertions.assertEquals(13, amountInInventory(p, Items.IRON_ORE_440))
}
}
@Test fun beltOreLimitsShouldAccountForCreatedBars() {
TestUtils.getMockPlayer("bf-baraccountedfor").use { p ->
val cont = BlastFurnace.getOreContainer(p)
cont.addOre(Items.IRON_ORE_440, BlastConsts.ORE_LIMIT - 15)
cont.convertToBars()
addItem(p, Items.IRON_ORE_440, 20)
BlastFurnace.placeAllOre(p)
Assertions.assertEquals(5, amountInInventory(p, Items.IRON_ORE_440))
}
}
@Test fun playerShouldBeAbleToOnlyPlaceSpecificOreOnBelt() {
TestUtils.getMockPlayer("bf-specific-oreplace").use { p ->
addItem(p, Items.IRON_ORE_440, 5)
addItem(p, Items.COAL_453, 3)
addItem(p, Items.RUNITE_ORE_451, 10)
BlastFurnace.placeAllOre(p, Items.RUNITE_ORE_451)
Assertions.assertEquals(0, amountInInventory(p, Items.RUNITE_ORE_451))
Assertions.assertEquals(5, amountInInventory(p, Items.IRON_ORE_440))
Assertions.assertEquals(3, amountInInventory(p, Items.COAL_453))
}
}
@Test fun playerShouldNotBeAbleToPlaceOresTheyLackTheLevelFor() {
TestUtils.getMockPlayer("bf-levelgate-oreplace").use { p ->
addItem(p, Items.RUNITE_ORE_451, 10)
BlastFurnace.placeAllOre(p, Items.RUNITE_ORE_451, accountForSkill = true)
Assertions.assertEquals(10, amountInInventory(p, Items.RUNITE_ORE_451))
}
}
@Test fun shouldNotBeAbleToOccupyExtraBronzeSlotsWithMoreThan28TinOrCopper() {
TestUtils.getMockPlayer("bf-bronze-orelimit").use { p ->
//Edge case - bronze bars have an edge case that allows 28 of both {copper, tin}, so this needs to make sure you can't, for example, add 56 copper.
addItem(p, Items.COPPER_ORE_436, 28)
BlastFurnace.placeAllOre(p)
addItem(p, Items.COPPER_ORE_436, 28)
BlastFurnace.placeAllOre(p)
Assertions.assertEquals(28, BlastFurnace.getAmountOnBelt(p, Items.COPPER_ORE_436))
Assertions.assertEquals(28, amountInInventory(p, Items.COPPER_ORE_436))
p.inventory.clear()
addItem(p, Items.TIN_ORE_438, 28)
BlastFurnace.placeAllOre(p)
addItem(p, Items.TIN_ORE_438, 28)
BlastFurnace.placeAllOre(p)
Assertions.assertEquals(28, BlastFurnace.getAmountOnBelt(p, Items.TIN_ORE_438))
Assertions.assertEquals(28, amountInInventory(p, Items.TIN_ORE_438))
}
}
@Test fun shouldNotBeAbleToPlaceMoreThan28TotalNonCoalOreOnTheBelt() {
TestUtils.getMockPlayer("bf-orelimit").use { p ->
addItem(p, Items.GOLD_ORE_444, 28)
BlastFurnace.placeAllOre(p)
addItem(p, Items.RUNITE_ORE_451, 28)
BlastFurnace.placeAllOre(p)
Assertions.assertEquals(28, BlastFurnace.getAmountOnBelt(p, Items.GOLD_ORE_444))
Assertions.assertEquals(0, amountInInventory(p, Items.GOLD_ORE_444))
Assertions.assertEquals(0, BlastFurnace.getAmountOnBelt(p, Items.RUNITE_ORE_451))
Assertions.assertEquals(28, amountInInventory(p, Items.RUNITE_ORE_451))
}
}
@Test fun shouldBeAbleToPlace28CopperAndTinOreOnTheBelt() {
TestUtils.getMockPlayer("bf-orelimit").use { p ->
addItem(p, Items.COPPER_ORE_436, 28)
BlastFurnace.placeAllOre(p)
addItem(p, Items.TIN_ORE_438, 28)
BlastFurnace.placeAllOre(p)
Assertions.assertEquals(28, BlastFurnace.getAmountOnBelt(p, Items.COPPER_ORE_436))
Assertions.assertEquals(0, amountInInventory(p, Items.COPPER_ORE_436))
Assertions.assertEquals(28, BlastFurnace.getAmountOnBelt(p, Items.TIN_ORE_438))
Assertions.assertEquals(0, amountInInventory(p, Items.TIN_ORE_438))
}
}
@Test fun BFAreaShouldPersistInfoAcrossPlayerRelogs() {
TestUtils.getMockPlayer("bf-persistence").use { p ->
var container = BlastFurnace.getOreContainer(p)
container.addOre(Items.IRON_ORE_440, 15)
container.addCoal(40)
BlastFurnace.addOreToBelt(p, Items.IRON_ORE_440, 4)
BlastFurnace.addOreToBelt(p, Items.RUNITE_ORE_451, 10)
BlastFurnace.addOreToBelt(p, Items.COAL_453, 20)
val area = BlastFurnace()
val saveObj = JSONObject()
area.savePlayer(p, saveObj)
BlastFurnace.playerStates.clear()
area.parsePlayer(p, saveObj)
container = BlastFurnace.getOreContainer(p)
Assertions.assertEquals(15, container.getOreAmount(Items.IRON_ORE_440))
Assertions.assertEquals(40, container.coalAmount())
Assertions.assertEquals(4, BlastFurnace.getAmountOnBelt(p, Items.IRON_ORE_440))
Assertions.assertEquals(10, BlastFurnace.getAmountOnBelt(p, Items.RUNITE_ORE_451))
Assertions.assertEquals(20, BlastFurnace.getAmountOnBelt(p, Items.COAL_453))
}
}
companion object {
init {
TestUtils.preTestSetup()
BlastFurnaceListeners().defineListeners()
}
}
}
@@ -0,0 +1,169 @@
package content.activity.blastfurnace
import content.global.skill.smithing.smelting.Bar
import content.minigame.blastfurnace.BFOreContainer
import content.minigame.blastfurnace.BlastConsts
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import org.rs09.consts.Items
class BlastFurnaceOreContainerTests {
@Test fun shouldBeAbleToAddCoal() {
val cont = BFOreContainer()
cont.addCoal(15)
Assertions.assertEquals(15, cont.coalAmount())
}
@Test fun addCoalShouldReturnExtraAmountIfAddingMoreThanPossible() {
val cont = BFOreContainer()
cont.addCoal(BlastConsts.COAL_LIMIT - 26)
Assertions.assertEquals(2, cont.addCoal(28))
}
@Test fun shouldBeAbleToAddOres() {
val cont = BFOreContainer()
cont.addOre (Items.IRON_ORE_440, 20)
Assertions.assertEquals(20, cont.getOreAmount(Items.IRON_ORE_440))
}
@Test fun addOreShouldReturnExtraAmountIfAddingMoreThanPossible() {
val cont = BFOreContainer()
cont.addOre(Items.IRON_ORE_440, BlastConsts.ORE_LIMIT - 2)
Assertions.assertEquals(3, cont.addOre(Items.IRON_ORE_440, 5))
}
@Test fun addOreShouldReturnExtraAmountWhenAddingMoreCopperOrTinThanPossible() {
val contTin = BFOreContainer()
Assertions.assertEquals(28, contTin.addOre(Items.TIN_ORE_438, 56))
val contCopper = BFOreContainer()
Assertions.assertEquals(28, contCopper.addOre(Items.COPPER_ORE_436, 56))
}
@Test fun convertToBarsShouldYieldExpectedResults() {
data class Data (val coalAmount: Int, val oreAmount: Array<Pair<Int,Int>>, val expectedOreAmounts: Array<Pair<Int,Int>>, val expectedCoalAmount: Int, val expectedBarResult: Array<Pair<Bar,Int>>)
val testData = arrayOf(
Data( //standard case - 20 iron with no coal creates 20 iron bars
0, arrayOf(Pair(Items.IRON_ORE_440, 20)),
arrayOf(Pair(Items.IRON_ORE_440, 0)), 0, arrayOf(Pair(Bar.IRON, 20))
),
Data ( //edge case - 20 iron with 10 coal produces 10 steel and 10 iron
10, arrayOf(Pair(Items.IRON_ORE_440, 20)),
arrayOf(Pair(Items.IRON_ORE_440, 0)), 0, arrayOf(Pair(Bar.STEEL, 10), Pair(Bar.IRON, 10))
),
Data ( //standard case - 20 coal with 10 mithril produces 10 mithril bars
20, arrayOf(Pair(Items.MITHRIL_ORE_447, 10)),
arrayOf(Pair(Items.MITHRIL_ORE_447, 0)), 0, arrayOf(Pair(Bar.MITHRIL, 10))
),
Data ( //standard case - 30 coal with 10 adamantite produces 10 addy bars
30, arrayOf(Pair(Items.ADAMANTITE_ORE_449, 10)),
arrayOf(Pair(Items.ADAMANTITE_ORE_449, 0)), 0, arrayOf(Pair(Bar.ADAMANT, 10))
),
Data ( //standard case - 40 coal with 10 runite produces 10 runite bars
40, arrayOf(Pair(Items.RUNITE_ORE_451, 10)),
arrayOf(Pair(Items.RUNITE_ORE_451, 0)), 0, arrayOf(Pair(Bar.RUNITE, 10))
),
Data ( //semi-edge case - 28 gold with 150 coal produces 28 gold bars with 150 coal remaining (doesn't use any coal when not needed)
150, arrayOf(Pair(Items.GOLD_ORE_444, 28)),
arrayOf(Pair(Items.GOLD_ORE_444, 0)), 150, arrayOf(Pair(Bar.GOLD, 28))
),
Data ( //edge case - 18 silver and 10 runite with 58 coal produces 18 silver bars and 10 runite bars with 18 coal remaining
58, arrayOf(Pair(Items.SILVER_ORE_442, 18), Pair(Items.RUNITE_ORE_451, 10)),
arrayOf(Pair(Items.SILVER_ORE_442, 0), Pair(Items.RUNITE_ORE_451, 0)), 18, arrayOf(Pair(Bar.SILVER, 18), Pair(Bar.RUNITE, 10))
),
Data ( //edge case - only 20 coal but 10 runite (half of what's needed) produces 5 runite bars, with 5 runite ore and 0 coal remaining.
20, arrayOf(Pair(Items.RUNITE_ORE_451, 10)),
arrayOf(Pair(Items.RUNITE_ORE_451, 5)), 0, arrayOf(Pair(Bar.RUNITE, 5))
),
Data (//technically an edge case - 28 copper and 28 tin makes 28 bronze with nothing leftover.
0, arrayOf(Pair(Items.COPPER_ORE_436, 28), Pair(Items.TIN_ORE_438, 28)),
arrayOf(Pair(Items.COPPER_ORE_436, 0), Pair(Items.TIN_ORE_438, 0)), 0, arrayOf(Pair(Bar.BRONZE, 28))
),
Data (//edge case - 10 copper and no tin makes nothing with 10 copper leftover
0, arrayOf(Pair(Items.COPPER_ORE_436, 10)),
arrayOf(Pair(Items.COPPER_ORE_436, 10)), 0, arrayOf(Pair(Bar.BRONZE, 0))
),
Data (//edge case - 14 copper and 5 tin make 5 bronze bars with 9 copper leftover
0, arrayOf(Pair(Items.COPPER_ORE_436, 14), Pair(Items.TIN_ORE_438, 5)),
arrayOf(Pair(Items.COPPER_ORE_436, 9), Pair(Items.TIN_ORE_438, 0)), 0, arrayOf(Pair(Bar.BRONZE, 5))
)
)
var index = 0
for ((initialCoal, initialOres, expectedOres, expectedCoal, expectedBars) in testData) {
val cont = BFOreContainer()
cont.addCoal(initialCoal)
for ((ore, amount) in initialOres) cont.addOre(ore, amount)
cont.convertToBars()
for ((ore, amount) in expectedOres)
Assertions.assertEquals(amount, cont.getOreAmount(ore), "Problem testcase was $index - Missing $ore")
for ((bar, amount) in expectedBars)
Assertions.assertEquals(amount, cont.getBarAmount(bar), "Problem testcase was $index - Missing ${bar.name}")
Assertions.assertEquals(expectedCoal, cont.coalAmount(), "Problem testcase was $index")
index++
}
}
@Test fun convertToBarsShouldNotConsumeMaterialsForAlreadyFilledBarType() {
val cont = BFOreContainer()
cont.addOre(Items.IRON_ORE_440, 28)
cont.convertToBars()
Assertions.assertEquals(28, cont.getBarAmount(Bar.IRON))
cont.addOre(Items.IRON_ORE_440, 28)
cont.convertToBars()
Assertions.assertEquals(28, cont.getBarAmount(Bar.IRON))
Assertions.assertEquals(28, cont.getOreAmount(Items.IRON_ORE_440))
}
@Test fun oreContainerShouldCleanlySerializeAndDeserializeFromJson() {
val cont = BFOreContainer()
cont.addOre(Items.IRON_ORE_440, 28)
cont.convertToBars()
cont.addOre(Items.RUNITE_ORE_451, 15)
cont.addOre(Items.MITHRIL_ORE_447, 13)
cont.addCoal(150)
val json = cont.toJson()
val deserialized = BFOreContainer.fromJson(json)
Assertions.assertEquals(28, deserialized.getBarAmount(Bar.IRON))
Assertions.assertEquals(15, cont.getOreAmount(Items.RUNITE_ORE_451))
Assertions.assertEquals(13, cont.getOreAmount(Items.MITHRIL_ORE_447))
Assertions.assertEquals(150, cont.coalAmount())
}
@Test fun shouldBeAbleToRemoveBars() {
val cont = BFOreContainer()
cont.addOre(Items.IRON_ORE_440, 28)
cont.convertToBars()
val bars = cont.takeBars(Bar.IRON, 15)
Assertions.assertEquals(15, bars?.amount)
Assertions.assertEquals(13, cont.getBarAmount(Bar.IRON))
}
@Test fun shouldNotBeAbleToRemoveMoreBarsThanPossible() {
val cont = BFOreContainer()
cont.addOre(Items.IRON_ORE_440, 28)
cont.convertToBars()
val bars = cont.takeBars(Bar.IRON, 50)
Assertions.assertEquals(28, bars?.amount)
Assertions.assertEquals(0, cont.getBarAmount(Bar.IRON))
}
@Test fun convertToBarsShouldReturnXPReward() {
val cont = BFOreContainer()
cont.addOre(Items.IRON_ORE_440, 28)
Assertions.assertEquals(350.0, cont.convertToBars())
}
@Test fun removingBarsWithNoStockReturnsNull() {
val cont = BFOreContainer()
Assertions.assertEquals(null, cont.takeBars(Bar.RUNITE, 1))
}
}
@@ -0,0 +1,95 @@
package content.activity.blastfurnace
import content.minigame.blastfurnace.BlastState
import content.minigame.blastfurnace.BlastConsts
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
class BlastStateTests {
@Test
fun tickPassedWithCokeInStoveShouldIncreaseStoveTemp() {
val state = BlastState(); state.disableBreaking = true
state.addCoke(1)
Assertions.assertEquals(0, state.stoveTemp)
state.tick(true, false)
Assertions.assertEquals(1, state.stoveTemp)
}
@Test
fun stoveTempShouldNeverExceed100() {
val state = BlastState(); state.disableBreaking = true
state.addCoke(BlastConsts.COKE_LIMIT)
for (i in 0 until 150)
state.tick(true, false)
Assertions.assertEquals(100, state.stoveTemp)
}
@Test fun cokeShouldDisappearFromStove() {
val state = BlastState(); state.disableBreaking = true
state.addCoke(1)
for (i in 0 until 10)
state.tick(true, false)
Assertions.assertEquals(0, state.cokeInStove)
}
@Test fun stoveTempShouldLowerWithoutCoke() {
val state = BlastState(); state.disableBreaking = true
state.addCoke(1)
for (i in 0 until 10)
state.tick(true, false)
Assertions.assertEquals(10, state.stoveTemp)
for (i in 0 until 10)
state.tick(true, false)
Assertions.assertEquals(0, state.stoveTemp)
}
@Test
fun stoveTempShouldNeverGoBelow0() {
val state = BlastState(); state.disableBreaking = true
for (i in 0 until 100)
state.tick(true, false)
Assertions.assertEquals(0, state.stoveTemp)
}
@Test fun furnaceTempShouldIncreaseProportionallyToStoveTempWhilePumping() {
val testData = arrayOf(
Pair(0, 0),
Pair(1, 1),
Pair(4, 2),
Pair(7, 3)
)
for ((cokeToAdd, expectedTempRise) in testData) {
val state = BlastState(); state.disableBreaking = true
state.addCoke(cokeToAdd)
for (i in 0 until state.cokeInStove * 10)
state.tick(false, false)
state.tick(true, false)
Assertions.assertEquals(expectedTempRise, state.furnaceTemp)
}
}
@Test fun pumpingShouldNotTransferHeatIfPipesBroken() {
val state1 = BlastState(); state1.disableBreaking = true
state1.addCoke(BlastConsts.COKE_LIMIT)
state1.pumpPipeBroken = true
for (i in 0 until 20) state1.tick(true, false)
Assertions.assertEquals(0, state1.furnaceTemp)
val state2 = BlastState(); state2.disableBreaking = true
state2.addCoke(BlastConsts.COKE_LIMIT)
state2.potPipeBroken = true
for (i in 0 until 20) state2.tick(true, false)
Assertions.assertEquals(0, state2.furnaceTemp)
}
@Test fun pumpingShouldNotTransferHeatIfBeltBroken() {
val state = BlastState(); state.disableBreaking = true
state.addCoke(BlastConsts.COKE_LIMIT)
state.beltBroken = true
for (i in 0 until 20) state.tick(true, false)
Assertions.assertEquals(0, state.furnaceTemp)
}
}