Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LAM crash #6166

Merged
merged 4 commits into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions megamek/src/megamek/client/bot/princess/AeroPathUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public static boolean willStall(MovePath movePath) {
*/
public static boolean willCrash(MovePath movePath) {
return movePath.getEntity().isAero() &&
movePath.isOnAtmosphericGroundMap() &&
(movePath.getFinalAltitude() < 1) &&
!movePath.contains(MoveStepType.VLAND) &&
!movePath.contains(MoveStepType.LAND);
Expand Down
112 changes: 63 additions & 49 deletions megamek/unittests/megamek/client/bot/princess/AeroPathUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,53 +35,67 @@
* @since 07/24/2024
*/
class AeroPathUtilTest {
@Test
void testAssertWillStallOnAtmosphereGroundMap() {
final Entity mockEntity = MockGenerators.generateMockAerospace(0, 0);
final MovePath mockPath = MockGenerators.generateMockPath(16, 16, mockEntity);
when(mockPath.isOnAtmosphericGroundMap()).thenReturn(false);

boolean result = AeroPathUtil.willStall(mockPath);
assertFalse(result);
}

@Test
void testAssertWillStallAsSpheroidDropshipWithVLAND() {
final Entity mockEntity = MockGenerators.generateMockAerospace(0, 0);
when(mockEntity.isSpheroid()).thenReturn(true);

final MovePath mockPath = MockGenerators.generateMockPath(16, 16, mockEntity);
when(mockPath.isOnAtmosphericGroundMap()).thenReturn(true);
when(mockPath.getFinalVelocity()).thenReturn(0);
when(mockPath.getFinalNDown()).thenReturn(0);
when(mockPath.getMpUsed()).thenReturn(0);
when(mockPath.contains(MoveStepType.VLAND)).thenReturn(true);

boolean result = AeroPathUtil.willStall(mockPath);
assertFalse(result);
}

@Test
void testAssertWillCrashWithOutLandOrVland() {
final Entity mockEntity = MockGenerators.generateMockAerospace(0, 0);

final MovePath mockPath = MockGenerators.generateMockPath(16, 16, mockEntity);
when(mockPath.getFinalVelocity()).thenReturn(1);

boolean result = AeroPathUtil.willCrash(mockPath);
assertTrue(result);
}

@Test
void testAssertWillCrashWithLandOrVland() {
final Entity mockEntity = MockGenerators.generateMockAerospace(0, 0);

final MovePath mockPath = MockGenerators.generateMockPath(16, 16, mockEntity);
when(mockPath.getFinalVelocity()).thenReturn(0);
when(mockPath.contains(MoveStepType.VLAND)).thenReturn(true);
when(mockPath.contains(MoveStepType.LAND)).thenReturn(true);

boolean result = AeroPathUtil.willCrash(mockPath);
assertFalse(result);
}
@Test
void testAssertWillStallOnAtmosphereGroundMap() {
final Entity mockEntity = MockGenerators.generateMockAerospace(0, 0);
final MovePath mockPath = MockGenerators.generateMockPath(16, 16, mockEntity);
when(mockPath.isOnAtmosphericGroundMap()).thenReturn(false);

boolean result = AeroPathUtil.willStall(mockPath);
assertFalse(result);
}

@Test
void testAssertWillStallAsSpheroidDropshipWithVLAND() {
final Entity mockEntity = MockGenerators.generateMockAerospace(0, 0);
when(mockEntity.isSpheroid()).thenReturn(true);

final MovePath mockPath = MockGenerators.generateMockPath(16, 16, mockEntity);
when(mockPath.isOnAtmosphericGroundMap()).thenReturn(true);
when(mockPath.getFinalVelocity()).thenReturn(0);
when(mockPath.getFinalNDown()).thenReturn(0);
when(mockPath.getMpUsed()).thenReturn(0);
when(mockPath.contains(MoveStepType.VLAND)).thenReturn(true);

boolean result = AeroPathUtil.willStall(mockPath);
assertFalse(result);
}

@Test
void testAssertWillCrashWithOutLandOrVland() {
final Entity mockEntity = MockGenerators.generateMockAerospace(0, 0);

final MovePath mockPath = MockGenerators.generateMockPath(16, 16, mockEntity);
when(mockPath.getFinalVelocity()).thenReturn(1);
when(mockPath.isOnAtmosphericGroundMap()).thenReturn(true);

boolean result = AeroPathUtil.willCrash(mockPath);
assertTrue(result);
}

@Test
void testAssertWillCrashWithLandOrVland() {
final Entity mockEntity = MockGenerators.generateMockAerospace(0, 0);

final MovePath mockPath = MockGenerators.generateMockPath(16, 16, mockEntity);
when(mockPath.getFinalVelocity()).thenReturn(0);
when(mockPath.contains(MoveStepType.VLAND)).thenReturn(true);
when(mockPath.contains(MoveStepType.LAND)).thenReturn(true);

boolean result = AeroPathUtil.willCrash(mockPath);
assertFalse(result);
}

@Test
void testAssertWillCrashNoAtmosphere() {
final Entity mockEntity = MockGenerators.generateMockAerospace(0, 0);

final MovePath mockPath = MockGenerators.generateMockPath(16, 16, mockEntity);
when(mockPath.getFinalVelocity()).thenReturn(1);
when(mockPath.isOnAtmosphericGroundMap()).thenReturn(false);

boolean result = AeroPathUtil.willCrash(mockPath);
assertFalse(result);
}

}