示例#1
0
 def test_get_race_breakdown(self, mockrand):
     """ verify race breakdown"""
     self.redis.lpush('npc_race', 'gnome')
     city = City(self.redis)
     self.redis.lpush('npc_race', 'orc')
     self.redis.lpush('npc_race', 'elf')
     self.redis.set('elf_subrace_chance', 101)
     city.races = {
         'orc': 3,
         'elf': {
             'shadowelf': 18,
             'snowelf': 11,
             'waterelf': 11
         },
         'other': 10
     }
     breakdown = city.get_race_breakdown()
     self.assertDictEqual(
         {
             'Orc': 3,
             'Shadow Elf': 18,
             'Snow Elf': 11,
             'Water Elf': 11,
             'Other': 10
         }, breakdown)
示例#2
0
    def test_select_subraces(self):
        """ verify subraces"""
        self.redis.lpush('npc_race', 'orc')
        self.redis.lpush('npc_race', 'elf')
        self.redis.set('elf_subrace_chance', 101)

        city = City(self.redis)
        city.races = {
            'orc': 3,
            'elf': {
                'shadowelf': 18,
                'snowelf': 11,
                'waterelf': 11
            }
        }
        city.select_subraces()
        self.assertDictEqual(
            {
                'orc': 3,
                'elf': {
                    'shadowelf': 18,
                    'snowelf': 11,
                    'waterelf': 11
                }
            }, city.races)
 def test_want_subraces(self, mockrand):
     """  """
     self.redis.lpush('npc_race','kobold')
     city = City(self.redis)
     mockrand.randint.return_value = 1
     self.assertEquals(True, city.want_subraces('kobold'))
     mockrand.randint.return_value = 100
     self.assertEquals(False, city.want_subraces('kobold'))
示例#4
0
 def test_want_subraces(self, mockrand):
     """  """
     self.redis.lpush('npc_race', 'kobold')
     city = City(self.redis)
     mockrand.randint.return_value = 1
     self.assertEquals(True, city.want_subraces('kobold'))
     mockrand.randint.return_value = 100
     self.assertEquals(False, city.want_subraces('kobold'))
 def test_calculate_subraces_lowrolls(self, mockrand):
     self.redis.lpush('npc_race','gnome')
     city = City(self.redis)
     mockrand.randint.side_effect = [11, 1, 2, 3, 4, 5, 6, 7, 8, 9]
     mockredis = Mock(self.redis)
     mockredis.lrange = MagicMock(return_value=['halfelf', 'wildelf', 'woodelf', 'darkelf'])
     city.redis = mockredis
     subraces = city.calculate_which_subraces('elf', 40)
     self.assertDictEqual({'halfelf': 34, 'darkelf': 3, 'wildelf': 1, 'woodelf': 2}, subraces)
 def test_calculate_racial_breakdown_lowrolls(self, mockrand):
     self.redis.lpush('npc_race','gnome')
     city = City(self.redis)
     mockrand.randint.side_effect = [11, 1, 2, 3, 4, 5, 6, 7, 8, 9]
     mockredis = Mock(self.redis)
     mockredis.lrange = MagicMock(return_value=['orc', 'ogre', 'molekin'])
     city.redis = mockredis
     city.calculate_racial_breakdown()
     self.assertLess(0, len(city.races))
     self.assertDictEqual({'molekin': 3, 'other': 94, 'orc': 1, 'ogre': 2}, city.races)
    def test_select_subraces(self):
        """ verify subraces"""
        self.redis.lpush('npc_race','orc')
        self.redis.lpush('npc_race','elf')
        self.redis.set('elf_subrace_chance',101) 

        city = City(self.redis)
        city.races = {'orc': 3, 'elf':  {'shadowelf': 18, 'snowelf': 11, 'waterelf': 11}}
        city.select_subraces()
        self.assertDictEqual({'orc': 3, 'elf': {'shadowelf': 18, 'snowelf': 11, 'waterelf': 11} },
                             city.races)
 def test_get_race_breakdown(self, mockrand):
     """ verify race breakdown"""
     self.redis.lpush('npc_race','gnome')
     city = City(self.redis)
     self.redis.lpush('npc_race','orc')
     self.redis.lpush('npc_race','elf')
     self.redis.set('elf_subrace_chance',101) 
     city.races = {'orc': 3, 'elf': {'shadowelf': 18, 'snowelf': 11, 'waterelf': 11}, 'other': 10}
     breakdown = city.get_race_breakdown()
     self.assertDictEqual({ 'Orc': 3, 'Shadow Elf': 18, 'Snow Elf': 11, 'Water Elf': 11, 'Other': 10},
                          breakdown)
 def test_calculate_racial_breakdown(self, mockrand):
     """  """
     self.redis.lpush('npc_race','gnome')
     city = City(self.redis)
     mockrand.randint.side_effect = [11, 30, 30, 30, 30]
     mockredis = Mock(self.redis)
     mockredis.lrange = MagicMock(return_value=['orc', 'ogre', 'molekin', 'human', 'harpy', 'halfling', 'elf'
                                                'goblin', 'gnome', 'dwarf', 'coatikin', 'bugbear', 'catfolk'])
     city.redis = mockredis
     city.calculate_racial_breakdown()
     self.assertLess(0, len(city.races))
     self.assertDictEqual({'molekin': 29, 'other': 11, 'orc': 30, 'ogre': 30}, city.races)
    def test_calculate_population(self):
        """  """
        self.redis.lpush('npc_race','gnome')
        city = City(self.redis)
        city.population_estimate = None
        city.population_density = None

        city.calculate_population()
        self.assertLessEqual(city.population_estimate, int(city.size['maxpop']))
        self.assertGreaterEqual(city.population_estimate, int(city.size['minpop']))

        self.assertLessEqual(city.population_density, int(city.size['max_density']))
        self.assertGreaterEqual(city.population_density, int(city.size['min_density']))
    def test_get_scale(self):
        mockredis = Mock(self.redis)
        self.redis.lpush('npc_race','gnome')
        city = City(self.redis)
        citydata = [
            '{"maxpop": "100", "max_density": "400", "name": "settlement", "min_density": "10", "minpop": "25"}',
            '{"maxpop": "500", "max_density": "2000", "name": "hamlet", "min_density": "20", "minpop": "101"}',
            '{"maxpop": "600", "max_density": "2400", "name": "small village", "min_density": "30", "minpop": "501"}'
            ]

        mockredis.zrange = MagicMock(return_value=citydata)
        city.redis = mockredis
        scale = city.get_scale()
        self.assertEqual([{u'name': u'settlement'}, {u'name': u'hamlet'}, {u'name': u'small village'}], scale)
