Пример #1
0
 def test_import_locations(self):
     locations = KeyedPoints()
     locations.import_locations([('prime', '0;0'),
                                 ('home', '52.015 -0.221')])
     expect(locations) == \
         KeyedPoints({'prime': Point(0.0, 0.0, 'metric', 'degrees', 0),
                      'home': Point(52.015, -0.221, 'metric', 'degrees',
                                    0)},
                     False, 'metric')
Пример #2
0
 def setUp(self):
     self.locs = KeyedPoints([('home', '52.015;-0.221'),
                              ('Carol', '52.168;0.040'),
                              ('Kenny', '52.855;0.657')],
                             parse=True)
Пример #3
0
class TestKeyedPoints(TestCase):
    def setUp(self):
        self.locs = KeyedPoints([('home', '52.015;-0.221'),
                                 ('Carol', '52.168;0.040'),
                                 ('Kenny', '52.855;0.657')],
                                parse=True)

    def test_import_locations(self):
        locations = KeyedPoints()
        locations.import_locations([('prime', '0;0'),
                                    ('home', '52.015 -0.221')])
        expect(locations) == \
            KeyedPoints({'prime': Point(0.0, 0.0, 'metric', 'degrees', 0),
                         'home': Point(52.015, -0.221, 'metric', 'degrees',
                                       0)},
                        False, 'metric')

    def test_distance(self):
        expect('%.3f' % sum(self.locs.distance(('home', 'Carol', 'Kenny')))) == '111.632'

    def test_bearing(self):
        expect(['%.3f' % x for x in self.locs.bearing(('home', 'Carol', 'Kenny'))]) == \
            ['46.242', '28.416']

    def test_final_bearing(self):
        expect(['%.3f' % x for x in self.locs.final_bearing(('home', 'Carol', 'Kenny'))]) == \
            ['46.448', '28.906']

    def test_inverse(self):
        expect(list(self.locs.inverse(('home', 'Carol', 'Kenny')))) == \
            [(46.24239319802467, 24.629669163425465),
             (28.41617384845358, 87.00207583308533)]

    def test_midpoint(self):
        expect(list(self.locs.midpoint(('home', 'Carol', 'Kenny')))) == \
            [Point(52.09157204324692, -0.09072375391429187, 'metric',
                   'degrees', 0),
             Point(52.51190105089283, 0.3460886030865466, 'metric', 'degrees',
                   0)]

    def test_range(self):
        expect(list(self.locs.range(Point(52.015, -0.221), 20))) == \
            [('home', Point(52.015, -0.221, 'metric', 'degrees', 0))]

    def test_destination(self):
        expect(sorted(self.locs.destination(42, 240))) == \
            [('Carol', Point(53.74846914951471, 2.4840382137470614, 'metric',
                             'degrees', 0)),
             ('Kenny', Point(54.43483380445103, 3.1418347849815293, 'metric',
                             'degrees', 0)),
             ('home', Point(53.59560782169536, 2.2141813683976777, 'metric',
                            'degrees', 0))]

    def test_sunrise(self):
        expect(sorted(self.locs.sunrise(datetime.date(2008, 5, 2)))) == \
            [('Carol', datetime.time(4, 26)),
             ('Kenny', datetime.time(4, 21)),
             ('home', datetime.time(4, 28))]

    def test_sunset(self):
        expect(sorted(self.locs.sunset(datetime.date(2008, 5, 2)))) == \
            [('Carol', datetime.time(19, 27)),
             ('Kenny', datetime.time(19, 27)),
             ('home', datetime.time(19, 28))]

    def test_sun_events(self):
        expect(sorted(self.locs.sun_events(datetime.date(2008, 5, 2)))) == \
            [('Carol', (datetime.time(4, 26), datetime.time(19, 27))),
             ('Kenny', (datetime.time(4, 21), datetime.time(19, 27))),
             ('home', (datetime.time(4, 28), datetime.time(19, 28)))]

    def test_to_grid_locator(self):
        expect(sorted(self.locs.to_grid_locator('extsquare'))) == \
            [('Carol', 'JO02ae40'), ('Kenny', 'JO02hu85'), ('home', 'IO92va33')]
        expect(sorted(self.locs.to_grid_locator('subsquare'))) == \
            [('Carol', 'JO02ae'), ('Kenny', 'JO02hu'), ('home', 'IO92va')]