Ejemplo n.º 1
0
    def test_update_beliefs_accepted(self):
        interval = (40, 60)
        mean = 150
        translated_shrunken = market.shrink_interval(market.translate_interval(interval, mean))
        shrunken = market.shrink_interval(interval)

        trade = market.Trade(resource="wood", price=150, requested=3, type="buy")
        market.trade_history = (
            (
                market.Trade(resource="wood", price=140, type="buy", requested=3, status="accepted"),
                market.Trade(resource="wood", price=160, type="buy", requested=3, status="accepted"),
            ),
        )
        npc = market.NPC(belief_intervals=market.BeliefIntervals(wood=interval))
        new_npc = market.update_beliefs_accepted(npc, trade)
        assert new_npc.belief_intervals.wood == shrunken  # No interval translation

        # Test lower bounds
        trade = market.Trade(resource="wood", price=99, requested=3, type="buy")
        new_npc = market.update_beliefs_accepted(npc, trade)
        assert new_npc.belief_intervals.wood == translated_shrunken  # Interval translation
        trade = market.Trade(resource="wood", price=100, requested=3, type="buy")
        new_npc = market.update_beliefs_accepted(npc, trade)
        assert new_npc.belief_intervals.wood == shrunken

        # Test upper bounds
        trade = market.Trade(resource="wood", price=199, requested=3, type="buy")
        new_npc = market.update_beliefs_accepted(npc, trade)
        assert new_npc.belief_intervals.wood == shrunken  # Interval translation
        trade = market.Trade(resource="wood", price=200, requested=3, type="buy")
        new_npc = market.update_beliefs_accepted(npc, trade)
        assert new_npc.belief_intervals.wood == translated_shrunken
Ejemplo n.º 2
0
 def test_shrink_interval(self):
     assert market.shrink_interval((100, 1000)) == (105, 950)