示例#12
0
 def test_calculate_subraces(self, mockrand):
     self.redis.lpush('npc_race', 'gnome')
     city = City(self.redis)
     mockrand.randint.side_effect = [29, 2, 39, 4, 5, 6, 7, 8, 9]
     mockredis = Mock(self.redis)
     mockredis.lrange = MagicMock(
         return_value=['halfelf', 'wildelf', 'woodelf', 'darkelf'])
     city.redis = mockredis
     subraces = city.calculate_which_subraces('elf', 40)
     self.assertDictEqual({
         'halfelf': 29,
         'wildelf': 2,
         'woodelf': 9
     }, subraces)
示例#13
0
 def test_calculate_racial_breakdown_lowrolls(self, mockrand):
     self.redis.lpush('npc_race', 'gnome')
     city = City(self.redis)
     mockrand.randint.side_effect = [11, 1, 2, 3, 4, 5, 6, 7, 8, 9]
     mockredis = Mock(self.redis)
     mockredis.lrange = MagicMock(return_value=['orc', 'ogre', 'molekin'])
     city.redis = mockredis
     city.calculate_racial_breakdown()
     self.assertLess(0, len(city.races))
     self.assertDictEqual({
         'molekin': 3,
         'other': 94,
         'orc': 1,
         'ogre': 2
     }, city.races)
    def test_select_no_subraces(self):
        """ verify subraces"""
        self.redis.lpush('npc_race','orc')
        self.redis.lpush('npc_race','elf')
        self.redis.set('elf_subrace_chance',101) 

        city = City(self.redis)
        city.races = {'orc': 3, 'elf':40}
        city.select_subraces()
        self.assertEqual(3,   city.races['orc'])
        self.assertNotEqual(40,   city.races['elf'])
        total=0
        for elfkey in city.races['elf'].keys():
            self.assertIn(elfkey, ['shadowelf','snowelf','waterelf'])
            self.assertLessEqual(city.races['elf'][elfkey], 40)
            total+=city.races['elf'][elfkey]
        """ Our total subraces should be equal to our original race percentage"""
        self.assertEqual(total, 40)
