@Test
  public void testUrgencyFull() throws NoSuchFieldException, IllegalAccessException {
    // we are going to check that prices change when urgency change
    // the only stub is the market
    Market market = mock(Market.class);
    when(market.getLastPrice()).thenReturn(50); // so last price is 50
    model.schedule =
        mock(
            Schedule
                .class); // we also mock the schedule to avoid the inventory control from spamming
                         // buy orders in the schedule

    when(market.getGoodType()).thenReturn(UndifferentiatedGoodType.GENERIC);
    Firm f = new Firm(model);

    PurchasesDepartment dept =
        PurchasesDepartment.getPurchasesDepartment(
                100,
                f,
                market,
                FixedInventoryControl.class,
                UrgentPriceFollowerStrategy.class,
                null,
                null)
            .getDepartment();

    // when there is nobody to search just go at random.
    Field field = PurchasesDepartment.class.getDeclaredField("pricingStrategy");
    field.setAccessible(true);
    BidPricingStrategy pricing = (BidPricingStrategy) field.get(dept);

    // assuming the fixed inventory control wants 6

    // right now it's danger
    for (int i = 0; i < 10; i++)
      assertEquals(pricing.maxPrice(UndifferentiatedGoodType.GENERIC), 60);

    // barely
    for (int i = 0; i < 3; i++)
      f.receive(Good.getInstanceOfUndifferentiatedGood(UndifferentiatedGoodType.GENERIC), null);
    for (int i = 0; i < 10; i++)
      assertEquals(pricing.maxPrice(UndifferentiatedGoodType.GENERIC), 50);

    // acceptable
    for (int i = 0; i < 3; i++)
      f.receive(Good.getInstanceOfUndifferentiatedGood(UndifferentiatedGoodType.GENERIC), null);
    for (int i = 0; i < 10; i++)
      assertEquals(pricing.maxPrice(UndifferentiatedGoodType.GENERIC), 40);

    // too much
    for (int i = 0; i < 30; i++)
      f.receive(Good.getInstanceOfUndifferentiatedGood(UndifferentiatedGoodType.GENERIC), null);
    for (int i = 0; i < 10; i++)
      assertEquals(pricing.maxPrice(UndifferentiatedGoodType.GENERIC), 25);
  }
Пример #2
0
  @Test
  public void testStep() throws Exception {

    Blueprint b =
        Blueprint.simpleBlueprint(
            DifferentiatedGoodType.CAPITAL, 1, DifferentiatedGoodType.CAPITAL, 1);
    MacroII localMacroII = new MacroII(1);
    localMacroII.schedule =
        mock(Schedule.class); // put in a fake schedule so we avoid steppables firing at random

    Firm f = new Firm(localMacroII);
    Plant localCRS = new Plant(b, new Firm(localMacroII));
    localCRS.setPlantMachinery(
        new CRSExponentialMachinery(DifferentiatedGoodType.CAPITAL, f, 0, localCRS, 1f, 1f));
    f.addPlant(localCRS);

    SalesDepartmentAllAtOnce stub = mock(SalesDepartmentAllAtOnce.class);
    when(stub.isSelling(any(Good.class))).thenReturn(Boolean.TRUE);
    localCRS.getOwner().registerSaleDepartment(stub, DifferentiatedGoodType.CAPITAL); // fake sales
    // department so that you don't try selling the stuff you build

    localCRS.setCostStrategy(new EmptyCostStrategy());
    try {
      localCRS.getModel();

      localCRS.getModel().getPhaseScheduler().step(localCRS.getModel());

      assertEquals(localCRS.getStatus(), PlantStatus.WAITING_FOR_WORKERS);
      localCRS.addWorker(new Person(localCRS.getModel()));
      localCRS.addWorker(new Person(localCRS.getModel()));

      localCRS.getModel().getPhaseScheduler().step(localCRS.getModel());

      assertEquals(localCRS.getStatus(), PlantStatus.WAITING_FOR_INPUT);
      localCRS
          .getOwner()
          .receive(
              Good.getInstanceOfDifferentiatedGood(
                  DifferentiatedGoodType.CAPITAL, drs.getOwner(), 1),
              drs.getOwner());

      localCRS.getModel().getPhaseScheduler().step(localCRS.getModel());
      assertEquals(
          localCRS.getStatus(), PlantStatus.READY); // you should automatically start production!

    } catch (Exception e) {
      fail("Can't throw exceptions now");
    }
  }
