From: Kimmo R. <ki...@us...> - 2010-04-10 19:01:45
|
Update of /cvsroot/arianne/stendhal/tests/games/stendhal/server/entity/player In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv18849/tests/games/stendhal/server/entity/player Modified Files: PlayerTest.java Log Message: Calculate susceptibility from the equipment Index: PlayerTest.java =================================================================== RCS file: /cvsroot/arianne/stendhal/tests/games/stendhal/server/entity/player/PlayerTest.java,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** PlayerTest.java 26 Dec 2009 20:24:46 -0000 1.23 --- PlayerTest.java 10 Apr 2010 19:01:37 -0000 1.24 *************** *** 5,8 **** --- 5,9 ---- import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.CoreMatchers.nullValue; + import static org.hamcrest.number.IsCloseTo.closeTo; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertThat; *************** *** 11,16 **** --- 12,22 ---- import games.stendhal.common.KeyedSlotUtil; import games.stendhal.server.core.engine.StendhalRPZone; + import games.stendhal.server.entity.DamageType; import games.stendhal.server.entity.Entity; + import games.stendhal.server.entity.item.Item; import games.stendhal.server.maps.MockStendlRPWorld; + + import java.util.HashMap; + import marauroa.common.game.RPObject; import marauroa.server.game.db.DatabaseFactory; *************** *** 342,344 **** --- 348,430 ---- } + + /** + * Test that the damage done by a player is of right type. + */ + @Test + public void testGetDamageType() { + Player player = PlayerTestHelper.createPlayer("don Quijote"); + assertThat("Default damage type", player.getDamageType(), is(DamageType.CUT)); + Item item = new Item("torch", "junk", "subclass", + new HashMap<String, String>()); + player.equip("rhand", item); + for (DamageType type : DamageType.values()) { + item.setDamageType(type); + assertThat("Non weapon items should not change the damage type", player.getDamageType(), is(DamageType.CUT)); + } + // turn the item in to a weapon + item.put("class", "club"); + for (DamageType type : DamageType.values()) { + item.setDamageType(type); + assertThat("Damage type should be got from the weapon", player.getDamageType(), is(type)); + } + } + + /** + * Test that players susceptibility is calculated correctly + */ + @Test + public void testGetSusceptibility() { + Player player = PlayerTestHelper.createPlayer("test dummy"); + for (DamageType type : DamageType.values()) { + assertThat("Default susceptibility", player.getSusceptibility(type), closeTo(1.0, 0.00001)); + } + + Item armor = new Item("rainbow armor", "armor", "subclass", + new HashMap<String, String>()); + player.equip("armor", armor); + HashMap<DamageType, Double> armorMap = new HashMap<DamageType, Double>(); + armor.setSusceptibilities(armorMap); + + for (DamageType type : DamageType.values()) { + armorMap.put(type, 0.42); + for (DamageType type2 : DamageType.values()) { + if (type == type2) { + assertThat(player.getSusceptibility(type2), closeTo(0.42, 0.00001)); + } else { + assertThat(player.getSusceptibility(type2), closeTo(1.0, 0.00001)); + } + } + armorMap.remove(type); + } + + Item legs = new Item("rainbow legs", "legs", "subclass", + new HashMap<String, String>()); + player.equip("legs", legs); + HashMap<DamageType, Double> legsMap = new HashMap<DamageType, Double>(); + legs.setSusceptibilities(legsMap); + legsMap.put(DamageType.ICE, 0.5); + + for (DamageType type : DamageType.values()) { + armorMap.put(type, 0.42); + for (DamageType type2 : DamageType.values()) { + double expected; + double ice = 1.0; + if (type2 == DamageType.ICE) { + // Ice effect if we are checking ice resistance + ice = 0.5; + } + if (type == type2) { + // checking the type we gave resistance 0.42 + expected = ice * 0.42; + } else { + // only the ice effect, if any + expected = ice; + } + + assertThat("Susceptibility to " + type2, player.getSusceptibility(type2), closeTo(expected, 0.00001)); + } + armorMap.remove(type); + } + } } |