示例#1
0
 def test_invalid_realm(self):
     realm = Realm()    
     army = Army(realm, 10)
     province = Province(None, 1, 1)
     province.add_army(army)
     
     self.assertRaises(AssertionError, can_move_army, None, army, Province(None, 2, 1))
示例#2
0
    def test_can_create_province(self):
        realm = Realm()
        army = Army(0, realm)
        province = Province(None, 0, 0)
        province.add_army(army)

        self.assertTrue(can_create_province(realm, army))
示例#3
0
    def test_invalid_realm(self):
        realm = Realm()
        army = Army(realm, 1)
        province = Province(None, 0, 0)
        province.add_army(army)

        self.assertRaises(AssertionError, can_create_province, None, army)
示例#4
0
 def test_actions(self):
     world = World()
     realm = world.create_realm('Realm0', 1.0, 1.0, 1.0)
     province = Province(None, 0,0)
     action0 = Action()
     province.action = action0
     realm.add_province(province)
     
     result = world.tick()
     
     self.assertEqual(world.turn, 1)
     self.assertEqual(action0.count, 1)
     self.assertEqual(province.action, None)
     self.assertEqual(len(result.battles), 0)
     
     army = world.create_army(realm)
     army.size = 1
     province.add_army(army)
     
     action1 = Action()
     army.action = action1
     
     result = world.tick()
     
     self.assertEqual(world.turn, 2)
     self.assertEqual(action0.count, 1)
     self.assertEqual(action1.count, 1)
     self.assertEqual(army.action, None)
     self.assertEqual(province.action, None)
     self.assertEqual(len(result.battles), 0)
示例#5
0
 def test_wrong_realm(self):
     realm0 = Realm()    
     realm1 = Realm()
     army = Army(0, realm0)
     province = Province(None, 1, 1)
     province.add_army(army)
     
     self.assertFalse(can_move_army(realm1, army, Province(None, 2, 1)))
示例#6
0
    def test_same_realm(self):
        realm = Realm()
        army = Army(0, realm)
        province = Province(None, 0, 0)
        province.add_army(army)
        realm.add_province(province)

        self.assertFalse(can_create_province(realm, army))
 def test_second_time(self):
     province = Province(None, 2, 4)
     army = Army(None, 10)
     
     self.assertTrue(province.add_army(army))
     self.assertFalse(province.add_army(army))
     self.assertEqual(len(province.armies), 1)
     self.assertTrue(army in province.armies)
     self.assertEqual(army.province, province)
示例#8
0
    def test_other_realm(self):
        realm0 = Realm()
        realm1 = Realm()
        army = Army(0, realm0)
        province = Province(None, 0, 0)
        province.add_army(army)
        realm1.add_province(province)

        self.assertFalse(can_create_province(realm0, army))
示例#9
0
 def test_remove(self): 
     army = Army()
     province = Province(None, 1, 1)
     province.add_army(army)
     
     army.remove()
     
     self.assertEqual(army.province, None)
     self.assertFalse(army in province.armies)
示例#10
0
 def test_not_neighbour(self):     
     realm = Realm()    
     army = Army(0, realm)
     province = Province(None, 1, 1)
     province.add_army(army)
     
     self.assertFalse(can_move_army(realm, army, Province(None, 0, 0)))
     self.assertFalse(can_move_army(realm, army, Province(None, 0, 2)))
     self.assertFalse(can_move_army(realm, army, Province(None, 3, 2)))
     self.assertFalse(can_move_army(realm, army, Province(None, 3, 0)))       
示例#11
0
    def test_create_province(self):
        realm = Realm()
        army = Army(0, realm)
        province = Province(None, 0, 0)
        province.add_army(army)

        create = CreateProvince(realm, army)
        create.execute()

        self.assertEqual(province.realm, realm)
        self.assertTrue(province in realm.provinces)
示例#12
0
 def test_other_province(self):
     province0 = Province(None, 2, 4)
     province1 = Province(None, 2, 5)
     army = Army(None, 10)
     
     self.assertTrue(province0.add_army(army))
     self.assertFalse(province1.add_army(army))
     self.assertEqual(len(province0.armies), 1)
     self.assertEqual(len(province1.armies), 0)
     self.assertTrue(army in province0.armies)
     self.assertFalse(army in province1.armies)
     self.assertEqual(army.province, province0)
