@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); }
@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"); } }
@Test public void testProduce() throws Exception { macro.schedule = new Schedule(); // create a real schedule, please. assertTrue(crs.getModel().schedule.scheduleComplete()); // the schedule should be empty! assertTrue(!crs.getOwner().hasAny(DifferentiatedGoodType.CAPITAL)); assertTrue(crs.getOwner().hasHowMany(DifferentiatedGoodType.CAPITAL) == 0); crs.getModel().schedule.reset(); crs.getModel() .schedule .scheduleOnce( Schedule.EPOCH, new Person(crs.getModel())); // this is to have the steppable not at time -1 crs.setCostStrategy(new EmptyCostStrategy()); // crs.completeProductionRunNow(); crs.startProductionRun(); // System.out.println(crs.getModel().schedule.getTime()); assertEquals(crs.getStatus(), PlantStatus.READY); assertTrue(crs.getOwner().hasAny(DifferentiatedGoodType.CAPITAL)); assertTrue(crs.getOwner().hasHowMany(DifferentiatedGoodType.CAPITAL) == 2); // here we produced 2 crs.setBlueprint( Blueprint.simpleBlueprint( DifferentiatedGoodType.CAPITAL, 2, DifferentiatedGoodType.CAPITAL, 1)); // dumb technology to test inputs crs.startProductionRun(); assertEquals(crs.getStatus(), PlantStatus.READY); assertTrue( crs.getOwner().hasAny(DifferentiatedGoodType.CAPITAL)); // should still have the stuff assertTrue( crs.getOwner().hasHowMany(DifferentiatedGoodType.CAPITAL) == 1); // burned two, made one crs.startProductionRun(); assertEquals(crs.getStatus(), PlantStatus.WAITING_FOR_INPUT); assertTrue(crs.getOwner().hasAny(DifferentiatedGoodType.CAPITAL)); // no change! assertTrue(crs.getOwner().hasHowMany(DifferentiatedGoodType.CAPITAL) == 1); // check that the counts are right Assert.assertEquals(crs.getOwner().getTodayConsumption(DifferentiatedGoodType.CAPITAL), 2); Assert.assertEquals(crs.getOwner().getTodayProduction(DifferentiatedGoodType.CAPITAL), 3); }
@Before public void setUp() throws Exception { Blueprint b = new Blueprint.Builder() .output(DifferentiatedGoodType.CAPITAL, 2) .build(); // create a simple output macro = new MacroII(1); macro.schedule = mock(Schedule.class); // put in a fake schedule so we avoid steppables firing at random Firm f = new Firm(macro); crs = new Plant(b, new Firm(macro)); crs.setPlantMachinery( new CRSExponentialMachinery(DifferentiatedGoodType.CAPITAL, f, 0, crs, 1f, 1f)); irs = new Plant(b, new Firm(macro)); irs.setPlantMachinery( new IRSExponentialMachinery(DifferentiatedGoodType.CAPITAL, f, 0, irs, 1f, 1f)); drs = new Plant(b, new Firm(macro)); drs.setPlantMachinery( new DRSExponentialMachinery(DifferentiatedGoodType.CAPITAL, f, 0, drs, 1f, 1f)); Person w1 = new Person(macro); Person w2 = new Person(macro); crs.addWorker(w1); crs.addWorker(w2); w1.hired(crs.getOwner(), 9999999); w2.hired(crs.getOwner(), 9999999); w1 = new Person(macro); w2 = new Person(macro); irs.addWorker(w1); irs.addWorker(w2); w1.hired(crs.getOwner(), 9999999); w2.hired(crs.getOwner(), 9999999); w1 = new Person(macro); w2 = new Person(macro); drs.addWorker(w1); drs.addWorker(w2); w1.hired(crs.getOwner(), 9999999); w2.hired(crs.getOwner(), 9999999); SalesDepartmentAllAtOnce stub = mock(SalesDepartmentAllAtOnce.class); crs.getOwner() .registerSaleDepartment( stub, DifferentiatedGoodType .CAPITAL); // fake sales department so that you don't sell the stuff you // completeProductionRunNow irs.getOwner() .registerSaleDepartment( stub, DifferentiatedGoodType .CAPITAL); // fake sales department so that you don't sell the stuff you // completeProductionRunNow drs.getOwner() .registerSaleDepartment( stub, DifferentiatedGoodType .CAPITAL); // fake sales department so that you don't sell the stuff you // completeProductionRunNow when(stub.isSelling(any(Good.class))).thenReturn(Boolean.TRUE); crs.setCostStrategy(new EmptyCostStrategy()); irs.setCostStrategy(new EmptyCostStrategy()); drs.setCostStrategy(new EmptyCostStrategy()); }