Exemplo n.º 1
0
    def setUp(self):
        self.inventory = GenericStorage()
        self.owner_inventory = GenericStorage()

        class Instance(object):
            def __init__(self, comp):
                self.comp = comp

            def get_component(self, x):
                class Comp(object):
                    inventory = self.comp

                return Comp()

        self.tradepost = TradePostComponent()
        self.tradepost.instance = Instance(self.inventory)
        self.tradepost.instance.owner = Instance(self.owner_inventory)
        self.tradepost.initialize()

        class Timer(object):
            def add_call(self, x):
                pass

            def get_ticks(self, x):
                return 100

        Scheduler.create_instance(timer=Timer())
	def setUp(self):
		self.inventory = GenericStorage()
		self.owner_inventory = GenericStorage()

		class Instance:
			def __init__(self, comp):
				self.comp = comp
				self.owner = None # type: Optional[Instance]

			def get_component(self, x):
				class Comp:
					inventory = self.comp
				return Comp()

		self.tradepost = TradePostComponent()
		self.tradepost.instance = Instance(self.inventory)
		self.tradepost.instance.owner = Instance(self.owner_inventory)
		self.tradepost.initialize()

		class Timer:
			def add_call(self, x):
				pass

			def get_ticks(self, x):
				return 100
		Scheduler.create_instance(timer=Timer())
Exemplo n.º 3
0
	def test_reset_all(self):
		s = GenericStorage()
		s.alter(1, 5)
		s.alter(2, 3)
		s.reset_all()
		self.assertEqual(s[1], 0)
		self.assertEqual(s[2], 0)
Exemplo n.º 4
0
	def test_alter(self):
		s = GenericStorage()
		self.assertEqual(s.alter(1, 5), 0)
		self.assertEqual(s.alter(2, 3), 0)
		self.assertEqual(s[1], 5)
		self.assertEqual(s[2], 3)

		self.assertEqual(s.alter(1, 10), 0)
		self.assertEqual(s[1], 15)
Exemplo n.º 5
0
	def test_alter(self):
		s = GenericStorage()
		self.assertEqual(s.alter(1, 5), 0)
		self.assertEqual(s.alter(2, 3), 0)
		self.assertEqual(s[1], 5)
		self.assertEqual(s[2], 3)

		self.assertEqual(s.alter(1, 10), 0)
		self.assertEqual(s[1], 15)
Exemplo n.º 6
0
	def test_reset_all(self):
		s = GenericStorage()
		s.alter(1, 5)
		s.alter(2, 3)
		s.reset_all()
		self.assertEqual(s[1], 0)
		self.assertEqual(s[2], 0)
Exemplo n.º 7
0
class TestTradePostComponent(TestCase):
    """
	TODO: buy_resource, sell_resource (needs ships and player concept)
	"""
    def setUp(self):
        self.inventory = GenericStorage()
        self.owner_inventory = GenericStorage()

        class Instance(object):
            def __init__(self, comp):
                self.comp = comp

            def get_component(self, x):
                class Comp(object):
                    inventory = self.comp

                return Comp()

        self.tradepost = TradePostComponent()
        self.tradepost.instance = Instance(self.inventory)
        self.tradepost.instance.owner = Instance(self.owner_inventory)
        self.tradepost.initialize()

        class Timer(object):
            def add_call(self, x):
                pass

            def get_ticks(self, x):
                return 100

        Scheduler.create_instance(timer=Timer())

    def tearDown(self):
        Scheduler.destroy_instance()

    def test_buy(self):
        self.owner_inventory.alter(RES.GOLD, 1)
        self.assertFalse(self.tradepost.buy(1, 1, 1, 100))
        self.tradepost.set_slot(0, 1, False, 2)
        self.assertTrue(self.tradepost.buy(1, 1, 1, 100))
        self.assertEqual(self.tradepost.buy_expenses, 1)

        Scheduler().cur_tick += 1

        # ran out of money
        self.assertFalse(self.tradepost.buy(1, 1, 1, 100))

        self.owner_inventory.alter(RES.GOLD, 2)
        self.assertTrue(self.tradepost.buy(1, 1, 1, 100))

        Scheduler().cur_tick += 1

        # only wanted to buy 2
        self.assertFalse(self.tradepost.buy(1, 1, 1, 100))

        self.inventory.alter(1, -2)
        self.assertTrue(self.tradepost.buy(1, 1, 1, 100))

        self.tradepost.clear_slot(0, True)
        # not buying any more
        self.assertFalse(self.tradepost.buy(1, 1, 1, 100))
        self.assertEqual(self.tradepost.buy_expenses, 3)
        self.assertEqual(self.tradepost.total_expenses, 3)

    def test_sell(self):
        self.inventory.alter(1, 1)
        self.assertFalse(self.tradepost.sell(1, 1, 1, 100))
        self.tradepost.set_slot(0, 1, True, 0)  # sell until 0
        self.assertTrue(self.tradepost.sell(1, 1, 1, 100))
        self.assertEqual(self.tradepost.sell_income, 1)

        Scheduler().cur_tick += 1

        # ran out of res
        self.assertFalse(self.tradepost.sell(1, 1, 1, 100))

        Scheduler().cur_tick += 1

        self.inventory.alter(1, 1)
        self.assertTrue(self.tradepost.sell(1, 1, 1, 100))

        self.tradepost.clear_slot(0, True)
        # not selling any more
        self.assertFalse(self.tradepost.sell(1, 1, 1, 100))
        self.assertEqual(self.tradepost.sell_income, 2)
        self.assertEqual(self.tradepost.total_earnings, 2)
