Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yairm210 committed Jun 13, 2024
1 parent 4f436e9 commit 3160416
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
1 change: 1 addition & 0 deletions tests/src/com/unciv/testing/TestGame.kt
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class TestGame {
}

fun getTile(position: Vector2) = tileMap[position]
fun getTile(x: Int, y: Int) = tileMap[x, y]

/** Sets the [terrain] and [features] of the tile at [position], and then returns it */
fun setTileTerrainAndFeatures(position: Vector2, terrain: String, vararg features: String): Tile {
Expand Down
24 changes: 19 additions & 5 deletions tests/src/com/unciv/uniques/ResourceTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class ResourceTests {
val tile = game.tileMap[1,1]
tile.resource = "Coal"
tile.resourceAmount = 1
tile.changeImprovement("Mine")
tile.setImprovement("Mine")

civInfo.tech.addTechnology(game.ruleset.tileImprovements["Mine"]!!.techRequired!!)
assertEquals(civInfo.getCivResourcesByName()["Coal"], 0)
Expand All @@ -91,7 +91,7 @@ class ResourceTests {
val tile = game.tileMap[1,1]
tile.resource = "Coal"
tile.resourceAmount = 1
tile.changeImprovement("Mine")
tile.setImprovement("Mine")

civInfo.tech.addTechnology(game.ruleset.tileImprovements["Mine"]!!.techRequired!!)
civInfo.tech.addTechnology(game.ruleset.tileResources["Coal"]!!.revealedBy!!)
Expand All @@ -106,7 +106,7 @@ class ResourceTests {
fun testImprovementProvidesResourceEvenWithoutTech() {
val tile = game.tileMap[1,1]
val improvement = game.createTileImprovement("Provides [1] [Coal]", "Consumes [1] [Silver]")
tile.changeImprovement(improvement.name, civInfo)
tile.setImprovement(improvement.name, civInfo)
Assert.assertTrue(civInfo.getCivResourcesByName()["Coal"] == 1)
Assert.assertTrue(civInfo.getCivResourcesByName()["Silver"] == -1)
}
Expand All @@ -116,7 +116,7 @@ class ResourceTests {
fun testImprovementProvidesResourceWithUniqueBonuses() {
val tile = game.tileMap[1,1]
val improvement = game.createTileImprovement("Provides [1] [Coal]")
tile.changeImprovement(improvement.name, civInfo)
tile.setImprovement(improvement.name, civInfo)
Assert.assertTrue(civInfo.getCivResourcesByName()["Coal"] == 1)

val doubleCoal = game.createBuilding("Double quantity of [Coal] produced")
Expand Down Expand Up @@ -255,7 +255,6 @@ class ResourceTests {
}



@Test
fun CityResourcesWorkWithConditional() {
// given
Expand All @@ -270,4 +269,19 @@ class ResourceTests {
// then
assertEquals(1f, faith)
}

@Test
fun CityResourcesFromImprovementWithConditional() {
// given
val resource = game.createResource(UniqueType.CityResource.text)
val resourceImprovement = game.createTileImprovement("Provides [2] [${resource.name}] <in [non-[Fresh water]] tiles>")
game.getTile(1,1).addTerrainFeature("Oasis")

// when
game.getTile(1,1).setImprovement(resourceImprovement.name)

// then
val resourceAmountInCapital = city.getAvailableResourceAmount(resource.name)
assert(resourceAmountInCapital == 0)
}
}

0 comments on commit 3160416

Please sign in to comment.