コード例 #1
0
  @Test
  public void scenario4() {

    DummyBuyer buyer1 = new DummyBuyer(model, -1, market);
    market.registerBuyer(buyer1);
    DummyBuyer buyer2 = new DummyBuyer(model, -1, market);
    market.registerBuyer(buyer2);

    List<EconomicAgent> sample = Arrays.asList(toTest.sampleBuyers());
    assertTrue(sample.size() == 2);

    EconomicAgent bestBuyer = toTest.getBestInSampleBuyer();
    assertTrue(bestBuyer == null);
  }
コード例 #2
0
  @Test
  public void scenario1() {

    DummyBuyer buyer1 = new DummyBuyer(model, 10, market);
    market.registerBuyer(buyer1);
    DummyBuyer buyer2 = new DummyBuyer(model, 20, market);
    market.registerBuyer(buyer2);
    DummyBuyer buyer3 = new DummyBuyer(model, 30, market);
    market.registerBuyer(buyer3);
    DummyBuyer buyer4 = new DummyBuyer(model, 40, market);
    market.registerBuyer(buyer4);
    DummyBuyer buyer5 = new DummyBuyer(model, 50, market);
    market.registerBuyer(buyer5);

    List<EconomicAgent> sample = Arrays.asList(toTest.sampleBuyers());
    assertTrue(sample.size() == 5);
    assertTrue(sample.contains(buyer1));
    assertTrue(sample.contains(buyer2));
    assertTrue(sample.contains(buyer3));
    assertTrue(sample.contains(buyer4));
    assertTrue(sample.contains(buyer5));

    EconomicAgent bestBuyer = toTest.getBestInSampleBuyer();
    assertEquals(buyer5, bestBuyer);
    assertEquals(50, bestBuyer.askedForABuyOffer(UndifferentiatedGoodType.GENERIC));

    buyer5.setQuotedPrice(5);

    toTest.reactToSuccess(buyer5, PurchaseResult.SUCCESS);

    bestBuyer = toTest.getBestInSampleBuyer();
    assertEquals(buyer5, bestBuyer);
    assertEquals(5, bestBuyer.askedForABuyOffer(UndifferentiatedGoodType.GENERIC));

    toTest.reactToFailure(buyer5, PurchaseResult.SUCCESS);

    bestBuyer = toTest.getBestInSampleBuyer();
    assertEquals(buyer4, bestBuyer);
    assertEquals(40, bestBuyer.askedForABuyOffer(UndifferentiatedGoodType.GENERIC));
  }
コード例 #3
0
  @Test
  public void scenario2() {

    DummyBuyer buyer1 = new DummyBuyer(model, -1, market);
    market.registerBuyer(buyer1);
    DummyBuyer buyer2 = new DummyBuyer(model, -1, market);
    market.registerBuyer(buyer2);
    DummyBuyer buyer3 = new DummyBuyer(model, 100, market);
    market.registerBuyer(buyer3);
    DummyBuyer buyer4 = new DummyBuyer(model, 2000, market);
    market.registerBuyer(buyer4);
    DummyBuyer buyer5 = new DummyBuyer(model, -1, market);
    market.registerBuyer(buyer5);
    DummyBuyer buyer6 = new DummyBuyer(model, -1, market);
    market.registerBuyer(buyer6);

    List<EconomicAgent> sample = Arrays.asList(toTest.sampleBuyers());
    assertTrue(sample.size() == 5);

    EconomicAgent bestBuyer = toTest.getBestInSampleBuyer();
    assertTrue(bestBuyer == buyer3 || bestBuyer == buyer4);
  }