Exemplo n.º 8
0
	def test_get_item(self):
		s = GenericStorage()
		s.alter(1, 5)
		self.assertEqual(s[1], 5)
		self.assertEqual(s[2], 0)
Exemplo n.º 9
0
	def test_sum_of_stored_resources(self):
		s = GenericStorage()
		s.alter(1, 5)
		s.alter(2, 3)
		self.assertEqual(s.get_sum_of_stored_resources(), 8)
Exemplo n.º 10
0
	def test_limit(self):
		s = GenericStorage()
		self.assertEqual(s.get_limit(), sys.maxint)
		self.assertEqual(s.get_limit(1), sys.maxint)
Exemplo n.º 11
0
	def test_get_item(self):
		s = GenericStorage()
		s.alter(1, 5)
		self.assertEqual(s[1], 5)
		self.assertEqual(s[2], 0)
Exemplo n.º 12
0
	def test_sum_of_stored_resources(self):
		s = GenericStorage()
		s.alter(1, 5)
		s.alter(2, 3)
		self.assertEqual(s.get_sum_of_stored_resources(), 8)
Exemplo n.º 13
0
	def test_limit(self):
		s = GenericStorage()
		self.assertEqual(s.get_limit(), sys.maxint)
		self.assertEqual(s.get_limit(1), sys.maxint)
class TestTradePostComponent(TestCase):
	"""
	TODO: buy_resource, sell_resource (needs ships and player concept)
	"""

	def setUp(self):
		self.inventory = GenericStorage()
		self.owner_inventory = GenericStorage()

		class Instance:
			def __init__(self, comp):
				self.comp = comp
				self.owner = None # type: Optional[Instance]

			def get_component(self, x):
				class Comp:
					inventory = self.comp
				return Comp()

		self.tradepost = TradePostComponent()
		self.tradepost.instance = Instance(self.inventory)
		self.tradepost.instance.owner = Instance(self.owner_inventory)
		self.tradepost.initialize()

		class Timer:
			def add_call(self, x):
				pass

			def get_ticks(self, x):
				return 100
		Scheduler.create_instance(timer=Timer())

	def tearDown(self):
		Scheduler.destroy_instance()

	def test_buy(self):
		self.owner_inventory.alter(RES.GOLD, 1)
		self.assertFalse(self.tradepost.buy(1, 1, 1, 100))
		self.tradepost.set_slot(0, 1, False, 2)
		self.assertTrue(self.tradepost.buy(1, 1, 1, 100))
		self.assertEqual(self.tradepost.buy_expenses, 1)

		Scheduler().cur_tick += 1

		# ran out of money
		self.assertFalse(self.tradepost.buy(1, 1, 1, 100))

		self.owner_inventory.alter(RES.GOLD, 2)
		self.assertTrue(self.tradepost.buy(1, 1, 1, 100))

		Scheduler().cur_tick += 1

		# only wanted to buy 2
		self.assertFalse(self.tradepost.buy(1, 1, 1, 100))

		self.inventory.alter(1, -2)
		self.assertTrue(self.tradepost.buy(1, 1, 1, 100))

		self.tradepost.clear_slot(0, True)
		# not buying any more
		self.assertFalse(self.tradepost.buy(1, 1, 1, 100))
		self.assertEqual(self.tradepost.buy_expenses, 3)
		self.assertEqual(self.tradepost.total_expenses, 3)

	def test_sell(self):
		self.inventory.alter(1, 1)
		self.assertFalse(self.tradepost.sell(1, 1, 1, 100))
		self.tradepost.set_slot(0, 1, True, 0) # sell until 0
		self.assertTrue(self.tradepost.sell(1, 1, 1, 100))
		self.assertEqual(self.tradepost.sell_income, 1)

		Scheduler().cur_tick += 1

		# ran out of res
		self.assertFalse(self.tradepost.sell(1, 1, 1, 100))

		Scheduler().cur_tick += 1

		self.inventory.alter(1, 1)
		self.assertTrue(self.tradepost.sell(1, 1, 1, 100))

		self.tradepost.clear_slot(0, True)
		# not selling any more
		self.assertFalse(self.tradepost.sell(1, 1, 1, 100))
		self.assertEqual(self.tradepost.sell_income, 2)
		self.assertEqual(self.tradepost.total_earnings, 2)