Skip to content

Commit 0d4959b

Browse files
committed
Do not multiply double <1 with ind
Improved Unit Test
1 parent 3065057 commit 0d4959b

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

MekHQ/src/mekhq/campaign/randomEvents/prisoners/PrisonerEventManager.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ int degradeTemporaryCapacity() {
179179
int newCapacity = 0;
180180

181181
if (temporaryCapacityModifier != DEFAULT_TEMPORARY_CAPACITY) {
182-
int differendInTemporaryCapacity = abs(DEFAULT_TEMPORARY_CAPACITY-temporaryCapacityModifier);
183-
int degreeOfChange = (int) max(1,round(differendInTemporaryCapacity * TEMPORARY_CAPACITY_DEGRADE_RATE));
182+
double differendInTemporaryCapacity = (double) abs(DEFAULT_TEMPORARY_CAPACITY-temporaryCapacityModifier);
183+
int degreeOfChange = max(1,(int) round(differendInTemporaryCapacity * TEMPORARY_CAPACITY_DEGRADE_RATE));
184184

185185
if (temporaryCapacityModifier < DEFAULT_TEMPORARY_CAPACITY) {
186186
temporaryCapacityModifier += degreeOfChange;

MekHQ/unittests/mekhq/campaign/randomEvents/prisoners/PrisonerEventManagerTest.java

+5
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import static mekhq.campaign.randomEvents.prisoners.PrisonerEventManager.DEFAULT_TEMPORARY_CAPACITY;
3636
import static mekhq.campaign.randomEvents.prisoners.PrisonerEventManager.TEMPORARY_CAPACITY_DEGRADE_RATE;
3737
import static org.junit.jupiter.api.Assertions.assertEquals;
38+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
3839
import static org.junit.jupiter.api.Assertions.assertFalse;
3940
import static org.junit.jupiter.api.Assertions.assertTrue;
4041
import static org.mockito.Mockito.mock;
@@ -85,6 +86,7 @@ void testDegradeTemporaryCapacity_DegradeDownTowardsDefault() {
8586

8687
// Assert
8788
assertEquals(expectedValue, actualValue);
89+
assertNotEquals(INITIAL_TEMPORARY_CAPACITY, actualValue);
8890
}
8991

9092
@Test
@@ -109,6 +111,7 @@ void testDegradeTemporaryCapacity_DegradeDownTowardsDefault_ResultBelowDefault()
109111

110112
// Assert
111113
assertEquals(expectedValue, actualValue);
114+
assertNotEquals(INITIAL_TEMPORARY_CAPACITY, actualValue);
112115
}
113116

114117
@Test
@@ -136,6 +139,7 @@ void testDegradeTemporaryCapacity_DegradeUpTowardsDefault() {
136139

137140
// Assert
138141
assertEquals(expectedValue, actualValue);
142+
assertNotEquals(INITIAL_TEMPORARY_CAPACITY, actualValue);
139143
}
140144

141145
@Test
@@ -160,6 +164,7 @@ void testDegradeTemporaryCapacity_DegradeUpTowardsDefault_ResultAboveDefault() {
160164

161165
// Assert
162166
assertEquals(expectedValue, actualValue);
167+
assertNotEquals(INITIAL_TEMPORARY_CAPACITY, actualValue);
163168
}
164169

165170
@Test

0 commit comments

Comments
 (0)