• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java MockPseudoRandom类的典型用法和代码示例

java 1次浏览

本文整理汇总了Java中net.sf.freecol.util.test.MockPseudoRandom的典型用法代码示例。如果您正苦于以下问题:Java MockPseudoRandom类的具体用法?Java MockPseudoRandom怎么用?Java MockPseudoRandom使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

MockPseudoRandom类属于net.sf.freecol.util.test包,在下文中一共展示了MockPseudoRandom类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: testUnitPromotionWorkingInWorkTile

点赞 2

import net.sf.freecol.util.test.MockPseudoRandom; //导入依赖的package包/类
public void testUnitPromotionWorkingInWorkTile() {
    Game game = ServerTestHelper.startServerGame(getTestMap(plains));

    Colony colony = getStandardColony();
    assertTrue("Colony should only have 1 colonist for test setup",
               colony.getUnitCount() == 1);

    Unit colonist = colony.getUnitList().get(0);
    String errMsg = "Error setting test, colonist should not be an expert";
    assertTrue(errMsg, colonist.getType() == colonistType);

    // set colonist as farmer
    Tile tile = colony.getTile().getNeighbourOrNull(Direction.N);
    assertTrue(colony.getOwner().canOwnTile(tile));
    ColonyTile colonyTile = colony.getColonyTile(tile);
    if (!colonyTile.isEmpty()) {
        colonyTile.getUnitList().get(0).setLocation(colony.getBuilding(townHallType));
    }
    assertTrue(colonyTile.canBeWorked());
    colonist.setLocation(colonyTile);
    colonist.changeWorkType(grainType);
    assertEquals("Wrong work allocation",
                 grainType, colonist.getWorkType());
    assertEquals(colonyTile.getUnitList().get(0), colonist);
    // Will colonist gain experience?
    assertTrue(colonyTile.getTotalProductionOf(colonist.getWorkType()) > 0);
    // Can colonist be upgraded
    UnitType learn = spec().getExpertForProducing(colonist.getWorkType());
    assertNotNull(learn);
    assertFalse(learn == colonist.getType());
    assertNotNull(colonist.getUnitChange(UnitChangeType.EXPERIENCE));

    // set some experience
    int expectXP = 10;
    colonist.modifyExperience(expectXP);
    assertEquals("Wrong colonist experience",
                 expectXP, colonist.getExperience());

    // We need a deterministic random
    List<Integer> setValues = new ArrayList<>();
    setValues.add(1);
    MockPseudoRandom mockRandom = new MockPseudoRandom(setValues, true);
    ServerTestHelper.setRandom(mockRandom);

    // Verify initial state
    boolean isExpert = colonist.getType() == expertFarmerType;
    assertFalse("Unit should not be an expert", isExpert);

    // Make upgrade
    ServerTestHelper.newTurn();
    assertTrue(colonist.getExperience() > expectXP);

    // verify upgrade
    isExpert = colonist.getType() == expertFarmerType;
    assertTrue("Unit should now be an expert", isExpert);
}
 

开发者ID:FreeCol,
项目名称:freecol,
代码行数:57,
代码来源:ServerUnitTest.java

示例2: testExposeResource

点赞 2

import net.sf.freecol.util.test.MockPseudoRandom; //导入依赖的package包/类
public void testExposeResource() {
    Game game = ServerTestHelper.startServerGame(getTestMap(savannahForest));
    InGameController igc = ServerTestHelper.getInGameController();

    ServerPlayer dutch = (ServerPlayer)game.getPlayerByNationId("model.nation.dutch");
    Map map = game.getMap();
    Tile tile = map.getTile(5, 8);
    tile.setOwner(dutch);
    tile.setExplored(dutch, true);

    // Almost clear the tile
    Role pioneerRole = spec().getRole("model.role.pioneer");
    ServerUnit hardyPioneer = new ServerUnit(game, tile, dutch,
                                             pioneerType, pioneerRole);
    //TileImprovement clearImprovement
    //    = new TileImprovement(game, tile, clear);
    //tile.add(clearImprovement);
    igc.changeWorkImprovementType(dutch, hardyPioneer, clear);

    // Verify initial state
    assertEquals(8, hardyPioneer.getWorkLeft());
    assertEquals(savannahForest, tile.getType());
    assertFalse(tile.hasResource());

    // Almost finish clearing
    ServerTestHelper.newTurn();
    ServerTestHelper.newTurn();
    ServerTestHelper.newTurn();

    // We need a deterministic random
    List<Integer> setValues = new ArrayList<>();
    setValues.add(1);
    MockPseudoRandom mockRandom = new MockPseudoRandom(setValues, true);
    ServerTestHelper.setRandom(mockRandom);

    // Finish clearing
    ServerTestHelper.newTurn();

    // Verify clearing succeeded and has revealed a resource
    assertEquals(savannah, tile.getType());
    assertTrue(tile.hasResource());
}
 

开发者ID:FreeCol,
项目名称:freecol,
代码行数:43,
代码来源:ServerUnitTest.java

示例3: testCaptureConvert

点赞 2

