Skip to content

Commit d7f4627

Browse files
committed
fix: update float and int for test data
1 parent 1d55840 commit d7f4627

File tree

3 files changed

+19
-51
lines changed

3 files changed

+19
-51
lines changed

megamek/src/megamek/ai/dataset/ActionAndState.java

-47
This file was deleted.

megamek/src/megamek/ai/neuralnetwork/Brain.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public float[] predict(float[] inputVector) {
125125
return resultArrayFromTensors(outputTensors);
126126
}
127127
} catch (Exception e) {
128-
logger.error("Prediction failed, there is no recourse from this", e);
128+
logger.error("Prediction failed due to an unexpected error", e);
129129
throw new RuntimeException("Failed to make prediction: " + e.getMessage(), e);
130130
}
131131
}

megamek/unittests/megamek/ai/neuralnetwork/BrainTest.java

+18-3
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ private static Collection<TestValue> loadTestValues() {
163163
*/
164164
private static MovementClassification getMovementClassificationFromSplitLine(String[] values) {
165165
// The last value in the line is the classification
166-
return MovementClassification.fromValue(Integer.parseInt(values[values.length-1]));
166+
return MovementClassification.fromValue(parseInt(values[values.length-1]));
167167
}
168168

169169
/**
@@ -175,9 +175,24 @@ private static float[] getInputsFromSplitLine(String[] values) {
175175
// The last value in the line is the classification, so we don't want it in the input value
176176
float[] entry = new float[values.length-1];
177177
for (int i = 0; i < values.length-1; i++) {
178-
entry[i] = Float.parseFloat(values[i]);
178+
entry[i] = parseFloat(values[i]);
179179
}
180180
return entry;
181181
}
182-
// endregion TestSetup
182+
183+
private static float parseFloat(String value) {
184+
try {
185+
return Float.parseFloat(value);
186+
} catch (NumberFormatException e) {
187+
throw new IllegalArgumentException("Invalid float value: " + value + " Possibly invalid test file", e);
188+
}
189+
}
190+
191+
private static int parseInt(String value) {
192+
try {
193+
return Integer.parseInt(value);
194+
} catch (NumberFormatException e) {
195+
throw new IllegalArgumentException("Invalid int value: " + value + " Possibly invalid test file", e);
196+
}
197+
}
183198
}

0 commit comments

Comments
 (0)