Пример #3
0
  @Test
  public void testTotalInputs() {

    Blueprint b = Blueprint.simpleBlueprint(DifferentiatedGoodType.CAPITAL, 1, BEEF, 1);
    MacroII localMacroII = mock(MacroII.class);
    PhaseScheduler scheduler = mock(PhaseScheduler.class);
    when(localMacroII.getCurrentPhase()).thenReturn(ActionOrder.PRODUCTION);
    when(localMacroII.getPhaseScheduler()).thenReturn(scheduler);
    when(localMacroII.getWeekLength()).thenReturn(7f);
    Firm f = new Firm(localMacroII);
    Plant localCRS = new Plant(b, new Firm(localMacroII));
    localCRS.setPlantMachinery(
        new LinearConstantMachinery(DifferentiatedGoodType.CAPITAL, f, 0, localCRS));
    f.addPlant(localCRS);
    localCRS.addWorker(new Person(localCRS.getModel()));
    localCRS.addWorker(new Person(localCRS.getModel()));
    localCRS
        .getOwner()
        .registerSaleDepartment(
            mock(SalesDepartmentAllAtOnce.class),
            BEEF); // fake sales department so that you don't sell the stuff you
                   // completeProductionRunNow
    localCRS.setCostStrategy(new InputCostStrategy(localCRS));

    // initially they should be set up to 0
    assertEquals(localCRS.getThisWeekInputCosts(), 0);
    assertEquals(localCRS.getLastWeekInputCosts(), 0);

    // now when I step you, you should  say you are waiting for inputs
    localCRS.getModel();
    localCRS.step(localMacroII);
    assertEquals(localCRS.getStatus(), PlantStatus.WAITING_FOR_INPUT);
    assertEquals(localCRS.getThisWeekInputCosts(), 0); // input costs should still be 0
    assertEquals(localCRS.getLastWeekInputCosts(), 0);

    // now I give you one input that costs 10$
    localCRS
        .getOwner()
        .receive(
            Good.getInstanceOfDifferentiatedGood(
                DifferentiatedGoodType.CAPITAL, drs.getOwner(), 10),
            drs.getOwner());
    localCRS.step(localCRS.getModel());
    assertEquals(localCRS.getThisWeekInputCosts(), 10); // input costs should still now be 10
    assertEquals(localCRS.getLastWeekInputCosts(), 0);

    // I'll give you another and force you to step again
    localCRS
        .getOwner()
        .receive(
            Good.getInstanceOfDifferentiatedGood(
                DifferentiatedGoodType.CAPITAL, drs.getOwner(), 10),
            drs.getOwner());
    localCRS.step(localCRS.getModel());
    assertEquals(localCRS.getThisWeekInputCosts(), 20); // input costs should still now be 20
    assertEquals(localCRS.getLastWeekInputCosts(), 0);

    // with weekend it should reset this week and make lastweekinput costs equal 20
    localCRS.weekEnd(7);
    assertEquals(localCRS.getThisWeekInputCosts(), 0); // reset to 0
    assertEquals(localCRS.getLastWeekInputCosts(), 20); // now it's 20

    // try one more time
    localCRS
        .getOwner()
        .receive(
            Good.getInstanceOfDifferentiatedGood(
                DifferentiatedGoodType.CAPITAL, drs.getOwner(), 10),
            drs.getOwner());
    localCRS.step(localCRS.getModel());
    assertEquals(localCRS.getThisWeekInputCosts(), 10); // input costs should now be 10
    assertEquals(localCRS.getLastWeekInputCosts(), 20); // this should be stuck at 20

    // new weekend, forget 20$ and reset this week
    localCRS.weekEnd(14);
    assertEquals(localCRS.getThisWeekInputCosts(), 0); // reset to 0
    assertEquals(localCRS.getLastWeekInputCosts(), 10); // now it's 10

    // another weekend, everything is at 0
    localCRS.weekEnd(0);
    assertEquals(localCRS.getThisWeekInputCosts(), 0); // reset to 0
    assertEquals(localCRS.getLastWeekInputCosts(), 0); // now it's 10
  }