示例#15
0
    def test_select_no_subraces(self):
        """ verify subraces"""
        self.redis.lpush('npc_race', 'orc')
        self.redis.lpush('npc_race', 'elf')
        self.redis.set('elf_subrace_chance', 101)

        city = City(self.redis)
        city.races = {'orc': 3, 'elf': 40}
        city.select_subraces()
        self.assertEqual(3, city.races['orc'])
        self.assertNotEqual(40, city.races['elf'])
        total = 0
        for elfkey in city.races['elf'].keys():
            self.assertIn(elfkey, ['shadowelf', 'snowelf', 'waterelf'])
            self.assertLessEqual(city.races['elf'][elfkey], 40)
            total += city.races['elf'][elfkey]
        """ Our total subraces should be equal to our original race percentage"""
        self.assertEqual(total, 40)
示例#16
0
 def test_calculate_racial_breakdown(self, mockrand):
     """  """
     self.redis.lpush('npc_race', 'gnome')
     city = City(self.redis)
     mockrand.randint.side_effect = [11, 30, 30, 30, 30]
     mockredis = Mock(self.redis)
     mockredis.lrange = MagicMock(return_value=[
         'orc', 'ogre', 'molekin', 'human', 'harpy', 'halfling', 'elf'
         'goblin', 'gnome', 'dwarf', 'coatikin', 'bugbear', 'catfolk'
     ])
     city.redis = mockredis
     city.calculate_racial_breakdown()
     self.assertLess(0, len(city.races))
     self.assertDictEqual(
         {
             'molekin': 29,
             'other': 11,
             'orc': 30,
             'ogre': 30
         }, city.races)
示例#17
0
    def test_get_scale(self):
        mockredis = Mock(self.redis)
        self.redis.lpush('npc_race', 'gnome')
        city = City(self.redis)
        citydata = [
            '{"maxpop": "100", "max_density": "400", "name": "settlement", "min_density": "10", "minpop": "25"}',
            '{"maxpop": "500", "max_density": "2000", "name": "hamlet", "min_density": "20", "minpop": "101"}',
            '{"maxpop": "600", "max_density": "2400", "name": "small village", "min_density": "30", "minpop": "501"}'
        ]

        mockredis.zrange = MagicMock(return_value=citydata)
        city.redis = mockredis
        scale = city.get_scale()
        self.assertEqual([{
            u'name': u'settlement'
        }, {
            u'name': u'hamlet'
        }, {
            u'name': u'small village'
        }], scale)
示例#18
0
    def test_calculate_population(self):
        """  """
        self.redis.lpush('npc_race', 'gnome')
        city = City(self.redis)
        city.population_estimate = None
        city.population_density = None

        city.calculate_population()
        self.assertLessEqual(city.population_estimate,
                             int(city.size['maxpop']))
        self.assertGreaterEqual(city.population_estimate,
                                int(city.size['minpop']))

        self.assertLessEqual(city.population_density,
                             int(city.size['max_density']))
        self.assertGreaterEqual(city.population_density,
                                int(city.size['min_density']))
示例#19
0
 def test_has_subrace(self):
     """  """
     self.redis.lpush('npc_race', 'kobold')
     city = City(self.redis)
     self.assertEquals(False, city.has_subraces('foo'))
     self.assertEquals(True, city.has_subraces('kobold'))
示例#20
0
 def test_city_region(self):
     """  """
     self.redis.lpush('npc_race', 'gnome')
     region = Region(self.redis)
     city = City(self.redis, {'region': region})
     self.assertEqual(str(city.region), str(region))
示例#21
0
 def test_random_city(self):
     """  """
     self.redis.lpush('npc_race', 'gnome')
     city = City(self.redis)
     self.assertEqual('Alta DeAllentle Gate', city.name.fullname)
     self.assertEquals(city.name.fullname, str(city))
 def test_has_subrace(self):
     """  """
     self.redis.lpush('npc_race','kobold')
     city = City(self.redis)
     self.assertEquals(False, city.has_subraces('foo'))
     self.assertEquals(True, city.has_subraces('kobold'))
示例#23
0
def GenerateCity():
    """Generate a simple city"""
    features = feature_filter('city')
    tempobj = City(app.server, features)
    return render_template('city.html', tempobj=tempobj)