From 9475fc9e3e9956e737c27974c7462360dd4db13d Mon Sep 17 00:00:00 2001 From: DM0000 <98051919+DM0000@users.noreply.github.com> Date: Sat, 26 Oct 2024 10:24:05 -0700 Subject: [PATCH 1/4] added atmosphere check to willCrash --- megamek/src/megamek/client/bot/princess/AeroPathUtil.java | 1 + 1 file changed, 1 insertion(+) diff --git a/megamek/src/megamek/client/bot/princess/AeroPathUtil.java b/megamek/src/megamek/client/bot/princess/AeroPathUtil.java index bb946965c85..a921ca419d9 100644 --- a/megamek/src/megamek/client/bot/princess/AeroPathUtil.java +++ b/megamek/src/megamek/client/bot/princess/AeroPathUtil.java @@ -120,6 +120,7 @@ public static boolean willCrash(MovePath movePath) { return movePath.getEntity().isAero() && (movePath.getFinalAltitude() < 1) && !movePath.contains(MoveStepType.VLAND) && + movePath.isOnAtmosphericGroundMap() && !movePath.contains(MoveStepType.LAND); } From 1257fee67f4992ddcd7266a8eecfd91421b976a5 Mon Sep 17 00:00:00 2001 From: DM0000 <98051919+DM0000@users.noreply.github.com> Date: Fri, 1 Nov 2024 17:28:21 -0700 Subject: [PATCH 2/4] Added unit test --- .../megamek/client/bot/princess/AeroPathUtil.java | 2 +- .../client/bot/princess/AeroPathUtilTest.java | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/megamek/src/megamek/client/bot/princess/AeroPathUtil.java b/megamek/src/megamek/client/bot/princess/AeroPathUtil.java index a921ca419d9..a8c46874aef 100644 --- a/megamek/src/megamek/client/bot/princess/AeroPathUtil.java +++ b/megamek/src/megamek/client/bot/princess/AeroPathUtil.java @@ -118,9 +118,9 @@ 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.isOnAtmosphericGroundMap() && !movePath.contains(MoveStepType.LAND); } diff --git a/megamek/unittests/megamek/client/bot/princess/AeroPathUtilTest.java b/megamek/unittests/megamek/client/bot/princess/AeroPathUtilTest.java index 7d4398252cd..ecfa002ec46 100644 --- a/megamek/unittests/megamek/client/bot/princess/AeroPathUtilTest.java +++ b/megamek/unittests/megamek/client/bot/princess/AeroPathUtilTest.java @@ -84,4 +84,18 @@ void testAssertWillCrashWithLandOrVland() { 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); + } + + } From 61c9f86ce1963f15092372cb7854d0afad0d0463 Mon Sep 17 00:00:00 2001 From: DM0000 <98051919+DM0000@users.noreply.github.com> Date: Fri, 1 Nov 2024 17:52:40 -0700 Subject: [PATCH 3/4] fixed formatting --- .../client/bot/princess/AeroPathUtilTest.java | 123 +++++++++--------- 1 file changed, 61 insertions(+), 62 deletions(-) diff --git a/megamek/unittests/megamek/client/bot/princess/AeroPathUtilTest.java b/megamek/unittests/megamek/client/bot/princess/AeroPathUtilTest.java index ecfa002ec46..bee36cc394b 100644 --- a/megamek/unittests/megamek/client/bot/princess/AeroPathUtilTest.java +++ b/megamek/unittests/megamek/client/bot/princess/AeroPathUtilTest.java @@ -35,67 +35,66 @@ * @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 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); - } - + @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 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); + } } From 336ba8f2d364fd854ecdf64efc4d9c76c34a31bc Mon Sep 17 00:00:00 2001 From: DM0000 <98051919+DM0000@users.noreply.github.com> Date: Fri, 1 Nov 2024 18:42:13 -0700 Subject: [PATCH 4/4] fix broken test --- .../unittests/megamek/client/bot/princess/AeroPathUtilTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/megamek/unittests/megamek/client/bot/princess/AeroPathUtilTest.java b/megamek/unittests/megamek/client/bot/princess/AeroPathUtilTest.java index bee36cc394b..e08827e89c5 100644 --- a/megamek/unittests/megamek/client/bot/princess/AeroPathUtilTest.java +++ b/megamek/unittests/megamek/client/bot/princess/AeroPathUtilTest.java @@ -67,6 +67,7 @@ void testAssertWillCrashWithOutLandOrVland() { 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);