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

Fix remaining armor test failures #5130

Merged
merged 4 commits into from
Feb 5, 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
3 changes: 3 additions & 0 deletions megamek/src/megamek/common/equipment/ArmorType.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public class ArmorType extends MiscType {
private static final List<ArmorType> allTypes = new ArrayList<>();

public static ArmorType of(int type, boolean clan) {
if (armorTypeLookupClan.isEmpty() && armorTypeLookupIS.isEmpty()) {
initializeTypes();
}
ArmorType armor = clan ? armorTypeLookupClan.get(type) : armorTypeLookupIS.get(type);
// Some mixed tech unit files use the unit tech base instead of the armor tech base.
if (armor == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import megamek.codeUtilities.StringUtility;
import megamek.common.*;
import megamek.common.MovePath.Key;
import megamek.common.equipment.ArmorType;
import megamek.common.options.GameOptions;
import megamek.common.options.OptionsConstants;
import megamek.common.options.PilotOptions;
Expand Down Expand Up @@ -61,6 +62,11 @@ public class BasicPathRankerTest {

@BeforeEach
public void beforeEach() {

// We now need to make sure all armor types are initialized or mockito will complain.
if (!ArmorType.getAllTypes().hasMoreElements()) {
ArmorType.initializeTypes();
}
final BehaviorSettings mockBehavior = mock(BehaviorSettings.class);
when(mockBehavior.getFallShameValue()).thenReturn(BehaviorSettings.FALL_SHAME_VALUES[5]);
when(mockBehavior.getBraveryValue()).thenReturn(BehaviorSettings.BRAVERY[5]);
Expand Down
50 changes: 25 additions & 25 deletions megamek/unittests/megamek/common/loaders/TdbFileTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,34 +39,34 @@
* @author nderwin
*/
public class TdbFileTest {

@Test
public void testJenner() throws Exception {
InputStream is = getClass().getResourceAsStream("JR7-D Jenner.xml");
assertNotNull(is);

TdbFile testMe = TdbFile.getInstance(is);

assertEquals(6, testMe.mounted.items.size());

Entity result = testMe.getEntity();

assertTrue(result instanceof BipedMech);
BipedMech mek = (BipedMech) result;

assertEquals("Jenner", mek.getChassis());
assertEquals("JR7-D", mek.getModel());
assertEquals(35.0f, mek.getWeight(), 0.0f);

assertEquals(Mech.COCKPIT_STANDARD, mek.getCockpitType());
assertEquals(Mech.GYRO_STANDARD, mek.getGyroType());

assertTrue(mek.getEngine().engineValid);
assertTrue(mek.getEngine().isFusion());
assertEquals(Engine.NORMAL_ENGINE, mek.getEngine().getEngineType());
assertEquals(7, mek.getWalkMP());
assertEquals(11, mek.getRunMP());

assertEquals(10, mek.getActiveSinks());

assertEquals(7, mek.getArmor(Mech.LOC_HEAD));
Expand All @@ -80,7 +80,7 @@ public void testJenner() throws Exception {
assertEquals(4, mek.getArmor(Mech.LOC_LARM));
assertEquals(6, mek.getArmor(Mech.LOC_RLEG));
assertEquals(6, mek.getArmor(Mech.LOC_LLEG));

assertFalse(mek.getFailedEquipment().hasNext());

boolean foundSRM = false;
Expand All @@ -90,14 +90,14 @@ public void testJenner() throws Exception {
int jjCT = 0;
int jjRT = 0;
int jjLT = 0;

for (Mounted m : mek.getEquipment()) {
switch (m.getLocation()) {
case Mech.LOC_CT:
if ("Jump Jet".equals(m.getName())) {
jjCT++;
}

if (!foundSRM && "SRM 4".equals(m.getName())) {
foundSRM = true;
} else if (foundSRM && "SRM 4".equals(m.getName())) {
Expand All @@ -112,7 +112,7 @@ public void testJenner() throws Exception {
if ("Jump Jet".equals(m.getName())) {
jjRT++;
}

if (!foundAmmo && "SRM 4 Ammo".equals(m.getName())) {
foundAmmo = true;
} else if (foundAmmo && "SRM 4 Ammo".equals(m.getName())) {
Expand Down Expand Up @@ -151,7 +151,7 @@ public void testJenner() throws Exception {
break;
}
}

assertTrue(foundSRM, "Found SRM-4");
assertTrue(foundAmmo, "Found SRM-4 ammo");
assertEquals(1, jjCT, "Found 1 Jump Jet in CT");
Expand All @@ -160,36 +160,36 @@ public void testJenner() throws Exception {
assertEquals(2, mlRARM, "Found 2 Medium Lasers in RARM");
assertEquals(2, mlLARM, "Found 2 Medium Lasers in LARM");
}

@Test
public void testTarantula() throws Exception {
InputStream is = getClass().getResourceAsStream("ZPH-1A Tarantula.xml");
assertNotNull(is);

TdbFile testMe = TdbFile.getInstance(is);

assertEquals(4, testMe.mounted.items.size());

Entity result = testMe.getEntity();

assertTrue(result instanceof QuadMech);
QuadMech mek = (QuadMech) result;

assertEquals("Tarantula", mek.getChassis());
assertEquals("ZPH-1A", mek.getModel());
assertEquals(25.0f, mek.getWeight(), 0.0f);

assertEquals(Mech.COCKPIT_STANDARD, mek.getCockpitType());
assertEquals(Mech.GYRO_STANDARD, mek.getGyroType());

assertTrue(mek.getEngine().engineValid);
assertTrue(mek.getEngine().isFusion());
assertEquals(Engine.XL_ENGINE, mek.getEngine().getEngineType());
assertEquals(8, mek.getWalkMP());
assertEquals(12, mek.getRunMP());

assertEquals(10, mek.getActiveSinks());

assertEquals(6, mek.getArmor(Mech.LOC_HEAD));
assertEquals(7, mek.getArmor(Mech.LOC_RT));
assertEquals(10, mek.getArmor(Mech.LOC_CT));
Expand All @@ -201,7 +201,7 @@ public void testTarantula() throws Exception {
assertEquals(7, mek.getArmor(Mech.LOC_LARM));
assertEquals(7, mek.getArmor(Mech.LOC_RLEG));
assertEquals(7, mek.getArmor(Mech.LOC_LLEG));

assertFalse(mek.getFailedEquipment().hasNext());

boolean foundSSRM = false;
Expand All @@ -222,7 +222,7 @@ public void testTarantula() throws Exception {
} else if (foundSSRM && "Streak SRM 2".equals(m.getName())) {
fail("Only 1 SSRM-2 in CT");
}

if (!foundAmmo && "Streak SRM 2 Ammo".equals(m.getName())) {
foundAmmo = true;
} else if (foundAmmo && "Streak SRM 2 Ammo".equals(m.getName())) {
Expand Down Expand Up @@ -250,7 +250,7 @@ public void testTarantula() throws Exception {
if ("Double Heat Sink".equals(m.getName())) {
dblHS++;
}

if ("Medium Laser".equals(m.getName())) {
mlLT++;
}
Expand All @@ -263,7 +263,7 @@ public void testTarantula() throws Exception {
if ("Jump Jet".equals(m.getName())) {
jjFRL++;
}

assertFalse(m.getName().contains("Heat Sink"), "Found a Heat Sink in RARM");
assertNotEquals("Medium Laser", m.getName(), "Found a Medium Laser in RARM");
assertNotEquals("Streak SRM 2", m.getName(), "Found a SSRM-2 in RARM");
Expand All @@ -273,7 +273,7 @@ public void testTarantula() throws Exception {
if ("Jump Jet".equals(m.getName())) {
jjFLL++;
}

assertFalse(m.getName().contains("Heat Sink"), "Found a Heat Sink in LARM");
assertNotEquals("Medium Laser", m.getName(), "Found a Medium Laser in LARM");
assertNotEquals("Streak SRM 2", m.getName(), "Found a SSRM-2 in LARM");
Expand Down
Loading