def test_load_uwp(self):
        '''Test create with UWP'''
        planet = LBB6Planet(uwp='B433432-A')
        self.assertTrue(str(planet) == 'B433432-A')

        planet = LBB6Planet(uwp='YS00000-0')
        self.assertTrue(str(planet) == 'YS00000-0')
 def test_non_hz_orbits(self):
     '''Test non-HZ orbits (hydrographics)'''
     star = Star('G2 V')
     planet = LBB6Planet()
     planet.generate(star=star, orbit=Orbit(1))
     self.assertTrue(int(planet.hydrographics) == 0)
     planet = LBB6Planet()
     planet.generate(star=star, orbit=Orbit(11))
     self.assertTrue(str(planet.atmosphere) in '0A')
    def test_create(self):
        '''Basic create tests'''
        planet = LBB6Planet()
        planet.generate()
        self.assertTrue(isinstance(planet, LBB6Planet))
        self.assertTrue(planet.starport in 'ABCDEX')

        # Not mainworld
        planet = LBB6Planet()
        planet.generate(is_mainworld=False)
        self.assertTrue(planet.starport in 'FGHY')
 def test_albedo_land_coverage(self):
     '''
     Test albedo land coverage
     desert_coverage = 10% * (10 - hydrographics)
     Modifiers:
     - Vacuum/trace atmosphere => desert_coverage = 100%
     - Very thin atmosphere => desert_coverage +10%
     - Thin atmosphere => desert_coverage +5%
     - Dense atmosphere => desert_coverage -5%
     '''
     planet = LBB6Planet()
     for hyd in range(0, 11):
         for atm in range(0, 10):
             expected = float((10 - hyd)) * 0.1
             if atm <= 1:
                 expected = 1.0
             if atm >= 2 and atm <= 3:
                 expected += 0.1
             if atm >= 4 and atm <= 5:
                 expected += 0.05
             if atm >= 8 and atm <= 9:
                 expected -= 0.05
             if hyd == 0:
                 expected = 1.0
             expected = round(expected, 2)
             expected = min(1.0, expected)
             expected = max(0.0, expected)
             planet.hydrographics = ehex(hyd)
             planet.atmosphere = ehex(atm)
             desert_coverage = planet._albedo_determine_desert_coverage()
             LOGGER.debug('uwp %s expected = %s actual = %s', str(planet),
                          expected, desert_coverage)
             self.assertTrue(expected == desert_coverage)
 def test_va(self):
     '''Test Va trade code'''
     planet = LBB6Planet()
     planet.atmosphere = ehex(0)
     planet._determine_env_trade_codes()
     LOGGER.debug('planet = %s', str(planet))
     self.assertTrue('Va' in planet.trade_codes)
 def test_temperature(self):
     '''Temperature tests'''
     star = Star('G2 V')
     for test in [{
             'uwp': 'A867A69-F',
             'orbit': 3,
             'expected': MinMax(221.0, 303.0)
     }, {
             'uwp': 'F20067C-F',
             'orbit': 3,
             'expected': MinMax(299.0, 299.0)
     }, {
             'uwp': 'F43056A-F',
             'orbit': 4,
             'expected': MinMax(237.0, 237.0)
     }, {
             'uwp': 'G8B0168-F',
             'orbit': 2,
             'expected': MinMax(300.0, 707.0)
     }, {
             'uwp': 'F10046C-F',
             'orbit': 9,
             'expected': MinMax(48.0, 48.0)
     }]:
         planet = LBB6Planet(uwp=test['uwp'])
         planet.generate(star=star, orbit=Orbit(test['orbit']))
         LOGGER.debug('planet = %s', planet.json())
         LOGGER.debug('uwp = %s expected = %s, actual = %s', test['uwp'],
                      test['expected'], planet.temperature)
         self.assertAlmostEqual(planet.temperature.min(),
                                test['expected'].min(),
                                delta=2)
         self.assertAlmostEqual(planet.temperature.max(),
                                test['expected'].max(),
                                delta=2)
 def test_as(self):
     '''Test As trade code'''
     planet = LBB6Planet()
     planet.is_mainworld = True
     planet.atmosphere = ehex(0)
     planet._determine_env_trade_codes()
     LOGGER.debug('planet = %s', str(planet))
     self.assertTrue('As' in planet.trade_codes)
 def test_not_va(self):
     '''Test !Va trade code'''
     planet = LBB6Planet()
     for atm in '123456789ABC':
         planet.atmosphere = ehex(atm)
         planet._determine_env_trade_codes()
         LOGGER.debug('planet = %s', str(planet))
         self.assertFalse('Va' in planet.trade_codes)
 def test_not_wa(self):
     '''Test !Wa trade code'''
     planet = LBB6Planet()
     for hyd in '0123456789':
         planet.hydrographics = ehex(hyd)
         planet._determine_env_trade_codes()
         LOGGER.debug('planet = %s', str(planet))
         self.assertFalse('Wa' in planet.trade_codes)
 def test_albedo_ice_no_hz(self):
     '''Ensure star.hz_orbit being None doesn't raise exception'''
     star = Star('MD')
     orbit = Orbit(3)
     planet = LBB6Planet(uwp='X644000-0')
     planet.generate(star=star, orbit=orbit)
     self.assertTrue(planet._determine_albedo_ice_coverage() == float(
         int(planet.hydrographics) / 10.0))
 def test_create(self, mock_fn):
     '''Create tests'''
     mainworld = LBB6Planet(uwp='A788767-8')
     parent = LBB6ExpandedStar(mainworld)
     companion = LBB6CompanionStar(parent)
     LOGGER.debug('companion = %s', str(companion))
     self.assertTrue(companion.type == 'K')
     self.assertTrue(companion.size == 'V')
 def test_not_as(self):
     '''Test !As trade code'''
     planet = LBB6Planet()
     planet.is_mainworld = False
     for atm in '0123456789ABC':
         planet.atmosphere = ehex(atm)
         planet._determine_env_trade_codes()
         LOGGER.debug('planet = %s', str(planet))
         self.assertFalse('As' in planet.trade_codes)
 def test_de(self):
     '''Test De trade code'''
     planet = LBB6Planet()
     planet.hydrographics = ehex(0)
     for atm in '23456789ABC':
         planet.atmosphere = ehex(atm)
         planet._determine_env_trade_codes()
         LOGGER.debug('planet = %s', str(planet))
         self.assertTrue('De' in planet.trade_codes)
 def test_create_roll1s(self, mock_fn):
     '''Create tests, roll 1 every time'''
     planet = LBB6Planet()
     # Size 0, not mainworld => size = S
     planet.generate(is_mainworld=False)
     LOGGER.debug('planet = %s', str(planet))
     self.assertTrue(planet.size == 'S')
     # Size 0, mainworld => size = 0
     planet.generate(is_mainworld=True)
     self.assertTrue(planet.size == '0')
 def test_not_ic(self):
     '''Test !Ic trade code'''
     planet = LBB6Planet()
     for atm in '23456789ABC':
         for hyd in '0123456789A':
             planet.atmosphere = ehex(atm)
             planet.hydrographics = ehex(hyd)
             planet._determine_env_trade_codes()
             LOGGER.debug('planet = %s', str(planet))
             self.assertFalse('Ic' in planet.trade_codes)
 def test_temperature_formula(self):
     '''Test temperature formula'''
     temp = LBB6Planet._temperature_formula(
         1.0,  # Luminosity
         0.3,  # Albedo
         1.0,  # Distance (AU)
         1.1  # Greenhouse effect
     )
     LOGGER.debug('temp = %s', temp)
     self.assertTrue(temp == 288)
