|
| 1 | +package net.tfminecraft.simplefactions.map.provinces; |
| 2 | + |
| 3 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 4 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
| 5 | + |
| 6 | +import org.junit.jupiter.api.AfterEach; |
| 7 | +import org.junit.jupiter.api.BeforeEach; |
| 8 | +import org.junit.jupiter.api.Test; |
| 9 | + |
| 10 | +import net.tfminecraft.simplefactions.Cache; |
| 11 | + |
| 12 | +class ProsperitySoftCapTest { |
| 13 | + |
| 14 | + private double previousCap; |
| 15 | + private double previousScale; |
| 16 | + |
| 17 | + @BeforeEach |
| 18 | + void setUp() { |
| 19 | + previousCap = Cache.prosperitySoftCap; |
| 20 | + previousScale = Cache.prosperitySoftCapScale; |
| 21 | + Cache.prosperitySoftCap = 80; |
| 22 | + Cache.prosperitySoftCapScale = 20; |
| 23 | + } |
| 24 | + |
| 25 | + @AfterEach |
| 26 | + void tearDown() { |
| 27 | + Cache.prosperitySoftCap = previousCap; |
| 28 | + Cache.prosperitySoftCapScale = previousScale; |
| 29 | + } |
| 30 | + |
| 31 | + @Test |
| 32 | + void apply_leavesProsperityUpToTheCapAlone() { |
| 33 | + assertEquals(0.0, ProsperitySoftCap.apply(0), 1e-9); |
| 34 | + assertEquals(42.5, ProsperitySoftCap.apply(42.5), 1e-9); |
| 35 | + assertEquals(80.0, ProsperitySoftCap.apply(80), 1e-9); |
| 36 | + } |
| 37 | + |
| 38 | + @Test |
| 39 | + void apply_slowsPastTheCapWithoutACeiling() { |
| 40 | + assertEquals(120.0, ProsperitySoftCap.apply(140), 1e-9); |
| 41 | + assertEquals(160.0, ProsperitySoftCap.apply(240), 1e-9); |
| 42 | + double far = ProsperitySoftCap.apply(10_000); |
| 43 | + assertTrue(far > 600, "expected continued growth far past the cap, was " + far); |
| 44 | + } |
| 45 | + |
| 46 | + @Test |
| 47 | + void diminish_isSmoothAtTheCap() { |
| 48 | + double atCap = ProsperitySoftCap.diminish(80.0, 80.0, 20.0); |
| 49 | + double justAbove = ProsperitySoftCap.diminish(80.001, 80.0, 20.0); |
| 50 | + assertEquals(0.001, justAbove - atCap, 1e-6); |
| 51 | + } |
| 52 | + |
| 53 | + @Test |
| 54 | + void diminish_marginalValueHalvesAtCapPlusThreeScales() { |
| 55 | + double step = 1e-4; |
| 56 | + double at = ProsperitySoftCap.diminish(140.0, 80.0, 20.0); |
| 57 | + double next = ProsperitySoftCap.diminish(140.0 + step, 80.0, 20.0); |
| 58 | + assertEquals(0.5, (next - at) / step, 1e-3); |
| 59 | + } |
| 60 | + |
| 61 | + @Test |
| 62 | + void diminish_zeroCapOrScaleDisablesIt() { |
| 63 | + assertEquals(500.0, ProsperitySoftCap.diminish(500.0, 0.0, 20.0), 1e-9); |
| 64 | + assertEquals(500.0, ProsperitySoftCap.diminish(500.0, 80.0, 0.0), 1e-9); |
| 65 | + } |
| 66 | +} |
0 commit comments