import net.sf.freecol.util.test.MockPseudoRandom; //导入依赖的package包/类
public void testCaptureConvert() {
    Map map = getTestMap(plains, true);
    Game game = ServerTestHelper.startServerGame(map);
    CombatModel combatModel = game.getCombatModel();
    InGameController igc = ServerTestHelper.getInGameController();

    ServerPlayer dutch = (ServerPlayer)game.getPlayerByNationId("model.nation.dutch");
    ServerPlayer inca = (ServerPlayer)game.getPlayerByNationId("model.nation.inca");
    dutch.setStance(inca, Stance.WAR);
    inca.setStance(dutch, Stance.WAR);

    Tile tile1 = map.getTile(5, 8);
    tile1.setExplored(dutch, true);
    Tile tile2 = map.getTile(4, 8);
    tile2.setExplored(dutch, true);
    Unit missionary = new ServerUnit(game, null, dutch,
                                     jesuitMissionaryType, missionaryRole);
    FreeColTestCase.IndianSettlementBuilder builder
        = new FreeColTestCase.IndianSettlementBuilder(game);
    IndianSettlement is = builder.player(inca)
        .settlementTile(tile1).skillToTeach(null).capital(true)
        .initialBravesInCamp(8).missionary(missionary).build();

    spec().setInteger(GameOptions.NATIVE_CONVERT_PROBABILITY, 100);

    Unit soldier = new ServerUnit(game, tile2, dutch, veteranType,
                                  soldierRole);
    Unit defender = is.getDefendingUnit(soldier);
    assertNotNull(defender);
    assertTrue(defender.getOwner().isIndian());
    
    MockPseudoRandom random = new MockPseudoRandom();
    List<Integer> il = new ArrayList<>();
    il.add(0);
    random.setNextNumbers(il, true);

    List<CombatResult> crs = combatModel.generateAttackResult(random,
        soldier, defender);
    checkCombat("Capture convert", crs,
                CombatResult.WIN, CombatResult.SLAUGHTER_UNIT,
                CombatResult.CAPTURE_CONVERT);
    assertEquals("One unit on tile", 1, tile2.getUnitList().size());
    dutch.csCombat(soldier, defender, crs, new Random(),
                   new ChangeSet());
    assertEquals("Two units on tile", 2, tile2.getUnitList().size());
    assertEquals("Convert on tile", indianConvertType,
                 tile2.getUnitList().get(1).getType());
}
 

开发者ID:FreeCol,
项目名称:freecol,
代码行数:49,
代码来源:CombatTest.java

示例4: testUnitPromotionWorkingInWorkTile

点赞 2

import net.sf.freecol.util.test.MockPseudoRandom; //导入依赖的package包/类
public void testUnitPromotionWorkingInWorkTile() {
    Map map = getTestMap(plains);
    Game game = ServerTestHelper.startServerGame(map);

    Colony colony = getStandardColony();
    assertTrue("Colony should only have 1 colonist for test setup",
               colony.getUnitCount() == 1);

    Unit colonist = colony.getUnitList().get(0);
    String errMsg = "Error setting test, colonist should not be an expert";
    assertTrue(errMsg, colonist.getType() == colonistType);

    // set colonist as farmer
    Tile tile = colony.getTile().getNeighbourOrNull(Direction.N);
    assertTrue(colony.getOwner().canOwnTile(tile));
    ColonyTile colonyTile = colony.getColonyTile(tile);
    if (!colonyTile.isEmpty()) {
        colonyTile.getUnitList().get(0).setLocation(colony.getBuilding(townHallType));
    }
    assertTrue(colonyTile.canBeWorked());
    colonist.setLocation(colonyTile);
    colonist.setWorkType(grainType);
    assertEquals("Wrong work allocation",
                 grainType, colonist.getWorkType());
    assertEquals(colonyTile.getUnitList().get(0), colonist);
    // Will colonist gain experience?
    assertTrue(colonyTile.getTotalProductionOf(colonist.getWorkType()) > 0);
    // Can colonist be upgraded
    UnitType learn = spec().getExpertForProducing(colonist.getWorkType());
    assertNotNull(learn);
    assertTrue(learn != colonist.getType());
    assertTrue(colonist.getType().canBeUpgraded(learn,
                                                ChangeType.EXPERIENCE));

    // set some experience
    int expectXP = 10;
    colonist.modifyExperience(expectXP);
    assertEquals("Wrong colonist experience",
                 expectXP, colonist.getExperience());

    // We need a deterministic random
    List<Integer> setValues = new ArrayList<Integer>();
    setValues.add(1);
    MockPseudoRandom mockRandom = new MockPseudoRandom(setValues, true);
    ServerTestHelper.setRandom(mockRandom);

    // Verify initial state
    boolean isExpert = colonist.getType() == expertFarmerType;
    assertFalse("Unit should not be an expert", isExpert);

    // Make upgrade
    ServerTestHelper.newTurn();
    assertTrue(colonist.getExperience() > expectXP);

    // verify upgrade
    isExpert = colonist.getType() == expertFarmerType;
    assertTrue("Unit should now be an expert", isExpert);
}
 

