Esempio n. 1
0
    def test_translate_interval(self):
        mean = 50
        interval = (25, 75)
        new_interval = market.translate_interval(interval, mean)
        assert new_interval == interval

        mean = 150
        interval = (40, 60)
        new_interval = market.translate_interval(interval, mean)
        assert new_interval == (45, 65)
Esempio n. 2
0
    def test_interval_is_divergent(self):
        interval = (130, 150)
        price = 100
        mean = 150
        assert market.interval_is_divergent(interval, price, mean) == interval

        price = 99
        assert market.interval_is_divergent(interval, price, mean) == market.translate_interval(interval, mean)

        price = 199
        assert market.interval_is_divergent(interval, price, mean) == interval

        price = 200
        assert market.interval_is_divergent(interval, price, mean) == market.translate_interval(interval, mean)
Esempio n. 3
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