Esempio n. 17
0
    def on_get(self, req, resp):
        '''GET <apiserver>/ct/lbb6/planet?uwp=<uwp>&<<options>>'''
        self.query_parameters = {
            'doc': False,
            'uwp': None,
            'orbit_no': None,
            'star': None,
            'name': None,
            'is_mainworld': True
        }
        self.parse_query_string(req.query_string)
        LOGGER.debug('querystring = %s', req.query_string)
        LOGGER.debug('is_mainworld = %s',
                     self.query_parameters['is_mainworld'])

        if self.query_parameters['doc'] is True:
            resp.body = self.get_doc_json(req)
            resp.status = falcon.HTTP_200
        else:
            # Anything to do?
            if self.query_parameters['uwp'] is None:
                raise falcon.HTTPError(title='Invalid UWP',
                                       status='400 Invalid parameter',
                                       description='No UWP specified')
            # Star?
            if self.query_parameters['star'] is not None:
                self.query_parameters['star'] = \
                    catch_html_space(self.query_parameters['star'])
                star = self.get_star_details()
            else:
                star = None
            # Orbit?
            if self.query_parameters['orbit_no'] is not None:
                orbit = self.get_orbit_details(star)
            else:
                orbit = None

            try:
                planet = LBB6Planet(uwp=self.query_parameters['uwp'],
                                    name=self.query_parameters['name'])
                LOGGER.debug('query_param is_mainworld = %s',
                             self.query_parameters['is_mainworld'])
                planet.generate(
                    star=star,
                    orbit=orbit,
                    is_mainworld=self.query_parameters['is_mainworld'])
            except ValueError as err:
                raise falcon.HTTPError(title='Invalid planet',
                                       status='400 Invalid parameter',
                                       description=str(err))

            resp.body = planet.json()
            resp.status = falcon.HTTP_200
 def test_create_random(self, mock_fn):
     '''Test codeless create'''
     # This mainworld gets a +4 on size and type rolls
     mainworld = LBB6Planet(uwp='A788767-8')
     LOGGER.debug('mainworld type = %s', type(mainworld))
     star = LBB6ExpandedStar(mainworld)
     self.assertTrue(star.type == 'M')
     self.assertTrue(star.size == 'V')
     LOGGER.debug('star.size_roll = %s, star.type_roll = %s',
                  star.size_roll, star.type_roll)
     self.assertTrue(star.size_roll == 6)
     self.assertTrue(star.type_roll == 6)
 def test_albedo(self):
     '''Albedo tests'''
     star = Star('G2 V')
     tests = [{
         'uwp': 'A867977-8',
         'star': star,
         'orbit': Orbit(3),
         'expected': (0.265, 0.465)
     }]
     for test in tests:
         planet = LBB6Planet(uwp=test['uwp'])
         planet.generate(star=test['star'], orbit=test['orbit'])
         LOGGER.debug('uwp = %s TCs = %s albedo = %s', str(planet),
                      planet.trade_codes, str(planet.albedo))
         self.assertTrue(planet.albedo.min() == test['expected'][0])
         self.assertTrue(planet.albedo.max() == test['expected'][1])
 def test_albedo_ice_coverage(self):
     '''
     Test albedo_ice_coverage
     Inner zone => ice_coverage = 0%
     HZ => ice_coverage == 10%
     Outer zone => ice_coverage = hydrographics
     Can't find orbit or star => ice_coverage = 10%
     '''
     planet = LBB6Planet(uwp='X644000-0')
     # Inner zone
     planet.generate(star=Star('G2 V'), orbit=Orbit(1))
     self.assertTrue(planet._determine_albedo_ice_coverage() == 0.0)
     # Habitable zone
     planet.generate(star=Star('G2 V'), orbit=Orbit(3))
     self.assertTrue(planet._determine_albedo_ice_coverage() == 0.1)
     # Outer zone
     planet.generate(star=Star('G2 V'), orbit=Orbit(5))
     for hyd in range(0, 11):
         planet.hydrographics = ehex(hyd)
         self.assertTrue(
             planet._determine_albedo_ice_coverage() == float(hyd / 10.0))
    def test_json(self, mock_fn):
        '''Test JSON representation'''
        # No orbit or star
        expected = json.dumps(
            {
                "is_mainworld": True,
                "name": "",
                "orbit": None,
                "orbital_period": None,
                "star": None,
                "temperature": {
                    "max": None,
                    "min": None
                },
                "temperature_factors": {
                    "albedo": {
                        "max": 0.266,
                        "min": 0.226
                    },
                    "cloudiness": 0.1,
                    'greenhouse': {
                        "max": 1.0,
                        "min": 1.0
                    }
                },
                "trade_codes": ["Ni", "Po"],
                "uwp": "B433432-A"
            },
            sort_keys=True)
        planet = LBB6Planet(uwp='B433432-A')
        planet.generate()
        LOGGER.debug('expected      = %s', expected)
        LOGGER.debug('planet.json() = %s', planet.json())
        self.assertTrue(planet.json() == expected)

        # Orbit, star
        expected = json.dumps(
            {
                "is_mainworld": True,
                "name": "Planet 9",
                "orbit": "Orbit 3: 1.0 AU, 149.6 Mkm",
                "orbital_period": None,
                "star": "G2 V",
                "temperature": {
                    "max": 289.0,
                    "min": 274.0
                },
                "temperature_factors": {
                    "albedo": {
                        "max": 0.266,
                        "min": 0.226
                    },
                    "cloudiness": 0.1,
                    'greenhouse': {
                        "max": 1.0,
                        "min": 1.0
                    }
                },
                "trade_codes": ["Ni", "Po"],
                "uwp": "B433432-A"
            },
            sort_keys=True)
        planet = LBB6Planet('Planet 9', uwp='B433432-A')
        planet.generate(star=Star('G2 V'), orbit=Orbit(3))
        LOGGER.debug('expected      = %s', expected)
        LOGGER.debug('planet.json() = %s', planet.json())
        self.assertTrue(planet.json() == expected)
 def test_wa(self):
     '''Test Wa trade code'''
     planet = LBB6Planet()
     planet.hydrographics = ehex('A')
     planet._determine_env_trade_codes()
     self.assertTrue('Wa' in planet.trade_codes)
 def test_greenhouse(self):
     '''Greenhouse tests'''
     planet = LBB6Planet()
     tests = [
         {
             'atm': '0',
             'expected': 1.0
         },
         {
             'atm': '1',
             'expected': 1.0
         },
         {
             'atm': '2',
             'expected': 1.0
         },
         {
             'atm': '3',
             'expected': 1.0
         },
         {
             'atm': '4',
             'expected': 1.05
         },
         {
             'atm': '5',
             'expected': 1.05
         },
         {
             'atm': '6',
             'expected': 1.1
         },
         {
             'atm': '7',
             'expected': 1.1
         },
         {
             'atm': '8',
             'expected': 1.15
         },
         {
             'atm': '9',
             'expected': 1.15
         },
         {
             'atm': 'A',
             'expected': (1.2, 1.7)
         },
         {
             'atm': 'B',
             'expected': (1.2, 2.2)
         },
         {
             'atm': 'C',
             'expected': (1.2, 2.2)
         },
         {
             'atm': 'D',
             'expected': 1.15
         },
         {
             'atm': 'E',
             'expected': 1.1
         },
         {
             'atm': 'F',
             'expected': 1.0
         },
     ]
     for test in tests:
         planet.atmosphere = ehex(test['atm'])
         planet.determine_greenhouse()
         LOGGER.debug('atm = %s expected = %s planet = %s, result = %s',
                      test['atm'], test['expected'], str(planet),
                      planet.greenhouse.dict())
         if isinstance(test['expected'], tuple):
             # pragma pylint: disable=E1136
             self.assertTrue(planet.greenhouse.min() == test['expected'][0])
             self.assertTrue(planet.greenhouse.max() == test['expected'][1])
         else:
             self.assertTrue(planet.greenhouse.min() == test['expected'])
             self.assertTrue(planet.greenhouse.max() == test['expected'])
 def test_cloudiness(self):
     '''
     Cloudiness tests
     hyd 0-1: cloudiness = 0%
     hyd 2-3: cloudiness = 10%
     hyd 4: cloudiness = 20%
     hyd 5: cloudiness = 30%
     hyd 6: cloudiness = 40%
     hyd 7: cloudiness = 50%
     hyd 8: cloudiness = 60%
     hyd 9-A: cloudiness = 70%
     atm A+: cloudiness +40%
     atm 3-: max cloudiness = 20%
     atm E: cloudiness / 2
     '''
     test_cases = [{
         'hyd': '0',
         'cloudiness': 0.0
     }, {
         'hyd': '1',
         'cloudiness': 0.0
     }, {
         'hyd': '2',
         'cloudiness': 0.1
     }, {
         'hyd': '3',
         'cloudiness': 0.1
     }, {
         'hyd': '4',
         'cloudiness': 0.2
     }, {
         'hyd': '5',
         'cloudiness': 0.3
     }, {
         'hyd': '6',
         'cloudiness': 0.4
     }, {
         'hyd': '7',
         'cloudiness': 0.5
     }, {
         'hyd': '8',
         'cloudiness': 0.6
     }, {
         'hyd': '9',
         'cloudiness': 0.7
     }, {
         'hyd': 'A',
         'cloudiness': 0.7
     }]
     planet = LBB6Planet()
     for test in test_cases:
         planet.hydrographics = ehex(test['hyd'])
         for atm in '0123456789ABCDEF':
             planet.atmosphere = ehex(atm)
             expected = test['cloudiness']
             if atm in '0123':
                 expected = min(expected, 0.2)
             if atm in 'ABCDEF':
                 expected += 0.4
                 expected = min(expected, 1.0)
             if atm == 'E':
                 expected = expected / 2.0
             expected = round(expected, 1)
             planet.determine_cloudiness()
             LOGGER.debug(
                 'hyd = %s, atm = %s, cloudiness = %s, expected = %s',
                 planet.hydrographics, planet.atmosphere, planet.cloudiness,
                 expected)
             self.assertTrue(planet.cloudiness == expected)