1
0
mirror of https://github.com/chylex/Hardcore-Ender-Expansion-2.git synced 2025-02-27 15:46:01 +01:00

Move unit tests and add main methods with special tests

This commit is contained in:
chylex 2021-01-23 13:58:34 +01:00
parent 276df76979
commit e9077c680f
7 changed files with 61 additions and 22 deletions
src
system/src/main/java/chylex/hee/game/loot/rng
test/java/chylex/hee/test

View File

@ -10,24 +10,6 @@ class RandomBiasedValueRange(range: ClosedFloatingPointRange<Float>, private val
require(highestChanceValue in min..max) { "highestChanceValue must be between min and max" }
}
/*
import java.util.Random
import chylex.hee.system.random.nextBiasedFloat
import kotlin.math.roundToInt
val rand = Random()
(1..100000).map {
val min = 3F
val max = 10F
val highestChanceValue = 6.5F
val biasSoftener = 3F
(highestChanceValue + (rand.nextBiasedFloat(biasSoftener) * (0.5F + max - highestChanceValue)) - (rand.nextBiasedFloat(biasSoftener) * (0.5F + highestChanceValue - min))).roundToInt()
}.groupBy { it }.mapValues { it.value.size }.toList().sortedBy { it.first }
*/
override fun generateInt(rand: Random): Int {
return (highestChanceValue + (rand.nextBiasedFloat(biasSoftener) * (0.5F + max - highestChanceValue)) - (rand.nextBiasedFloat(biasSoftener) * (0.5F + highestChanceValue - min))).roundToInt()
}

View File

@ -0,0 +1,28 @@
package chylex.hee.test.main
import chylex.hee.game.loot.rng.RandomBiasedValueRange
import java.util.Random
import kotlin.math.roundToInt
fun main() {
val min = 3F
val max = 10F
val highestChanceValue = 6.5F
val biasSoftener = 3F
val rand = Random()
val generator = RandomBiasedValueRange(min..max, highestChanceValue, biasSoftener)
val reps = 100000
val results = (1..reps).map { generator.generateInt(rand) }
.groupBy { it }
.mapValues { it.value.size }
.toList()
.sortedBy { it.first }
val pad1 = results.maxOf { it.first.toString().length }
val pad2 = results.maxOf { it.second.toString().length }
println(results.joinToString("\n") {
"${it.first.toString().padStart(pad1)} | ${it.second.toString().padStart(pad2)} | ${((it.second * 100.0) / reps).roundToInt().toString().padStart(2)} %"
})
}

View File

@ -0,0 +1,29 @@
package chylex.hee.test.main
import chylex.hee.game.world.feature.tombdungeon.TombDungeonLevel
import chylex.hee.game.world.feature.tombdungeon.TombDungeonLevel.MobAmount
import java.util.Random
import kotlin.math.roundToInt
fun main() {
val rand = Random()
for(level in TombDungeonLevel.values()) {
val reps = 100000
println("\n")
println("-".repeat(level.name.length))
println(level.name)
println("-".repeat(level.name.length))
println(MobAmount.values().joinToString("\n") { amount ->
"\n " + amount.name + "\n\n" + (1..reps)
.map { level.pickUndreadAndSpiderlingSpawns(rand, amount) }
.groupingBy { it }
.eachCount()
.entries
.map { ((it.value * 100.0) / reps).roundToInt() to it.key }
.sortedWith(compareBy({ -it.first }, { -it.second.first }, { -it.second.second }))
.joinToString("\n") { " U = ${it.second.first}, S = ${it.second.second} ... ${it.first} %" }
})
}
}

View File

@ -1,4 +1,4 @@
package chylex.hee.test.mechanics.damage
package chylex.hee.test.unit.mechanics.damage
import chylex.hee.game.mechanics.damage.DamageProperties
import chylex.hee.game.mechanics.damage.DamageType

View File

@ -1,4 +1,4 @@
package chylex.hee.test.mechanics.energy
package chylex.hee.test.unit.mechanics.energy
import chylex.hee.game.mechanics.energy.IEnergyQuantity.Floating
import chylex.hee.game.mechanics.energy.IEnergyQuantity.Internal

View File

@ -1,4 +1,4 @@
package chylex.hee.test.system.util
package chylex.hee.test.unit.system
import chylex.hee.game.world.Pos
import chylex.hee.system.math.Vec

View File

@ -1,4 +1,4 @@
package chylex.hee.test.system.util
package chylex.hee.test.unit.system
import chylex.hee.game.inventory.cleanupNBT
import chylex.hee.game.inventory.heeTag