开发者ID:vishal-mittal,
项目名称:SOEN6471-FreeCol,
代码行数:59,
代码来源:ServerUnitTest.java

示例5: testExposeResource

点赞 2

import net.sf.freecol.util.test.MockPseudoRandom; //导入依赖的package包/类
public void testExposeResource() {
    Map map = getTestMap(savannahForest);
    Game game = ServerTestHelper.startServerGame(map);
    InGameController igc = ServerTestHelper.getInGameController();

    ServerPlayer dutch = (ServerPlayer)game.getPlayer("model.nation.dutch");
    Tile tile = map.getTile(5, 8);
    tile.setOwner(dutch);
    tile.setExploredBy(dutch, true);

    // Almost clear the tile
    ServerUnit hardyPioneer = new ServerUnit(game, tile, dutch,
                                             pioneerType, toolsType);
    //TileImprovement clearImprovement
    //    = new TileImprovement(game, tile, clear);
    //tile.add(clearImprovement);
    igc.changeWorkImprovementType(dutch, hardyPioneer, clear);

    // Verify initial state
    assertEquals(8, hardyPioneer.getWorkLeft());
    assertEquals(savannahForest, tile.getType());
    assertFalse(tile.hasResource());

    // Almost finish clearing
    ServerTestHelper.newTurn();
    ServerTestHelper.newTurn();
    ServerTestHelper.newTurn();

    // We need a deterministic random
    List<Integer> setValues = new ArrayList<Integer>();
    setValues.add(1);
    MockPseudoRandom mockRandom = new MockPseudoRandom(setValues, true);
    ServerTestHelper.setRandom(mockRandom);

    // Finish clearing
    ServerTestHelper.newTurn();

    // Verify clearing succeeded and has revealed a resource
    assertEquals(savannah, tile.getType());
    assertTrue(tile.hasResource());
}
 

开发者ID:vishal-mittal,
项目名称:SOEN6471-FreeCol,
代码行数:42,
代码来源:ServerUnitTest.java

示例6: testMarketRecovery

点赞 2

import net.sf.freecol.util.test.MockPseudoRandom; //导入依赖的package包/类
/**
 * If we wait a number of turns after selling, the market should
 * recover and finally settle back to the initial levels.  Also
 * test that selling reduces the price for other players.
 */
public void testMarketRecovery() {
    Game game = ServerTestHelper.startServerGame(getTestMap());
    InGameController igc = ServerTestHelper.getInGameController();

    ServerPlayer french = (ServerPlayer) game.getPlayer("model.nation.french");
    ServerPlayer english = (ServerPlayer) game.getPlayer("model.nation.english");
    Market frenchMarket = french.getMarket();
    Market englishMarket = english.getMarket();
    int frenchGold = french.getGold();
    int silverPrice = spec().getInitialPrice(silverType);

    // Sell lightly in the English market to check that the good
    // is now considered "traded".
    english.sell(null, silverType, 1, new Random());
    assertTrue(englishMarket.hasBeenTraded(silverType));
    int englishAmount = englishMarket.getAmountInMarket(silverType);

    // Sell heavily in the French market, price should drop.
    french.sell(null, silverType, 200, new Random());
    assertEquals(frenchGold + silverPrice * 200, french.getGold());
    assertTrue(frenchMarket.hasBeenTraded(silverType));
    assertTrue(frenchMarket.getSalePrice(silverType, 1) < silverPrice);

    // Price might have dropped in the English market too, but
    // not as much as for the French.
    assertTrue("English silver increases due to French sales",
        englishMarket.getAmountInMarket(silverType) > englishAmount);
    assertTrue("English silver price might drop due to French sales",
        englishMarket.getSalePrice(silverType, 1) <= silverPrice);
    assertTrue("English silver price should drop less than French",
        englishMarket.getSalePrice(silverType, 1)
        >= frenchMarket.getSalePrice(silverType, 1));

    // Pretend time is passing.
    // Have to advance time as yearly goods removal is initially low.
    game.setTurn(new Turn(200));
    List<Integer> setValues = new ArrayList<Integer>();
    setValues.add(20);
    MockPseudoRandom mockRandom = new MockPseudoRandom(setValues, true);
    ServerTestHelper.setRandom(mockRandom);
    boolean frenchRecovered = false;
    boolean englishRecovered = false;
    for (int i = 0; i < 100; i++) {
        igc.yearlyGoodsAdjust((ServerPlayer) french);
        if (frenchMarket.getSalePrice(silverType, 1) >= silverPrice) {
            frenchRecovered = true;
        }
        igc.yearlyGoodsAdjust((ServerPlayer) english);
        if (englishMarket.getSalePrice(silverType, 1) >= silverPrice) {
            englishRecovered = true;
        }
    }

    // Prices should have recovered.
    assertTrue("French silver price should have recovered",
               frenchRecovered);
    assertTrue("English silver price should have recovered",
               englishRecovered);
}
 

开发者ID:vishal-mittal,
项目名称:SOEN6471-FreeCol,
代码行数:65,
代码来源:ServerPlayerTest.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)