コード例 #1
0
ファイル: unitmgr_test.py プロジェクト: mtday/pygame
 def test_add(self):
     unitmgr = UnitMgr(None, Menu(None))
     unitmgr.add(Unit('type1', UnitInfo(1, 1, 1, Coord())))
     unitmgr.add(Unit('type2', UnitInfo(2, 1, 1, Coord())))
     self.assertEqual(len(unitmgr), 2)
     self.assertTrue(1 in unitmgr)
     self.assertTrue(2 in unitmgr)
コード例 #2
0
 def test_eq(self):
     # Only the unit id is checked
     a = Unit('type1', UnitInfo(1, 2, 3, Coord(1, 2, -3)))
     b = Unit('type1', UnitInfo(2, 2, 3, Coord(1, 2, -3)))
     self.assertTrue(a == a)
     self.assertFalse(a == b)
     self.assertFalse(b == a)
     self.assertTrue(b == b)
コード例 #3
0
ファイル: unitmgr_test.py プロジェクト: mtday/pygame
    def test_get_by_id(self):
        unitmgr = UnitMgr(None, Menu(None))
        unitmgr.add(Unit('type1', UnitInfo(1, 1, 1, Coord())))
        unitmgr.add(Unit('type2', UnitInfo(2, 1, 1, Coord())))

        missing = unitmgr.get_by_id('missing')
        self.assertIsNone(missing)

        unit1 = unitmgr.get_by_id(1)
        self.assertIsNotNone(unit1)
        self.assertEqual(unit1.unit_type, 'type1')
        self.assertEqual(unit1.unit_info.unit_id, 1)
コード例 #4
0
 def test_init(self):
     unit = Unit('type', UnitInfo(10, 11, 12, Coord(1, 2, -3)))
     self.assertEqual(unit.unit_type, 'type')
     self.assertEqual(unit.unit_info.unit_id, 10)
     self.assertEqual(unit.unit_info.user_id, 11)
     self.assertEqual(unit.unit_info.game_id, 12)
     self.assertEqual(unit.unit_info.coord, Coord(1, 2, -3))
コード例 #5
0
ファイル: unitmgr_test.py プロジェクト: mtday/pygame
    def test_get_selected_default(self):
        unitmgr = UnitMgr(None, Menu(None))
        a = Unit('type1', UnitInfo(1, 1, 1, Coord()))
        b = Unit('type2', UnitInfo(2, 1, 1, Coord()))
        unitmgr.add(a)
        unitmgr.add(b)

        empty = unitmgr.get_selected()
        self.assertIsNotNone(empty)
        self.assertEqual(len(empty), 0)

        a.selected = True

        sel = unitmgr.get_selected()
        self.assertIsNotNone(sel)
        self.assertEqual(len(sel), 1)
        self.assertEqual(sel[0].unit_info.unit_id, a.unit_info.unit_id)
コード例 #6
0
ファイル: unitmgr_test.py プロジェクト: mtday/pygame
    def test_remove_by_id(self):
        unitmgr = UnitMgr(None, Menu(None))
        unitmgr.add(Unit('type1', UnitInfo(1, 1, 1, Coord())))
        unitmgr.add(Unit('type2', UnitInfo(2, 1, 1, Coord())))
        self.assertEqual(len(unitmgr), 2)
        self.assertTrue(1 in unitmgr)
        self.assertTrue(2 in unitmgr)

        unitmgr.remove_by_id(3)
        self.assertEqual(len(unitmgr), 2)
        self.assertTrue(1 in unitmgr)
        self.assertTrue(2 in unitmgr)

        unitmgr.remove_by_id(1)
        self.assertEqual(len(unitmgr), 1)
        self.assertFalse(1 in unitmgr)
        self.assertTrue(2 in unitmgr)
コード例 #7
0
ファイル: unitmgr_test.py プロジェクト: mtday/pygame
    def test_get_selected_false(self):
        unitmgr = UnitMgr(None, Menu(None))
        a = Unit('type1', UnitInfo(1, 1, 1, Coord()))
        b = Unit('type2', UnitInfo(2, 1, 1, Coord()))
        unitmgr.add(a)
        unitmgr.add(b)

        both = unitmgr.get_selected(False)
        self.assertIsNotNone(both)
        self.assertEqual(len(both), 2)
        self.assertEqual(both[0].unit_info.unit_id, a.unit_info.unit_id)
        self.assertEqual(both[1].unit_info.unit_id, b.unit_info.unit_id)

        a.selected = True

        unsel = unitmgr.get_selected(False)
        self.assertIsNotNone(unsel)
        self.assertEqual(len(unsel), 1)
        self.assertEqual(unsel[0].unit_info.unit_id, b.unit_info.unit_id)
コード例 #8
0
ファイル: unitmgr_test.py プロジェクト: mtday/pygame
    def test_get_by_type(self):
        unitmgr = UnitMgr(None, Menu(None))
        unitmgr.add(Unit('type1', UnitInfo(1, 1, 1, Coord())))
        unitmgr.add(Unit('type2', UnitInfo(2, 1, 1, Coord())))
        unitmgr.add(Unit('type1', UnitInfo(3, 1, 1, Coord())))

        empty = unitmgr.get_by_type('missing')
        self.assertIsNotNone(empty)
        self.assertEqual(len(empty), 0)

        type1 = unitmgr.get_by_type('type1')
        self.assertIsNotNone(type1)
        self.assertEqual(len(type1), 2)
        self.assertEqual(1, type1[0].unit_info.unit_id)
        self.assertEqual(3, type1[1].unit_info.unit_id)

        type2 = unitmgr.get_by_type('type2')
        self.assertIsNotNone(type2)
        self.assertEqual(len(type2), 1)
        self.assertEqual(2, type2[0].unit_info.unit_id)
コード例 #9
0
 def test_str(self):
     unit = Unit('type', UnitInfo(10, 11, 12, Coord(1, 2, -3)))
     self.assertEqual(
         str(unit),
         'Unit[unit_type=type, unit_info=UnitInfo[unit_id=10, user_id=11, game_id=12,'
         + ' coord=Coord[x=1, y=2, z=-3]]]')