示例#13
0
 def test_move(self):     
     realm = Realm()    
     army = Army(0, realm)
     province0 = Province(None, 1, 1)
     province1 = Province(None, 1, 2)
     
     province0.add_army(army)
     
     move = MoveArmy(realm, army, province1)
     move.execute()
     
     self.assertEqual(len(province0.armies), 0)
     self.assertEqual(len(province1.armies), 1)               
     self.assertFalse(army in province0.armies)
     self.assertTrue(army in province1.armies)
     self.assertEqual(army.province, province1)        
 def test_remove_army(self):
     province = Province(None, 2, 4)
     army0 = Army(None, 10)
     army1 = Army(None, 10)
     
     province.add_army(army0)
     province.add_army(army1)
     
     self.assertTrue(province.remove_army(army0))
     self.assertTrue(province.remove_army(army1))
     
     self.assertEqual(len(province.armies), 0)
     self.assertFalse(army0 in province.armies)
     self.assertFalse(army1 in province.armies)
     self.assertEqual(army0.province, None)
     self.assertEqual(army1.province, None)
示例#15
0
 def test_even(self): 
     realm0 = Realm()
     realm1 = Realm()
     army0 = Army(0, realm0)
     army1 = Army(1, realm1)
     army0.size = 5
     army1.size = 5
     province = Province(None, 1, 1)
     province.add_army(army0)
     province.add_army(army1)
     
     battle = Battle(army0, army1)
     
     self.assertEqual(army0.size, 0)
     self.assertEqual(army1.size, 0)
     
     self.assertEqual(army0.province, None)
     self.assertFalse(army0 in province.armies)
     self.assertEqual(army1.province, None)
     self.assertFalse(army1 in province.armies)
示例#16
0
 def test_zero_wins(self): 
     realm0 = Realm()
     realm1 = Realm()
     army0 = Army(0, realm0)
     army1 = Army(1, realm1)
     army0.size = 10        
     army1.size = 4
     province = Province(None, 1, 1)
     province.add_army(army0)
     province.add_army(army1)
     
     battle = Battle(army0, army1)
     
     self.assertEqual(army0.size, 6)
     self.assertEqual(army1.size, 0)
     
     self.assertEqual(army0.province, province)
     self.assertTrue(army0 in province.armies)
     self.assertEqual(army1.province, None)
     self.assertFalse(army1 in province.armies)
示例#17
0
 def test_add_army(self):
     province = Province(None, 2, 4)
     army0 = Army(None, 10)
     army1 = Army(None, 10)
     
     self.assertTrue(province.add_army(army0))
     self.assertTrue(province.add_army(army1))
     self.assertEqual(len(province.armies), 2)
     self.assertTrue(army0 in province.armies)
     self.assertTrue(army1 in province.armies)
     self.assertEqual(army0.province, province)
     self.assertEqual(army1.province, province)
示例#18
0
 def test_can_move_army(self): 
     realm = Realm()    
     army = Army(0, realm)
     province0 = Province(None, 1, 1)
     province0.add_army(army)
     
     self.assertTrue(can_move_army(realm, army, Province(None, 2, 1)))
     self.assertTrue(can_move_army(realm, army, Province(None, 2, 2)))
     self.assertTrue(can_move_army(realm, army, Province(None, 1, 2)))
     self.assertTrue(can_move_army(realm, army, Province(None, 0, 1)))
     self.assertTrue(can_move_army(realm, army, Province(None, 1, 0)))
     self.assertTrue(can_move_army(realm, army, Province(None, 2, 0)))
     
     province0.remove_army(army)
     province1 = Province(None, 1, 2)
     province1.add_army(army)
     
     self.assertTrue(can_move_army(realm, army, Province(None, 2, 2)))
     self.assertTrue(can_move_army(realm, army, Province(None, 1, 3)))
     self.assertTrue(can_move_army(realm, army, Province(None, 0, 3)))
     self.assertTrue(can_move_army(realm, army, Province(None, 0, 2)))
     self.assertTrue(can_move_army(realm, army, Province(None, 0, 1)))
     self.assertTrue(can_move_army(realm, army, Province(None, 1, 1)))